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


PHP CRM_Core_DAO_CustomField::save方法代码示例

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


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

示例1: postProcess

 /**
  * Process the form
  *
  * @param null
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     // store the submitted values in an array
     $params = $this->controller->exportValues('Option');
     if ($this->_action == CRM_Core_Action::DELETE) {
         $fieldValues = array('option_group_id' => $this->_optionGroupID);
         $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_id, $fieldValues);
         CRM_Core_BAO_CustomOption::del($this->_id);
         CRM_Core_Session::setStatus(ts('Your multiple choice option has been deleted'));
         return;
     }
     // set values for custom field properties and save
     $customOption = new CRM_Core_DAO_OptionValue();
     $customOption->label = $params['label'];
     $customOption->name = CRM_Utils_String::titleToVar($params['label']);
     $customOption->weight = $params['weight'];
     $customOption->value = $params['value'];
     $customOption->is_active = CRM_Utils_Array::value('is_active', $params, FALSE);
     $oldWeight = NULL;
     if ($this->_id) {
         $customOption->id = $this->_id;
         CRM_Core_BAO_CustomOption::updateCustomValues($params);
         $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'weight', 'id');
     }
     $fieldValues = array('option_group_id' => $this->_optionGroupID);
     $customOption->weight = CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_OptionValue', $oldWeight, $params['weight'], $fieldValues);
     $customOption->option_group_id = $this->_optionGroupID;
     $customField = new CRM_Core_DAO_CustomField();
     $customField->id = $this->_fid;
     if ($customField->find(TRUE) && ($customField->html_type == 'CheckBox' || $customField->html_type == 'AdvMulti-Select' || $customField->html_type == 'Multi-Select')) {
         $defVal = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($customField->default_value, 1, -1));
         if (CRM_Utils_Array::value('default_value', $params)) {
             if (!in_array($customOption->value, $defVal)) {
                 if (empty($defVal[0])) {
                     $defVal = array($customOption->value);
                 } else {
                     $defVal[] = $customOption->value;
                 }
                 $customField->default_value = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, $defVal) . CRM_Core_DAO::VALUE_SEPARATOR;
                 $customField->save();
             }
         } elseif (in_array($customOption->value, $defVal)) {
             $tempVal = array();
             foreach ($defVal as $v) {
                 if ($v != $customOption->value) {
                     $tempVal[] = $v;
                 }
             }
             $customField->default_value = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, $tempVal) . CRM_Core_DAO::VALUE_SEPARATOR;
             $customField->save();
         }
     } else {
         switch ($customField->data_type) {
             case 'Money':
                 $customOption->value = CRM_Utils_Rule::cleanMoney($customOption->value);
                 break;
             case 'Int':
                 $customOption->value = intval($customOption->value);
                 break;
             case 'Float':
                 $customOption->value = floatval($customOption->value);
                 break;
         }
         if (CRM_Utils_Array::value('default_value', $params)) {
             $customField->default_value = $customOption->value;
             $customField->save();
         } elseif ($customField->find(TRUE) && $customField->default_value == $customOption->value) {
             // this is the case where this option is the current default value and we have been reset
             $customField->default_value = 'null';
             $customField->save();
         }
     }
     $customOption->save();
     CRM_Core_Session::setStatus(ts('Your multiple choice option \'%1\' has been saved', array(1 => $customOption->label)));
     $buttonName = $this->controller->getButtonName();
     $session = CRM_Core_Session::singleton();
     if ($buttonName == $this->getButtonName('next', 'new')) {
         CRM_Core_Session::setStatus(ts(' You can add another option.'));
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/field/option', 'reset=1&action=add&fid=' . $this->_fid . '&gid=' . $this->_gid));
     }
 }
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:89,代码来源:Option.php

示例2: postProcess

 /**
  * Process the form when submitted
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     $params = $this->controller->exportValues($this->_name);
     $tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_values['custom_group_id'], 'table_name');
     $singleValueOps = array('Text', 'Select', 'Radio', 'Autocomplete-Select');
     $mutliValueOps = array('CheckBox', 'Multi-Select', 'AdvMulti-Select');
     $srcHtmlType = $this->_values['html_type'];
     $dstHtmlType = $params['dst_html_type'];
     $customField = new CRM_Core_DAO_CustomField();
     $customField->id = $this->_id;
     $customField->find(TRUE);
     if ($dstHtmlType == 'Text' && in_array($srcHtmlType, array('Select', 'Radio', 'Autocomplete-Select'))) {
         $customField->option_group_id = "NULL";
         CRM_Core_BAO_CustomField::checkOptionGroup($this->_values['option_group_id']);
     }
     if (in_array($srcHtmlType, $mutliValueOps) && in_array($dstHtmlType, $singleValueOps)) {
         $this->flattenToFirstValue($tableName, $this->_values['column_name']);
     } elseif (in_array($srcHtmlType, $singleValueOps) && in_array($dstHtmlType, $mutliValueOps)) {
         $this->firstValueToFlatten($tableName, $this->_values['column_name']);
     }
     $customField->html_type = $dstHtmlType;
     $customField->save();
     // Reset cache for custom fields
     CRM_Core_BAO_Cache::deleteGroup('contact fields');
     CRM_Core_Session::setStatus(ts('Input type of custom field \'%1\' has been successfully changed to \'%2\'.', array(1 => $this->_values['label'], 2 => $dstHtmlType)));
 }
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:32,代码来源:ChangeFieldType.php

示例3: create

 /**
  * Takes an associative array and creates a custom field object.
  *
  * This function is invoked from within the web form layer and also from the api layer
  *
  * @param array $params
  *   (reference) an assoc array of name/value pairs.
  *
  * @return CRM_Core_DAO_CustomField
  */
 public static function create(&$params)
 {
     $origParams = array_merge(array(), $params);
     if (!isset($params['id'])) {
         if (!isset($params['column_name'])) {
             // if add mode & column_name not present, calculate it.
             $params['column_name'] = strtolower(CRM_Utils_String::munge($params['label'], '_', 32));
         }
         if (!isset($params['name'])) {
             $params['name'] = CRM_Utils_String::munge($params['label'], '_', 64);
         }
     } else {
         $params['column_name'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $params['id'], 'column_name');
     }
     $columnName = $params['column_name'];
     $indexExist = FALSE;
     //as during create if field is_searchable we had created index.
     if (!empty($params['id'])) {
         $indexExist = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $params['id'], 'is_searchable');
     }
     switch (CRM_Utils_Array::value('html_type', $params)) {
         case 'Select Date':
             if (empty($params['date_format'])) {
                 $config = CRM_Core_Config::singleton();
                 $params['date_format'] = $config->dateInputFormat;
             }
             break;
         case 'CheckBox':
         case 'AdvMulti-Select':
         case 'Multi-Select':
             if (isset($params['default_checkbox_option'])) {
                 $tempArray = array_keys($params['default_checkbox_option']);
                 $defaultArray = array();
                 foreach ($tempArray as $k => $v) {
                     if ($params['option_value'][$v]) {
                         $defaultArray[] = $params['option_value'][$v];
                     }
                 }
                 if (!empty($defaultArray)) {
                     // also add the separator before and after the value per new convention (CRM-1604)
                     $params['default_value'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, $defaultArray) . CRM_Core_DAO::VALUE_SEPARATOR;
                 }
             } else {
                 if (!empty($params['default_option']) && isset($params['option_value'][$params['default_option']])) {
                     $params['default_value'] = $params['option_value'][$params['default_option']];
                 }
             }
             break;
     }
     $transaction = new CRM_Core_Transaction();
     // create any option group & values if required
     if ($params['html_type'] != 'Text' && in_array($params['data_type'], array('String', 'Int', 'Float', 'Money'))) {
         $tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['custom_group_id'], 'table_name');
         //CRM-16659: if option_value then create an option group for this custom field.
         if ($params['option_type'] == 1 && (empty($params['option_group_id']) || !empty($params['option_value']))) {
             // first create an option group for this custom group
             $optionGroup = new CRM_Core_DAO_OptionGroup();
             $optionGroup->name = "{$columnName}_" . date('YmdHis');
             $optionGroup->title = $params['label'];
             $optionGroup->is_active = 1;
             $optionGroup->save();
             $params['option_group_id'] = $optionGroup->id;
             if (!empty($params['option_value']) && is_array($params['option_value'])) {
                 foreach ($params['option_value'] as $k => $v) {
                     if (strlen(trim($v))) {
                         $optionValue = new CRM_Core_DAO_OptionValue();
                         $optionValue->option_group_id = $optionGroup->id;
                         $optionValue->label = $params['option_label'][$k];
                         $optionValue->name = CRM_Utils_String::titleToVar($params['option_label'][$k]);
                         switch ($params['data_type']) {
                             case 'Money':
                                 $optionValue->value = CRM_Utils_Rule::cleanMoney($v);
                                 break;
                             case 'Int':
                                 $optionValue->value = intval($v);
                                 break;
                             case 'Float':
                                 $optionValue->value = floatval($v);
                                 break;
                             default:
                                 $optionValue->value = trim($v);
                         }
                         $optionValue->weight = $params['option_weight'][$k];
                         $optionValue->is_active = CRM_Utils_Array::value($k, $params['option_status'], FALSE);
                         $optionValue->save();
                     }
                 }
             }
         }
     }
//.........这里部分代码省略.........
开发者ID:Hack4Eugene,项目名称:Hack4Cause2016,代码行数:101,代码来源:CustomField.php

示例4: create

 /**
  * takes an associative array and creates a custom field object
  *
  * This function is invoked from within the web form layer and also from the api layer
  *
  * @param array $params (reference) an assoc array of name/value pairs
  *
  * @return object CRM_Core_DAO_CustomField object
  * @access public
  * @static
  */
 static function create(&$params)
 {
     if (!isset($params['id']) && !isset($params['column_name'])) {
         // if add mode & column_name not present, calculate it.
         require_once 'CRM/Utils/String.php';
         $params['column_name'] = strtolower(CRM_Utils_String::munge($params['label'], '_', 32));
         $params['name'] = CRM_Utils_String::munge($params['label'], '_', 64);
     } else {
         if (isset($params['id'])) {
             $params['column_name'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $params['id'], 'column_name');
         }
     }
     $indexExist = false;
     //as during create if field is_searchable we had created index.
     if (CRM_Utils_Array::value('id', $params)) {
         $indexExist = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $params['id'], 'is_searchable');
     }
     if (($params['html_type'] == 'CheckBox' || $params['html_type'] == 'AdvMulti-Select' || $params['html_type'] == 'Multi-Select') && isset($params['default_checkbox_option'])) {
         $tempArray = array_keys($params['default_checkbox_option']);
         $defaultArray = array();
         foreach ($tempArray as $k => $v) {
             if ($params['option_value'][$v]) {
                 $defaultArray[] = $params['option_value'][$v];
             }
         }
         if (!empty($defaultArray)) {
             // also add the seperator before and after the value per new conventio (CRM-1604)
             $params['default_value'] = CRM_Core_BAO_CustomOption::VALUE_SEPERATOR . implode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $defaultArray) . CRM_Core_BAO_CustomOption::VALUE_SEPERATOR;
         }
     } else {
         if (CRM_Utils_Array::value('default_option', $params) && isset($params['option_value'][$params['default_option']])) {
             $params['default_value'] = $params['option_value'][$params['default_option']];
         }
     }
     require_once 'CRM/Core/Transaction.php';
     $transaction = new CRM_Core_Transaction();
     // create any option group & values if required
     if ($params['html_type'] != 'Text' && in_array($params['data_type'], array('String', 'Int', 'Float', 'Money')) && !empty($params['option_value']) && is_array($params['option_value'])) {
         $tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['custom_group_id'], 'table_name');
         if ($params['option_type'] == 1) {
             // first create an option group for this custom group
             require_once 'CRM/Core/BAO/OptionGroup.php';
             $optionGroup = new CRM_Core_DAO_OptionGroup();
             $optionGroup->name = "{$params['column_name']}_" . date('YmdHis');
             $optionGroup->label = $params['label'];
             $optionGroup->is_active = 1;
             $optionGroup->save();
             $params['option_group_id'] = $optionGroup->id;
             require_once 'CRM/Core/BAO/OptionValue.php';
             require_once 'CRM/Utils/String.php';
             foreach ($params['option_value'] as $k => $v) {
                 if (strlen(trim($v))) {
                     $optionValue = new CRM_Core_DAO_OptionValue();
                     $optionValue->option_group_id = $optionGroup->id;
                     $optionValue->label = $params['option_label'][$k];
                     $optionValue->name = CRM_Utils_String::titleToVar($params['option_label'][$k]);
                     switch ($params['data_type']) {
                         case 'Money':
                             require_once 'CRM/Utils/Rule.php';
                             $optionValue->value = number_format(CRM_Utils_Rule::cleanMoney($v), 2);
                             break;
                         case 'Int':
                             $optionValue->value = intval($v);
                             break;
                         case 'Float':
                             $optionValue->value = floatval($v);
                             break;
                         default:
                             $optionValue->value = trim($v);
                     }
                     $optionValue->weight = $params['option_weight'][$k];
                     $optionValue->is_active = CRM_Utils_Array::value($k, $params['option_status'], false);
                     $optionValue->save();
                 }
             }
         }
     }
     // check for orphan option groups
     if (CRM_Utils_Array::value('option_group_id', $params)) {
         if (CRM_Utils_Array::value('id', $params)) {
             self::fixOptionGroups($params['id'], $params['option_group_id']);
         }
         // if we dont have a default value
         // retrive it from one of the other custom fields which use this option group
         if (!CRM_Utils_Array::value('default_value', $params)) {
             //don't insert only value separator as default value, CRM-4579
             $defaultValue = self::getOptionGroupDefault($params['option_group_id'], $params['html_type']);
             if (!CRM_Utils_System::isNull(explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $defaultValue))) {
                 $params['default_value'] = $defaultValue;
//.........这里部分代码省略.........
开发者ID:hampelm,项目名称:Ginsberg-CiviDemo,代码行数:101,代码来源:CustomField.php


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