当前位置: 首页>>代码示例>>PHP>>正文


PHP CRM_Utils_Weight::getNewWeight方法代码示例

本文整理汇总了PHP中CRM_Utils_Weight::getNewWeight方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_Weight::getNewWeight方法的具体用法?PHP CRM_Utils_Weight::getNewWeight怎么用?PHP CRM_Utils_Weight::getNewWeight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CRM_Utils_Weight的用法示例。


在下文中一共展示了CRM_Utils_Weight::getNewWeight方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: updateOtherWeights

 /**
  * Updates the weight fields of other rows according to the new and old weight paased in. 
  * And returns the new weight be used. If old-weight not present, Creates a gap for a new row to be inserted 
  * at the specified new weight
  *
  * @param string $daoName full name of the DAO
  * @param integer $oldWeight
  * @param integer $newWeight 
  * @param array $fieldValues field => value to be used in the WHERE
  * @param string $weightField field which contains the weight value,
  * defaults to 'weight'
  * @return bool 
  */
 static function updateOtherWeights($daoName, $oldWeight, $newWeight, $fieldValues = null, $weightField = 'weight')
 {
     $oldWeight = (int) $oldWeight;
     $newWeight = (int) $newWeight;
     // max weight is the highest current weight
     $maxWeight = CRM_Utils_Weight::getMax($daoName, $fieldValues, $weightField);
     if (!$maxWeight) {
         $maxWeight = 1;
     }
     if ($newWeight > $maxWeight) {
         //calculate new weight, CRM-4133
         $calNewWeight = CRM_Utils_Weight::getNewWeight($daoName, $fieldValues, $weightField);
         //no need to update weight for other fields.
         if ($calNewWeight > $maxWeight) {
             return $calNewWeight;
         }
         $newWeight = $maxWeight;
         if (!$oldWeight) {
             return $newWeight + 1;
         }
     } elseif ($newWeight < 1) {
         $newWeight = 1;
     }
     // if they're the same, nothing to do
     if ($oldWeight == $newWeight) {
         return $newWeight;
     }
     // if oldWeight not present, indicates new weight is to be added. So create a gap for a new row to be inserted.
     if (!$oldWeight) {
         $additionalWhere = "{$weightField} >= {$newWeight}";
         $update = "{$weightField} = ({$weightField} + 1)";
         CRM_Utils_Weight::query('UPDATE', $daoName, $fieldValues, $update, $additionalWhere);
         return $newWeight;
     } else {
         if ($newWeight > $oldWeight) {
             $additionalWhere = "{$weightField} > {$oldWeight} AND {$weightField} <= {$newWeight}";
             $update = "{$weightField} = ({$weightField} - 1)";
         } elseif ($newWeight < $oldWeight) {
             $additionalWhere = "{$weightField} >= {$newWeight} AND {$weightField} < {$oldWeight}";
             $update = "{$weightField} = ({$weightField} + 1)";
         }
         CRM_Utils_Weight::query('UPDATE', $daoName, $fieldValues, $update, $additionalWhere);
         return $newWeight;
     }
 }
开发者ID:bhirsch,项目名称:voipdev,代码行数:58,代码来源:Weight.php


注:本文中的CRM_Utils_Weight::getNewWeight方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。