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


PHP CRM_Utils_Weight::correctDuplicateWeights方法代码示例

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


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

示例1: correctDuplicateWeights

 /**
  * Correct duplicate weight entries by putting them (duplicate weights) in sequence.
  *
  * @param string $daoName
  *   Full name of the DAO.
  * @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
  */
 public static function correctDuplicateWeights($daoName, $fieldValues = NULL, $weightField = 'weight')
 {
     $selectField = "MIN(id) AS dupeId, count(id) as dupeCount, {$weightField} as dupeWeight";
     $groupBy = "{$weightField} having dupeCount>1";
     $minDupeID = CRM_Utils_Weight::query('SELECT', $daoName, $fieldValues, $selectField, NULL, NULL, $groupBy);
     // return early if query returned empty
     // CRM-8043
     if (!$minDupeID->fetch()) {
         return TRUE;
     }
     if ($minDupeID->dupeId) {
         $additionalWhere = "id !=" . $minDupeID->dupeId . " AND {$weightField} >= " . $minDupeID->dupeWeight;
         $update = "{$weightField} = {$weightField} + 1";
         $status = CRM_Utils_Weight::query('UPDATE', $daoName, $fieldValues, $update, $additionalWhere);
     }
     if ($minDupeID->dupeId && $status) {
         //recursive call to correct all duplicate weight entries.
         return CRM_Utils_Weight::correctDuplicateWeights($daoName, $fieldValues, $weightField);
     } elseif (!$minDupeID->dupeId) {
         // case when no duplicate records are found.
         return TRUE;
     } elseif (!$status) {
         // case when duplicate records are found but update status is false.
         return FALSE;
     }
 }
开发者ID:nganivet,项目名称:civicrm-core,代码行数:39,代码来源:Weight.php

示例2: savePdfFormat

 /**
  * Save the PDF Page Format in the DB.
  *
  * @param array (reference) $values associative array of name/value pairs
  * @param int $id
  *   Id of the database record (null = new record).
  *
  * @return void
  */
 public function savePdfFormat(&$values, $id = NULL)
 {
     // get the Option Group ID for PDF Page Formats (create one if it doesn't exist)
     $group_id = self::_getGid();
     // clear other default if this is the new default PDF Page Format
     if ($values['is_default']) {
         $query = "UPDATE civicrm_option_value SET is_default = 0 WHERE option_group_id = {$group_id}";
         CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
     }
     if ($id) {
         // fetch existing record
         $this->id = $id;
         if ($this->find()) {
             $this->fetch();
         }
     }
     // copy the supplied form values to the corresponding Option Value fields in the base class
     foreach ($this->fields() as $name => $field) {
         $this->{$name} = trim(CRM_Utils_Array::value($name, $values, $this->{$name}));
         if (empty($this->{$name})) {
             $this->{$name} = 'null';
         }
     }
     $this->id = $id;
     $this->option_group_id = $group_id;
     $this->label = $this->name;
     $this->is_active = 1;
     // serialize PDF Page Format fields into a single string to store in the 'value' column of the Option Value table
     $v = json_decode($this->value, TRUE);
     foreach (self::$optionValueFields as $name => $field) {
         $v[$name] = self::getValue($name, $values, CRM_Utils_Array::value($name, $v));
     }
     $this->value = json_encode($v);
     // make sure serialized array will fit in the 'value' column
     $attribute = CRM_Core_DAO::getAttribute('CRM_Core_BAO_PdfFormat', 'value');
     if (strlen($this->value) > $attribute['maxlength']) {
         CRM_Core_Error::fatal(ts('PDF Page Format does not fit in database.'));
     }
     $this->save();
     // fix duplicate weights
     $filter = array('option_group_id' => self::_getGid());
     CRM_Utils_Weight::correctDuplicateWeights('CRM_Core_DAO_OptionValue', $filter);
 }
开发者ID:kidaa30,项目名称:yes,代码行数:52,代码来源:PdfFormat.php

示例3: saveLabelFormat

 /**
  * Save the Label Format in the DB
  *
  * @param array (reference)   $values    associative array of name/value pairs
  * @param int                 $id        id of the database record (null = new record)
  * @param string $groupName   group name of the label format
  *
  * @return void
  * @access public
  */
 function saveLabelFormat(&$values, $id = NULL, $groupName = 'label_format')
 {
     // get the Option Group ID for Label Formats (create one if it doesn't exist)
     $group_id = self::_getGid($groupName);
     // clear other default if this is the new default label format
     if ($values['is_default']) {
         $query = "UPDATE civicrm_option_value SET is_default = 0 WHERE option_group_id = {$group_id}";
         CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
     }
     if ($id) {
         // fetch existing record
         $this->id = $id;
         if ($this->find()) {
             $this->fetch();
         }
     } else {
         // new record
         $list = self::getList(TRUE, $groupName);
         $cnt = 1;
         while (array_key_exists("custom_{$cnt}", $list)) {
             $cnt++;
         }
         $values['name'] = "custom_{$cnt}";
         $values['grouping'] = self::customGroupName();
     }
     // copy the supplied form values to the corresponding Option Value fields in the base class
     foreach ($this->fields() as $name => $field) {
         $this->{$name} = trim(CRM_Utils_Array::value($name, $values, $this->{$name}));
         if (empty($this->{$name})) {
             $this->{$name} = 'null';
         }
     }
     $this->id = $id;
     $this->option_group_id = $group_id;
     $this->is_active = 1;
     // serialize label format fields into a single string to store in the 'value' column of the Option Value table
     $v = json_decode($this->value, TRUE);
     foreach (self::$optionValueFields as $name => $field) {
         if (!isset($v[$name])) {
             $v[$name] = NULL;
         }
         $v[$name] = self::getValue($name, $values, $v[$name]);
     }
     $this->value = json_encode($v);
     // make sure serialized array will fit in the 'value' column
     $attribute = CRM_Core_DAO::getAttribute('CRM_Core_BAO_LabelFormat', 'value');
     if (strlen($this->value) > $attribute['maxlength']) {
         CRM_Core_Error::fatal(ts('Label Format does not fit in database.'));
     }
     $this->save();
     // fix duplicate weights
     $filter = array('option_group_id' => self::_getGid());
     CRM_Utils_Weight::correctDuplicateWeights('CRM_Core_DAO_OptionValue', $filter);
 }
开发者ID:prashantgajare,项目名称:civicrm-core,代码行数:64,代码来源:LabelFormat.php

示例4: postProcess

 /**
  * Process the form submission.
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         $fieldValues = array('option_group_id' => $this->_gid);
         $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_id, $fieldValues);
         if (CRM_Core_BAO_OptionValue::del($this->_id)) {
             if ($this->_gName == 'phone_type') {
                 CRM_Core_BAO_Phone::setOptionToNull(CRM_Utils_Array::value('value', $this->_defaultValues));
             }
             CRM_Core_Session::setStatus(ts('Selected %1 type has been deleted.', array(1 => $this->_gLabel)), ts('Record Deleted'), 'success');
         } else {
             CRM_Core_Session::setStatus(ts('Selected %1 type has not been deleted.', array(1 => $this->_gLabel)), ts('Sorry'), 'error');
             CRM_Utils_Weight::correctDuplicateWeights('CRM_Core_DAO_OptionValue', $fieldValues);
         }
     } else {
         $params = $ids = array();
         $params = $this->exportValues();
         // allow multiple defaults within group.
         $allowMultiDefaults = array('email_greeting', 'postal_greeting', 'addressee', 'from_email_address');
         if (in_array($this->_gName, $allowMultiDefaults)) {
             if ($this->_gName == 'from_email_address') {
                 $params['reset_default_for'] = array('domain_id' => CRM_Core_Config::domainID());
             } elseif ($filter = CRM_Utils_Array::value('contactOptions', $params)) {
                 $params['filter'] = $filter;
                 $params['reset_default_for'] = array('filter' => "0, " . $params['filter']);
             }
             //make sure we should has to have space, CRM-6977
             if ($this->_gName == 'from_email_address') {
                 $params['label'] = str_replace('"<', '" <', $params['label']);
             }
         }
         // set value of filter if not present in params
         if ($this->_id && !array_key_exists('filter', $params)) {
             if ($this->_gName == 'participant_role') {
                 $params['filter'] = 0;
             } else {
                 $params['filter'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'filter', 'id');
             }
         }
         $groupParams = array('name' => $this->_gName);
         $optionValue = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $this->_action, $this->_id);
         // CRM-11516
         if (!empty($params['financial_account_id'])) {
             $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' "));
             $params = array('entity_table' => 'civicrm_option_value', 'entity_id' => $optionValue->id, 'account_relationship' => $relationTypeId, 'financial_account_id' => $params['financial_account_id']);
             CRM_Financial_BAO_FinancialTypeAccount::add($params);
         }
         CRM_Core_Session::setStatus(ts('The %1 \'%2\' has been saved.', array(1 => $this->_gLabel, 2 => $optionValue->label)), ts('Saved'), 'success');
     }
 }
开发者ID:nielosz,项目名称:civicrm-core,代码行数:53,代码来源:Options.php

示例5: deleteField

 /**
  * Delete the Custom Field.
  *
  * @param object $field
  *   The field object.
  */
 public static function deleteField($field)
 {
     CRM_Utils_System::flushCache();
     // first delete the custom option group and values associated with this field
     if ($field->option_group_id) {
         //check if option group is related to any other field, if
         //not delete the option group and related option values
         self::checkOptionGroup($field->option_group_id);
     }
     // next drop the column from the custom value table
     self::createField($field, 'delete');
     $field->delete();
     CRM_Core_BAO_UFField::delUFField($field->id);
     CRM_Utils_Weight::correctDuplicateWeights('CRM_Core_DAO_CustomField');
 }
开发者ID:Hack4Eugene,项目名称:Hack4Cause2016,代码行数:21,代码来源:CustomField.php

示例6: postProcess

 /**
  * Function to process the form
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         if (CRM_Core_BAO_OptionValue::del($this->_id)) {
             CRM_Core_Session::setStatus(ts('Selected %1 Report has been deleted.', array(1 => $this->_GName)));
             CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/report/options/report_template', "reset=1"));
         } else {
             CRM_Core_Session::setStatus(ts('Selected %1 type has not been deleted.', array(1 => $this->_GName)));
             CRM_Utils_Weight::correctDuplicateWeights('CRM_Core_DAO_OptionValue', $fieldValues);
         }
     } else {
         // get the submitted form values.
         $params = $this->controller->exportValues($this->_name);
         $ids = array();
         $groupParams = array('name' => 'report_template');
         $optionValue = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $this->_action, $this->_id);
         CRM_Core_Session::setStatus(ts('The %1 \'%2\' has been saved.', array(1 => 'Report Template', 2 => $optionValue->label)));
         CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/report/options/report_template', "reset=1"));
     }
 }
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:27,代码来源:Register.php

示例7: postProcess

 /**
  * Process the form when submitted
  *
  * @param null
  * 
  * @return void
  * @access public
  */
 public function postProcess()
 {
     $field =& new CRM_Core_DAO_CustomField();
     $field->id = $this->_id;
     $field->find(true);
     CRM_Core_BAO_CustomField::deleteField($field);
     // also delete any profiles associted with this custom field
     require_once "CRM/Core/BAO/UFField.php";
     CRM_Core_BAO_UFField::delUFField($this->_id);
     CRM_Core_Session::setStatus(ts('The custom field \'%1\' has been deleted.', array(1 => $field->label)));
     CRM_Utils_Weight::correctDuplicateWeights('CRM_Core_DAO_CustomField');
 }
开发者ID:bhirsch,项目名称:voipdev,代码行数:20,代码来源:DeleteField.php

示例8: postProcess

 /**
  * Function to process the form
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         $fieldValues = array('option_group_id' => $this->_gid);
         $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_id, $fieldValues);
         if (CRM_Core_BAO_OptionValue::del($this->_id)) {
             if ($this->_gName == 'phone_type') {
                 require_once 'CRM/Core/BAO/Phone.php';
                 CRM_Core_BAO_Phone::setOptionToNull(CRM_Utils_Array::value('value', $this->_defaultValues));
             }
             CRM_Core_Session::setStatus(ts('Selected %1 type has been deleted.', array(1 => $this->_GName)));
         } else {
             CRM_Core_Session::setStatus(ts('Selected %1 type has not been deleted.', array(1 => $this->_GName)));
             CRM_Utils_Weight::correctDuplicateWeights('CRM_Core_DAO_OptionValue', $fieldValues);
         }
     } else {
         $params = $ids = array();
         $params = $this->exportValues();
         // allow multiple defaults within group.
         $allowMultiDefaults = array('email_greeting', 'postal_greeting', 'addressee', 'from_email_address');
         if (CRM_Utils_Array::value('is_default', $params) && in_array($this->_gName, $allowMultiDefaults)) {
             if ($this->_gName == 'from_email_address') {
                 $params['reset_default_for'] = array('domain_id' => CRM_Core_Config::domainID());
             } else {
                 if ($filter = CRM_Utils_Array::value('contactOptions', $params)) {
                     $params['filter'] = $filter;
                     $params['reset_default_for'] = array('filter' => "0, " . $params['filter']);
                 }
             }
         }
         $groupParams = array('name' => $this->_gName);
         require_once 'CRM/Core/OptionValue.php';
         $optionValue = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $this->_action, $this->_id);
         CRM_Core_Session::setStatus(ts('The %1 \'%2\' has been saved.', array(1 => $this->_GName, 2 => $optionValue->label)));
     }
 }
开发者ID:bhirsch,项目名称:voipdev,代码行数:42,代码来源:Options.php

示例9: postProcess

 /**
  * Function to process the form
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         $fieldValues = array('option_group_id' => $this->_gid);
         $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_id, $fieldValues);
         if (CRM_Core_BAO_OptionValue::del($this->_id)) {
             if ($this->_gName == 'phone_type') {
                 require_once 'CRM/Core/BAO/Phone.php';
                 CRM_Core_BAO_Phone::setOptionToNull(CRM_Utils_Array::value('value', $this->_defaultValues));
             }
             CRM_Core_Session::setStatus(ts('Selected %1 type has been deleted.', array(1 => $this->_GName)));
         } else {
             CRM_Core_Session::setStatus(ts('Selected %1 type has not been deleted.', array(1 => $this->_GName)));
             CRM_Utils_Weight::correctDuplicateWeights('CRM_Core_DAO_OptionValue', $fieldValues);
         }
     } else {
         $params = $ids = array();
         $params = $this->exportValues();
         //set defaultGreeting option in params as per contact type
         if (CRM_Utils_Array::value('contactOptions', $params)) {
             $params['filter'] = CRM_Utils_Array::value('contactOptions', $params);
             $params['defaultGreeting'] = 1;
         }
         $groupParams = array('name' => $this->_gName);
         require_once 'CRM/Core/OptionValue.php';
         $optionValue = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $this->_action, $this->_id);
         CRM_Core_Session::setStatus(ts('The %1 \'%2\' has been saved.', array(1 => $this->_GName, 2 => $optionValue->label)));
     }
 }
开发者ID:ksecor,项目名称:civicrm,代码行数:35,代码来源:Options.php

示例10: postProcess

 /**
  * Function to process the form
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         $fieldValues = array('option_group_id' => $this->_gid);
         $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_id, $fieldValues);
         if (CRM_Core_BAO_OptionValue::del($this->_id)) {
             if ($this->_gName == 'phone_type') {
                 CRM_Core_BAO_Phone::setOptionToNull(CRM_Utils_Array::value('value', $this->_defaultValues));
             }
             CRM_Core_Session::setStatus(ts('Selected %1 type has been deleted.', array(1 => $this->_GName)));
         } else {
             CRM_Core_Session::setStatus(ts('Selected %1 type has not been deleted.', array(1 => $this->_GName)));
             CRM_Utils_Weight::correctDuplicateWeights('CRM_Core_DAO_OptionValue', $fieldValues);
         }
     } else {
         $params = $ids = array();
         $params = $this->exportValues();
         // allow multiple defaults within group.
         $allowMultiDefaults = array('email_greeting', 'postal_greeting', 'addressee', 'from_email_address');
         if (in_array($this->_gName, $allowMultiDefaults)) {
             if ($this->_gName == 'from_email_address') {
                 $params['reset_default_for'] = array('domain_id' => CRM_Core_Config::domainID());
             } elseif ($filter = CRM_Utils_Array::value('contactOptions', $params)) {
                 $params['filter'] = $filter;
                 $params['reset_default_for'] = array('filter' => "0, " . $params['filter']);
             }
             //make sure we should has to have space, CRM-6977
             if ($this->_gName == 'from_email_address') {
                 $params['label'] = str_replace('"<', '" <', $params['label']);
             }
         }
         // set db value of filter in params if filter is non editable
         if ($this->_id && !array_key_exists('filter', $params) && !$this->_gName == 'participant_role') {
             $params['filter'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'filter', 'id');
         }
         $groupParams = array('name' => $this->_gName);
         $optionValue = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $this->_action, $this->_id);
         CRM_Core_Session::setStatus(ts('The %1 \'%2\' has been saved.', array(1 => $this->_GName, 2 => $optionValue->label)));
     }
 }
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:47,代码来源:Options.php


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