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


PHP CRM_Core_BAO_CustomOption::getCustomOption方法代码示例

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


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

示例1: crm_get_option_values

/**
 * 
 * Retrieves an array of valid values for "enum" type properties 
 *
 * @param  $customField  Object  custom fields object
 *
 * @return  Array of custom field options. 
 *
 * @access public
 *
 */
function crm_get_option_values($customField)
{
    _crm_initialize();
    if (!isset($customField->id)) {
        return _crm_error("custom_field is not valid custom_field object");
    }
    $fieldId = $customField->id;
    require_once 'CRM/Core/BAO/CustomOption.php';
    return CRM_Core_BAO_CustomOption::getCustomOption($fieldId);
}
开发者ID:bhirsch,项目名称:voipdrupal-4.7-1.0,代码行数:21,代码来源:CustomGroup.php

示例2: _civicrm_api3_deprecated_add_formatted_location_blocks

/**
 * This function format location blocks w/ v3.0 format.
 *
 * @param array $values
 *   The variable(s) to be added.
 * @param array $params
 *   The structured parameter list.
 *
 * @return bool
 */
function _civicrm_api3_deprecated_add_formatted_location_blocks(&$values, &$params)
{
    static $fields = NULL;
    if ($fields == NULL) {
        $fields = array();
    }
    foreach (array('Phone', 'Email', 'IM', 'OpenID', 'Phone_Ext') as $block) {
        $name = strtolower($block);
        if (!array_key_exists($name, $values)) {
            continue;
        }
        if ($name == 'phone_ext') {
            $block = 'Phone';
        }
        // block present in value array.
        if (!array_key_exists($name, $params) || !is_array($params[$name])) {
            $params[$name] = array();
        }
        if (!array_key_exists($block, $fields)) {
            $className = "CRM_Core_DAO_{$block}";
            $fields[$block] =& $className::fields();
        }
        $blockCnt = count($params[$name]);
        // copy value to dao field name.
        if ($name == 'im') {
            $values['name'] = $values[$name];
        }
        _civicrm_api3_store_values($fields[$block], $values, $params[$name][++$blockCnt]);
        if (empty($params['id']) && $blockCnt == 1) {
            $params[$name][$blockCnt]['is_primary'] = TRUE;
        }
        // we only process single block at a time.
        return TRUE;
    }
    // handle address fields.
    if (!array_key_exists('address', $params) || !is_array($params['address'])) {
        $params['address'] = array();
    }
    $addressCnt = 1;
    foreach ($params['address'] as $cnt => $addressBlock) {
        if (CRM_Utils_Array::value('location_type_id', $values) == CRM_Utils_Array::value('location_type_id', $addressBlock)) {
            $addressCnt = $cnt;
            break;
        }
        $addressCnt++;
    }
    if (!array_key_exists('Address', $fields)) {
        require_once 'CRM/Core/DAO/Address.php';
        $fields['Address'] = CRM_Core_DAO_Address::fields();
    }
    // Note: we doing multiple value formatting here for address custom fields, plus putting into right format.
    // The actual formatting (like date, country ..etc) for address custom fields is taken care of while saving
    // the address in CRM_Core_BAO_Address::create method
    if (!empty($values['location_type_id'])) {
        static $customFields = array();
        if (empty($customFields)) {
            $customFields = CRM_Core_BAO_CustomField::getFields('Address');
        }
        // make a copy of values, as we going to make changes
        $newValues = $values;
        foreach ($values as $key => $val) {
            $customFieldID = CRM_Core_BAO_CustomField::getKeyID($key);
            if ($customFieldID && array_key_exists($customFieldID, $customFields)) {
                // mark an entry in fields array since we want the value of custom field to be copied
                $fields['Address'][$key] = NULL;
                $htmlType = CRM_Utils_Array::value('html_type', $customFields[$customFieldID]);
                switch ($htmlType) {
                    case 'CheckBox':
                    case 'AdvMulti-Select':
                    case 'Multi-Select':
                        if ($val) {
                            $mulValues = explode(',', $val);
                            $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE);
                            $newValues[$key] = array();
                            foreach ($mulValues as $v1) {
                                foreach ($customOption as $v2) {
                                    if (strtolower($v2['label']) == strtolower(trim($v1)) || strtolower($v2['value']) == strtolower(trim($v1))) {
                                        if ($htmlType == 'CheckBox') {
                                            $newValues[$key][$v2['value']] = 1;
                                        } else {
                                            $newValues[$key][] = $v2['value'];
                                        }
                                    }
                                }
                            }
                        }
                        break;
                }
            }
        }
//.........这里部分代码省略.........
开发者ID:rameshrr99,项目名称:civicrm-core,代码行数:101,代码来源:DeprecatedUtils.php

示例3: formatCommonData


//.........这里部分代码省略.........
                     $break = TRUE;
                 }
                 if (!$break) {
                     require_once 'CRM/Utils/DeprecatedUtils.php';
                     _civicrm_api3_deprecated_add_formatted_param($value, $formatted);
                 }
             }
             if (!$isAddressCustomField) {
                 continue;
             }
         }
         $formatValues = array($key => $field);
         if ($key !== 'preferred_communication_method' && array_key_exists($key, $contactFields)) {
             // due to merging of individual table and
             // contact table, we need to avoid
             // preferred_communication_method forcefully
             $formatValues['contact_type'] = $formatted['contact_type'];
         }
         if ($key == 'id' && isset($field)) {
             $formatted[$key] = $field;
         }
         require_once 'CRM/Utils/DeprecatedUtils.php';
         _civicrm_api3_deprecated_add_formatted_param($formatValues, $formatted);
         //Handling Custom Data
         // note: Address custom fields will be handled separately inside _civicrm_api3_deprecated_add_formatted_param
         if (($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) && array_key_exists($customFieldID, $customFields) && !array_key_exists($customFieldID, $addressCustomFields)) {
             $extends = CRM_Utils_Array::value('extends', $customFields[$customFieldID]);
             $htmlType = CRM_Utils_Array::value('html_type', $customFields[$customFieldID]);
             switch ($htmlType) {
                 case 'Select':
                 case 'Radio':
                 case 'Autocomplete-Select':
                     if ($customFields[$customFieldID]['data_type'] == 'String') {
                         $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE);
                         foreach ($customOption as $customFldID => $customValue) {
                             $val = CRM_Utils_Array::value('value', $customValue);
                             $label = CRM_Utils_Array::value('label', $customValue);
                             $label = strtolower($label);
                             $value = strtolower(trim($formatted[$key]));
                             if ($value == $label || $value == strtolower($val)) {
                                 $params[$key] = $formatted[$key] = $val;
                             }
                         }
                     }
                     break;
                 case 'CheckBox':
                 case 'AdvMulti-Select':
                 case 'Multi-Select':
                     if (!empty($formatted[$key]) && !empty($params[$key])) {
                         $mulValues = explode(',', $formatted[$key]);
                         $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE);
                         $formatted[$key] = array();
                         $params[$key] = array();
                         foreach ($mulValues as $v1) {
                             foreach ($customOption as $v2) {
                                 if (strtolower($v2['label']) == strtolower(trim($v1)) || strtolower($v2['value']) == strtolower(trim($v1))) {
                                     if ($htmlType == 'CheckBox') {
                                         $params[$key][$v2['value']] = $formatted[$key][$v2['value']] = 1;
                                     } else {
                                         $params[$key][] = $formatted[$key][] = $v2['value'];
                                     }
                                 }
                             }
                         }
                     }
                     break;
开发者ID:JSProffitt,项目名称:civicrm-website-org,代码行数:67,代码来源:Contact.php

示例4: _crm_format_custom_params

function _crm_format_custom_params(&$params, &$values, $extends)
{
    $values['custom'] = array();
    $customFields = CRM_Core_BAO_CustomField::getFields($extends);
    foreach ($params as $key => $value) {
        if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
            /* check if it's a valid custom field id */
            if (!array_key_exists($customFieldID, $customFields)) {
                return _crm_error('Invalid custom field ID');
            }
            $fieldType = null;
            // modified for CRM-1586
            // check data type for importing custom field (labels) with data type Integer/Float/Money
            /* validate the data against the CF type */
            if ($customFields[$customFieldID]['data_type'] == "Int" || $customFields[$customFieldID]['data_type'] == "Float" || $customFields[$customFieldID]['data_type'] == "Money") {
                if ($customFields[$customFieldID]['html_type'] == "Text") {
                    $fieldType = $customFields[$customFieldID]['data_type'];
                } else {
                    $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID);
                    foreach ($customOption as $customValue => $customLabel) {
                        //check wether $value is label or value
                        if (strtolower($customValue) == strtolower(trim($value))) {
                            $fieldType = "String";
                        } else {
                            if (strtolower($customValue) == strtolower(trim($value))) {
                                $fieldType = $customFields[$customFieldID]['data_type'];
                            }
                        }
                    }
                }
            } else {
                //set the Field type
                $fieldType = $customFields[$customFieldID]['data_type'];
            }
            $valid = null;
            //Validate the datatype of $value
            $valid = CRM_Core_BAO_CustomValue::typecheck($fieldType, $value);
            //return error, if not valid custom field
            if (!$valid) {
                return _crm_error('Invalid value for custom field ' . $customFields[$customFieldID][1]);
            }
            // fix the date field if so
            if ($customFields[$customFieldID]['data_type'] == 'Date') {
                $value = str_replace('-', '', $value);
            }
            // fixed for checkbox and multiselect
            $newMulValues = array();
            if ($customFields[$customFieldID]['html_type'] == 'CheckBox' || $customFields[$customFieldID]['html_type'] == 'Multi-Select') {
                $value = str_replace(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, ',', trim($value, CRM_Core_BAO_CustomOption::VALUE_SEPERATOR));
                $value = str_replace("|", ",", $value);
                $mulValues = explode(',', $value);
                $custumOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, true);
                foreach ($mulValues as $v1) {
                    foreach ($customOption as $customValue => $customLabel) {
                        if (strtolower($customLabel) == strtolower(trim($v1)) || strtolower($customValue) == strtolower(trim($v1))) {
                            $newMulValues[] = $customValue;
                        }
                    }
                }
                $value = CRM_Core_BAO_CustomOption::VALUE_SEPERATOR . implode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $newMulValues) . CRM_Core_BAO_CustomOption::VALUE_SEPERATOR;
            } else {
                if ($customFields[$customFieldID]['html_type'] == 'Select' || $customFields[$customFieldID]['html_type'] == 'Radio') {
                    $custumOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, true);
                    foreach ($customOption as $customValue => $customLabel) {
                        if (strtolower($customLabel) == strtolower(trim($value)) || strtolower($customValue) == strtolower(trim($value))) {
                            $value = $customValue;
                            break;
                        }
                    }
                }
            }
            $values['custom'][$customFieldID] = array('value' => $value, 'extends' => $customFields[$customFieldID]['extends'], 'type' => $customFields[$customFieldID]['data_type'], 'custom_field_id' => $customFieldID);
        }
    }
}
开发者ID:ksecor,项目名称:civicrm,代码行数:75,代码来源:utils.php

示例5: formatCommonData


//.........这里部分代码省略.........
                             $break = true;
                             break;
                         }
                     }
                 } else {
                     $break = true;
                 }
                 if (!$break) {
                     _civicrm_add_formatted_param($value, $formatted);
                 }
             }
             continue;
         }
         $formatValues = array($key => $field);
         if ($key !== 'preferred_communication_method' && array_key_exists($key, $contactFields)) {
             // due to merging of individual table and
             // contact table, we need to avoid
             // preferred_communication_method forcefully
             $formatValues['contact_type'] = $formatted['contact_type'];
         }
         if ($key == 'id' && isset($field)) {
             $formatted[$key] = $field;
         }
         _civicrm_add_formatted_param($formatValues, $formatted);
         //Handling Custom Data
         if (($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) && array_key_exists($customFieldID, $customFields)) {
             //get the html type.
             $type = $customFields[$customFieldID]['html_type'];
             switch ($type) {
                 case 'CheckBox':
                 case 'AdvMulti-Select':
                 case 'Multi-Select':
                     $mulValues = explode(',', $field);
                     $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, true);
                     $formatted[$key] = array();
                     foreach ($mulValues as $v1) {
                         foreach ($customOption as $v2) {
                             if (strtolower($v2['label']) == strtolower(trim($v1)) || strtolower($v2['value']) == strtolower(trim($v1))) {
                                 if ($type == 'CheckBox') {
                                     $formatted[$key][$v2['value']] = 1;
                                 } else {
                                     $formatted[$key][] = $v2['value'];
                                 }
                             }
                         }
                     }
                     break;
                 case 'Select':
                 case 'Radio':
                     $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, true);
                     foreach ($customOption as $v2) {
                         if (strtolower($v2['label']) == strtolower(trim($field)) || strtolower($v2['value']) == strtolower(trim($field))) {
                             $formatted[$key] = $v2['value'];
                         }
                     }
                     break;
                 case 'Multi-Select State/Province':
                     $mulValues = explode(',', $field);
                     $stateAbbr = CRM_Core_PseudoConstant::stateProvinceAbbreviation();
                     $stateName = CRM_Core_PseudoConstant::stateProvince();
                     $formatted[$key] = $stateValues = array();
                     foreach ($mulValues as $values) {
                         if ($val = CRM_Utils_Array::key($values, $stateAbbr)) {
                             $formatted[$key][] = $val;
                         } else {
                             if ($val = CRM_Utils_Array::key($values, $stateName)) {
开发者ID:bhirsch,项目名称:voipdev,代码行数:67,代码来源:Contact.php

示例6: browse

 /**
  * Browse the listing
  *
  * @return void
  * @access public
  */
 function browse()
 {
     $dateFields = NULL;
     $cgcount = 0;
     $dateFieldsVals = NULL;
     if ($this->_pageViewType == 'profileDataView' && $this->_profileId) {
         $fields = CRM_Core_BAO_UFGroup::getFields($this->_profileId, FALSE, NULL, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::EDIT);
         $multiRecordFields = array();
         $fieldIDs = NULL;
         $result = NULL;
         $multiRecordFieldsWithSummaryListing = CRM_Core_BAO_UFGroup::shiftMultiRecordFields($fields, $multiRecordFields, TRUE);
         $multiFieldId = CRM_Core_BAO_CustomField::getKeyID(key($multiRecordFields));
         $customGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $multiFieldId, 'custom_group_id');
         $reached = CRM_Core_BAO_CustomGroup::hasReachedMaxLimit($customGroupId, $this->_contactId);
         if (!$reached) {
             $this->assign('contactId', $this->_contactId);
             $this->assign('gid', $this->_profileId);
         }
         $this->assign('reachedMax', $reached);
         if ($multiRecordFieldsWithSummaryListing && !empty($multiRecordFieldsWithSummaryListing)) {
             $fieldIDs = array_keys($multiRecordFieldsWithSummaryListing);
         }
     } elseif ($this->_pageViewType == 'customDataView') {
         // require custom group id for _pageViewType of customDataView
         $customGroupId = $this->_customGroupId;
         $reached = CRM_Core_BAO_CustomGroup::hasReachedMaxLimit($customGroupId, $this->_contactId);
         if (!$reached) {
             $this->assign('contactId', $this->_contactId);
             $this->assign('customGroupId', $customGroupId);
             $this->assign('ctype', $this->_contactType);
         }
         $this->assign('reachedMax', $reached);
         // custom group info : this consists of the field title of group fields
         $groupDetail = CRM_Core_BAO_CustomGroup::getGroupDetail($customGroupId, NULL, CRM_Core_DAO::$_nullObject, TRUE);
         // field ids of fields in_selector for the custom group id provided
         $fieldIDs = array_keys($groupDetail[$customGroupId]['fields']);
         // field labels for headers
         $fieldLabels = $groupDetail[$customGroupId]['fields'];
         // from the above customGroupInfo we can get $this->_customGroupTitle
         $this->_customGroupTitle = $groupDetail[$customGroupId]['title'];
     }
     if ($fieldIDs && !empty($fieldIDs) && $this->_contactId) {
         $options = array();
         $returnProperities = array('html_type', 'data_type', 'date_format', 'time_format');
         foreach ($fieldIDs as $key => $fieldID) {
             $fieldIDs[$key] = !is_numeric($fieldID) ? CRM_Core_BAO_CustomField::getKeyID($fieldID) : $fieldID;
             $param = array('id' => $fieldIDs[$key]);
             $returnValues = array();
             CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $param, $returnValues, $returnProperities);
             if ($returnValues['data_type'] == 'Date') {
                 $dateFields[$fieldIDs[$key]] = 1;
             }
             $optionValuePairs = CRM_Core_BAO_CustomOption::getCustomOption($fieldIDs[$key]);
             if (!empty($optionValuePairs)) {
                 foreach ($optionValuePairs as $optionPairs) {
                     $options[$fieldIDs[$key]][$optionPairs['value']] = $optionPairs['label'];
                 }
             }
             $options[$fieldIDs[$key]]['attributes']['html_type'] = $returnValues['html_type'];
             $options[$fieldIDs[$key]]['attributes']['data_type'] = $returnValues['data_type'];
             $options[$fieldIDs[$key]]['attributes']['format'] = $options[$fieldIDs[$key]]['attributes']['date_format'] = CRM_Utils_Array::value('date_format', $returnValues);
             $options[$fieldIDs[$key]]['attributes']['time_format'] = CRM_Utils_Array::value('time_format', $returnValues);
         }
         // commonly used for both views i.e profile listing view (profileDataView) and custom data listing view (customDataView)
         $result = CRM_Core_BAO_CustomValueTable::getEntityValues($this->_contactId, NULL, $fieldIDs, TRUE);
         if ($this->_pageViewType == 'profileDataView') {
             if (!empty($fieldIDs)) {
                 //get the group info of multi rec fields in listing view
                 $fieldInput = $fieldIDs;
                 $fieldIdInput = $fieldIDs[0];
             } else {
                 //if no listing fields exist, take the group title for display
                 $nonListingFieldIds = array_keys($multiRecordFields);
                 $singleField = CRM_Core_BAO_CustomField::getKeyID($nonListingFieldIds[0]);
                 $fieldIdInput = $singleField;
                 $singleField = array($singleField);
                 $fieldInput = $singleField;
             }
             $customGroupInfo = CRM_Core_BAO_CustomGroup::getGroupTitles($fieldInput);
             $this->_customGroupTitle = $customGroupInfo[$fieldIdInput]['groupTitle'];
         }
         // $cgcount is defined before 'if' condition as enitiy may have no record
         // and $cgcount is used to build new record url
         $cgcount = 1;
         if ($result && !empty($result)) {
             $links = self::links();
             if ($this->_pageViewType == 'profileDataView') {
                 $pageCheckSum = $this->get('pageCheckSum');
                 if ($pageCheckSum) {
                     foreach ($links as $key => $link) {
                         $links[$key] = $link['qs'] . "&cs=%%cs%%";
                     }
                 }
             }
//.........这里部分代码省略.........
开发者ID:ruchirapingale,项目名称:civicrm-core,代码行数:101,代码来源:MultipleRecordFieldsListing.php

示例7: browse

 /**
  * Browse the listing
  *
  * @return void
  * @access public
  */
 function browse()
 {
     if ($this->_profileId) {
         $fields = CRM_Core_BAO_UFGroup::getFields($this->_profileId, FALSE, NULL, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::EDIT);
         $multiRecordFields = array();
         $fieldIDs = NULL;
         $result = NULL;
         $multiRecordFieldsWithSummaryListing = CRM_Core_BAO_UFGroup::shiftMultiRecordFields($fields, $multiRecordFields, TRUE);
         $multiFieldId = CRM_Core_BAO_CustomField::getKeyID(key($multiRecordFields));
         $customGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $multiFieldId, 'custom_group_id');
         $reached = CRM_Core_BAO_CustomGroup::hasReachedMaxLimit($customGroupId, $this->_contactId);
         if (!$reached) {
             $this->assign('contactId', $this->_contactId);
             $this->assign('gid', $this->_profileId);
         }
         $this->assign('reachedMax', $reached);
         if ($multiRecordFieldsWithSummaryListing && !empty($multiRecordFieldsWithSummaryListing)) {
             $fieldIDs = array_keys($multiRecordFieldsWithSummaryListing);
         }
     }
     if ($fieldIDs && !empty($fieldIDs) && $this->_contactId) {
         $options = array();
         $returnProperities = array('html_type', 'data_type', 'date_format', 'time_format');
         foreach ($fieldIDs as $key => $fieldID) {
             $fieldIDs[$key] = CRM_Core_BAO_CustomField::getKeyID($fieldID);
             $param = array('id' => $fieldIDs[$key]);
             $returnValues = array();
             CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $param, $returnValues, $returnProperities);
             $optionValuePairs = CRM_Core_BAO_CustomOption::getCustomOption($fieldIDs[$key]);
             if (!empty($optionValuePairs)) {
                 foreach ($optionValuePairs as $optionPairs) {
                     $options[$fieldIDs[$key]][$optionPairs['value']] = $optionPairs['label'];
                 }
             }
             $options[$fieldIDs[$key]]['attributes']['html_type'] = $returnValues['html_type'];
             $options[$fieldIDs[$key]]['attributes']['data_type'] = $returnValues['data_type'];
             $options[$fieldIDs[$key]]['attributes']['format'] = $options[$fieldIDs[$key]]['attributes']['date_format'] = CRM_Utils_Array::value('date_format', $returnValues);
             $options[$fieldIDs[$key]]['attributes']['time_format'] = CRM_Utils_Array::value('time_format', $returnValues);
         }
         $result = CRM_Core_BAO_CustomValueTable::getEntityValues($this->_contactId, NULL, $fieldIDs, TRUE);
         if (!empty($fieldIDs)) {
             //get the group info of multi rec fields in listing view
             $fieldInput = $fieldIDs;
             $fieldIdInput = $fieldIDs[0];
         } else {
             //if no listing fields exist, take the group title for display
             $nonListingFieldIds = array_keys($multiRecordFields);
             $singleField = CRM_Core_BAO_CustomField::getKeyID($nonListingFieldIds[0]);
             $fieldIdInput = $singleField;
             $singleField = array($singleField);
             $fieldInput = $singleField;
         }
         $customGroupInfo = CRM_Core_BAO_CustomGroup::getGroupTitles($fieldInput);
         $this->_customGroupTitle = $customGroupInfo[$fieldIdInput]['groupTitle'];
         if ($result && !empty($result)) {
             $links = self::links();
             $pageCheckSum = $this->get('pageCheckSum');
             if ($pageCheckSum) {
                 foreach ($links as $key => $link) {
                     $links[$key] = $link['qs'] . "&cs=%%cs%%";
                 }
             }
             $linkAction = array_sum(array_keys($this->links()));
             foreach ($result as $recId => &$value) {
                 foreach ($value as $fieldId => &$val) {
                     if (is_numeric($fieldId)) {
                         $customValue =& $val;
                         $customValue = CRM_Core_BAO_CustomField::getDisplayValue($customValue, $fieldId, $options);
                         if (!$customValue) {
                             $customValue = "";
                         }
                         $actionParams = array('recordId' => $recId, 'gid' => $this->_profileId, 'id' => $this->_contactId, 'onPopupClose' => $this->_onPopupClose);
                         if ($pageCheckSum) {
                             $actionParams['cs'] = $pageCheckSum;
                         }
                         $value['action'] = CRM_Core_Action::formLink($links, $linkAction, $actionParams, ts('more'), FALSE, 'profile.multiValue.row', 'customValue', $fieldId);
                     }
                 }
             }
         }
     }
     $headers = array();
     if (!empty($fieldIDs)) {
         foreach ($fieldIDs as $fieldID) {
             $headers[$fieldID] = $customGroupInfo[$fieldID]['fieldLabel'];
         }
     }
     $this->assign('customGroupTitle', $this->_customGroupTitle);
     $this->assign('headers', $headers);
     $this->assign('records', $result);
 }
开发者ID:archcidburnziso,项目名称:civicrm-core,代码行数:97,代码来源:MultipleRecordFieldsListing.php

示例8: extractGetParams

 /**
  * Extract the get params from the url, validate and store it in session.
  *
  * @param CRM_Core_Form $form
  *   The form object.
  * @param string $type
  *   The type of custom group we are using.
  *
  * @return array
  */
 public static function extractGetParams(&$form, $type)
 {
     if (empty($_GET)) {
         return array();
     }
     $groupTree = CRM_Core_BAO_CustomGroup::getTree($type);
     $customValue = array();
     $htmlType = array('CheckBox', 'Multi-Select', 'AdvMulti-Select', 'Select', 'Radio');
     foreach ($groupTree as $group) {
         if (!isset($group['fields'])) {
             continue;
         }
         foreach ($group['fields'] as $key => $field) {
             $fieldName = 'custom_' . $key;
             $value = CRM_Utils_Request::retrieve($fieldName, 'String', $form, FALSE, NULL, 'GET');
             if ($value) {
                 $valid = FALSE;
                 if (!in_array($field['html_type'], $htmlType) || $field['data_type'] == 'Boolean') {
                     $valid = CRM_Core_BAO_CustomValue::typecheck($field['data_type'], $value);
                 }
                 if ($field['html_type'] == 'CheckBox' || $field['html_type'] == 'AdvMulti-Select' || $field['html_type'] == 'Multi-Select') {
                     $value = str_replace("|", ",", $value);
                     $mulValues = explode(',', $value);
                     $customOption = CRM_Core_BAO_CustomOption::getCustomOption($key, TRUE);
                     $val = array();
                     foreach ($mulValues as $v1) {
                         foreach ($customOption as $coID => $coValue) {
                             if (strtolower(trim($coValue['label'])) == strtolower(trim($v1))) {
                                 $val[$coValue['value']] = 1;
                             }
                         }
                     }
                     if (!empty($val)) {
                         $value = $val;
                         $valid = TRUE;
                     } else {
                         $value = NULL;
                     }
                 } elseif ($field['html_type'] == 'Select' || $field['html_type'] == 'Radio' && $field['data_type'] != 'Boolean') {
                     $customOption = CRM_Core_BAO_CustomOption::getCustomOption($key, TRUE);
                     foreach ($customOption as $customID => $coValue) {
                         if (strtolower(trim($coValue['label'])) == strtolower(trim($value))) {
                             $value = $coValue['value'];
                             $valid = TRUE;
                         }
                     }
                 } elseif ($field['data_type'] == 'Date') {
                     if (!empty($value)) {
                         $time = NULL;
                         if (!empty($field['time_format'])) {
                             $time = CRM_Utils_Request::retrieve($fieldName . '_time', 'String', $form, FALSE, NULL, 'GET');
                         }
                         list($value, $time) = CRM_Utils_Date::setDateDefaults($value . ' ' . $time);
                         if (!empty($field['time_format'])) {
                             $customValue[$fieldName . '_time'] = $time;
                         }
                     }
                     $valid = TRUE;
                 }
                 if ($valid) {
                     $customValue[$fieldName] = $value;
                 }
             }
         }
     }
     return $customValue;
 }
开发者ID:saurabhbatra96,项目名称:civicrm-core,代码行数:77,代码来源:CustomGroup.php

示例9: _crm_add_formatted_history_param

/**
 * This function adds the activity history variable in $values to the
 * parameter list $params.  For most cases, $values should have length 1.
 *
 * @param array  $values    The variable(s) to be added
 * @param array  $params    The structured parameter list
 * 
 * @return bool|CRM_Utils_Error
 * @access public
 */
function _crm_add_formatted_history_param(&$values, &$params)
{
    /* Cache the various object fields */
    static $fields = null;
    if ($fields == null) {
        $fields = array();
    }
    //print_r($values);
    //print_r($params);
    if (isset($values['activity_type'])) {
        $params['activity_type'] = $values['activity_type'];
        return true;
    }
    if (isset($values['activity_date'])) {
        $params['activity_date'] = $values['activity_date'];
        return true;
    }
    if (isset($values['activity_id'])) {
        $params['activity_id'] = $values['activity_id'];
        return true;
    }
    /* Check for custom field values */
    if ($fields['custom'] == null) {
        $fields['custom'] =& CRM_Core_BAO_CustomField::getFields('Contribution');
    }
    foreach ($values as $key => $value) {
        if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
            /* check if it's a valid custom field id */
            if (!array_key_exists($customFieldID, $fields['custom'])) {
                return _crm_error('Invalid custom field ID');
            }
            if (!isset($params['custom'])) {
                $params['custom'] = array();
            }
            // fixed for Import
            $newMulValues = array();
            if ($fields['custom'][$customFieldID][3] == 'CheckBox' || $fields['custom'][$customFieldID][3] == 'Multi-Select') {
                $value = str_replace("|", ",", $value);
                $mulValues = explode(',', $value);
                $custuomOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, true);
                foreach ($mulValues as $v1) {
                    foreach ($custuomOption as $v2) {
                        if (strtolower($v2['label']) == strtolower(trim($v1))) {
                            $newMulValues[] = $v2['value'];
                        }
                    }
                }
                $value = implode(CRM_CORE_BAO_CUSTOMOPTION_VALUE_SEPERATOR, $newMulValues);
            } else {
                if ($fields['custom'][$customFieldID][3] == 'Select' || $fields['custom'][$customFieldID][3] == 'Radio') {
                    $custuomOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, true);
                    foreach ($custuomOption as $v2) {
                        if (strtolower($v2['label']) == strtolower(trim($value))) {
                            $value = $v2['value'];
                            break;
                        }
                    }
                }
            }
            $customBlock = count($params['custom']) + 1;
            $params['custom'][$customBlock] = array('custom_field_id' => $customFieldID, 'value' => $value, 'type' => $fields['custom'][$customFieldID][2], 'name' => $fields['custom'][$customFieldID][0]);
        }
    }
    /* Finally, check for contribution fields */
    if (!isset($fields['History'])) {
        $fields['History'] =& CRM_Core_DAO_ActivityHistory::fields();
    }
    _crm_store_values($fields['History'], $values, $params);
}
开发者ID:bhirsch,项目名称:voipdrupal-4.7-1.0,代码行数:79,代码来源:utils.php

示例10: _civicrm_activity_formatted_param

/**
 * take the input parameter list as specified in the data model and 
 * convert it into the same format that we use in QF and BAO object
 *
 * @param array  $params       Associative array of property name/value
 *                             pairs to insert in new contact.
 * @param array  $values       The reformatted properties that we can use internally
 *
 * @param array  $create       Is the formatted Values array going to
 *                             be used for CRM_Activity_BAO_Activity::create()
 *
 * @return array|CRM_Error
 * @access public
 */
function _civicrm_activity_formatted_param(&$params, &$values, $create = false)
{
    $fields =& CRM_Activity_DAO_Activity::fields();
    _civicrm_store_values($fields, $params, $values);
    require_once 'CRM/Core/OptionGroup.php';
    $customFields = CRM_Core_BAO_CustomField::getFields('Activity');
    foreach ($params as $key => $value) {
        // ignore empty values or empty arrays etc
        if (CRM_Utils_System::isNull($value)) {
            continue;
        }
        //Handling Custom Data
        if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
            $values[$key] = $value;
            $type = $customFields[$customFieldID]['html_type'];
            if ($type == 'CheckBox' || $type == 'Multi-Select') {
                $mulValues = explode(',', $value);
                $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, true);
                $values[$key] = array();
                foreach ($mulValues as $v1) {
                    foreach ($customOption as $customValueID => $customLabel) {
                        $customValue = $customLabel['value'];
                        if (strtolower($customLabel['label']) == strtolower(trim($v1)) || strtolower($customValue) == strtolower(trim($v1))) {
                            if ($type == 'CheckBox') {
                                $values[$key][$customValue] = 1;
                            } else {
                                $values[$key][] = $customValue;
                            }
                        }
                    }
                }
            } else {
                if ($type == 'Select' || $type == 'Radio') {
                    $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, true);
                    foreach ($customOption as $customValue => $customLabel) {
                        if (strtolower($customLabel) == strtolower(trim($v1)) || strtolower($customValue) == strtolower(trim($v1))) {
                            $values[$key] = $customValue;
                        }
                    }
                }
            }
        }
    }
    return null;
}
开发者ID:ksecor,项目名称:civicrm,代码行数:59,代码来源:utils.php

示例11: isErrorInCustomData

 /**
  *  function to check if an error in custom data
  *  
  *  @param String   $errorMessage   A string containing all the error-fields.
  *  
  *  @access public 
  */
 function isErrorInCustomData($params, &$errorMessage)
 {
     $session = CRM_Core_Session::singleton();
     $dateType = $session->get("dateTypes");
     //CRM-5125
     //add custom fields for contact sub type
     if (!empty($this->_contactSubType)) {
         $csType = $this->_contactSubType;
     }
     if (CRM_Utils_Array::value('contact_sub_type', $params)) {
         $csType = CRM_Utils_Array::value('contact_sub_type', $params);
     }
     $customFields = CRM_Core_BAO_CustomField::getFields($params['contact_type'], false, false, $csType);
     $addressCustomFields = CRM_Core_BAO_CustomField::getFields('Address');
     $customFields = $customFields + $addressCustomFields;
     foreach ($params as $key => $value) {
         if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
             /* check if it's a valid custom field id */
             if (!array_key_exists($customFieldID, $customFields)) {
                 self::addToErrorMsg(ts('field ID'), $errorMessage);
             }
             //For address custom fields, we do get actual custom field value as an inner array of
             //values so need to modify
             if (array_key_exists($customFieldID, $addressCustomFields)) {
                 $value = $value[0][$key];
             }
             /* validate the data against the CF type */
             if ($value) {
                 if ($customFields[$customFieldID]['data_type'] == 'Date') {
                     if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key)) {
                         $value = $params[$key];
                     } else {
                         self::addToErrorMsg($customFields[$customFieldID]['label'], $errorMessage);
                     }
                 } else {
                     if ($customFields[$customFieldID]['data_type'] == 'Boolean') {
                         if (CRM_Utils_String::strtoboolstr($value) === false) {
                             self::addToErrorMsg($customFields[$customFieldID]['label'], $errorMessage);
                         }
                     }
                 }
                 // need not check for label filed import
                 $htmlType = array('CheckBox', 'Multi-Select', 'AdvMulti-Select', 'Select', 'Radio', 'Multi-Select State/Province', 'Multi-Select Country', 'Text');
                 if (!in_array($customFields[$customFieldID]['html_type'], $htmlType) || $customFields[$customFieldID]['data_type'] == 'Boolean' || $customFields[$customFieldID]['data_type'] == 'ContactReference') {
                     $valid = CRM_Core_BAO_CustomValue::typecheck($customFields[$customFieldID]['data_type'], $value);
                     if (!$valid) {
                         self::addToErrorMsg($customFields[$customFieldID]['label'], $errorMessage);
                     }
                 }
                 // check for values for custom fields for checkboxes and multiselect
                 if ($customFields[$customFieldID]['html_type'] == 'CheckBox' || $customFields[$customFieldID]['html_type'] == 'AdvMulti-Select' || $customFields[$customFieldID]['html_type'] == 'Multi-Select') {
                     $value = trim($value);
                     $value = str_replace('|', ',', $value);
                     $mulValues = explode(',', $value);
                     $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, true);
                     foreach ($mulValues as $v1) {
                         if (strlen($v1) == 0) {
                             continue;
                         }
                         $flag = false;
                         foreach ($customOption as $v2) {
                             if (strtolower(trim($v2['label'])) == strtolower(trim($v1)) || strtolower(trim($v2['value'])) == strtolower(trim($v1))) {
                                 $flag = true;
                             }
                         }
                         if (!$flag) {
                             self::addToErrorMsg($customFields[$customFieldID]['label'], $errorMessage);
                         }
                     }
                 } else {
                     if ($customFields[$customFieldID]['html_type'] == 'Select' || $customFields[$customFieldID]['html_type'] == 'Radio' && $customFields[$customFieldID]['data_type'] != 'Boolean') {
                         $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, true);
                         $flag = false;
                         foreach ($customOption as $v2) {
                             if (strtolower(trim($v2['label'])) == strtolower(trim($value)) || strtolower(trim($v2['value'])) == strtolower(trim($value))) {
                                 $flag = true;
                             }
                         }
                         if (!$flag) {
                             self::addToErrorMsg($customFields[$customFieldID]['label'], $errorMessage);
                         }
                     } else {
                         if ($customFields[$customFieldID]['html_type'] == 'Multi-Select State/Province') {
                             $mulValues = explode(',', $value);
                             foreach ($mulValues as $stateValue) {
                                 if ($stateValue) {
                                     if (self::in_value(trim($stateValue), CRM_Core_PseudoConstant::stateProvinceAbbreviation()) || self::in_value(trim($stateValue), CRM_Core_PseudoConstant::stateProvince())) {
                                         continue;
                                     } else {
                                         self::addToErrorMsg($customFields[$customFieldID]['label'], $errorMessage);
                                     }
                                 }
                             }
//.........这里部分代码省略.........
开发者ID:hampelm,项目名称:Ginsberg-CiviDemo,代码行数:101,代码来源:Contact.php

示例12: isErrorInCustomData

 /**
  *  function to check if an error in custom data
  *  
  *  @param String   $errorMessage   A string containing all the error-fields.
  *  
  *  @access public 
  */
 function isErrorInCustomData($params, &$errorMessage)
 {
     $customFields = CRM_Core_BAO_CustomField::getFields($params['contact_type']);
     foreach ($params as $key => $value) {
         if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
             /* check if it's a valid custom field id */
             if (!array_key_exists($customFieldID, $customFields)) {
                 //return _crm_error('Invalid custom field ID');
                 CRM_Import_Parser_Contact::addToErrorMsg('field ID', $errorMessage);
             }
             /* validate the data against the CF type */
             //CRM_Core_Error::debug( $value, $customFields[$customFieldID] );
             if ($value) {
                 // need not check for label filed import
                 $htmlType = array('CheckBox', 'Multi-Select', 'Select', 'Radio');
                 if (!in_array($customFields[$customFieldID][3], $htmlType) || $customFields[$customFieldID][2] == 'Boolean') {
                     $valid = CRM_Core_BAO_CustomValue::typecheck($customFields[$customFieldID][2], $value);
                     if (!$valid) {
                         //return _crm_error('Invalid value for custom field :' .$customFields[$customFieldID][0]);
                         CRM_Import_Parser_Contact::addToErrorMsg($customFields[$customFieldID][0], $errorMessage);
                     }
                 }
                 // check for values for custom fields for checkboxes and multiselect
                 if ($customFields[$customFieldID][3] == 'CheckBox' || $customFields[$customFieldID][3] == 'Multi-Select') {
                     $value = str_replace("|", ",", $value);
                     $mulValues = explode(',', $value);
                     $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, true);
                     foreach ($mulValues as $v1) {
                         $flag = false;
                         foreach ($customOption as $v2) {
                             if (strtolower(trim($v2['label'])) == strtolower(trim($v1))) {
                                 $flag = true;
                             }
                         }
                         if (!$flag) {
                             //return _crm_error('Invalid value for custom field :' .$customFields[$customFieldID][0]);
                             CRM_Import_Parser_Contact::addToErrorMsg($customFields[$customFieldID][0], $errorMessage);
                         }
                     }
                 } else {
                     if ($customFields[$customFieldID][3] == 'Select' || $customFields[$customFieldID][3] == 'Radio' && $customFields[$customFieldID][2] != 'Boolean') {
                         $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, true);
                         $flag = false;
                         foreach ($customOption as $v2) {
                             if (strtolower(trim($v2['label'])) == strtolower(trim($value))) {
                                 $flag = true;
                             }
                         }
                         if (!$flag) {
                             //return _crm_error('Invalid value for custom field :' .$customFields[$customFieldID][0]);
                             CRM_Import_Parser_Contact::addToErrorMsg($customFields[$customFieldID][0], $errorMessage);
                         }
                     }
                 }
             }
         }
     }
     //return true;
 }
开发者ID:bhirsch,项目名称:voipdrupal-4.7-1.0,代码行数:66,代码来源:Contact.php

示例13: _civicrm_activity_formatted_param

/**
 * take the input parameter list as specified in the data model and 
 * convert it into the same format that we use in QF and BAO object
 *
 * @param array  $params       Associative array of property name/value
 *                             pairs to insert in new contact.
 * @param array  $values       The reformatted properties that we can use internally
 *
 * @param array  $create       Is the formatted Values array going to
 *                             be used for CRM_Activity_BAO_Activity::create()
 *
 * @return array|CRM_Error
 * @access public
 */
function _civicrm_activity_formatted_param(&$params, &$values, $create = false)
{
    $fields =& CRM_Activity_DAO_Activity::fields();
    _civicrm_store_values($fields, $params, $values);
    require_once 'CRM/Core/OptionGroup.php';
    $customFields = CRM_Core_BAO_CustomField::getFields('Activity');
    foreach ($params as $key => $value) {
        // ignore empty values or empty arrays etc
        if (CRM_Utils_System::isNull($value)) {
            continue;
        }
        //Handling Custom Data
        if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
            $values[$key] = $value;
            $type = $customFields[$customFieldID]['html_type'];
            if ($type == 'CheckBox' || $type == 'Multi-Select') {
                $mulValues = explode(',', $value);
                $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, true);
                $values[$key] = array();
                foreach ($mulValues as $v1) {
                    foreach ($customOption as $customValueID => $customLabel) {
                        $customValue = $customLabel['value'];
                        if (strtolower($customLabel['label']) == strtolower(trim($v1)) || strtolower($customValue) == strtolower(trim($v1))) {
                            if ($type == 'CheckBox') {
                                $values[$key][$customValue] = 1;
                            } else {
                                $values[$key][] = $customValue;
                            }
                        }
                    }
                }
            } else {
                if ($type == 'Select' || $type == 'Radio') {
                    $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, true);
                    foreach ($customOption as $customValue => $customLabel) {
                        if (strtolower($customLabel) == strtolower(trim($v1)) || strtolower($customValue) == strtolower(trim($v1))) {
                            $values[$key] = $customValue;
                        }
                    }
                }
            }
        } else {
            if ($key == 'target_contact_id') {
                if (!CRM_Utils_Rule::integer($value)) {
                    return civicrm_create_error("contact_id not valid: {$value}");
                }
                $contactID = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_contact WHERE id = {$value}");
                if (!$contactID) {
                    return civicrm_create_error("Invalid Contact ID: There is no contact record with contact_id = {$value}.");
                }
            }
        }
    }
    return null;
}
开发者ID:bhirsch,项目名称:voipdev,代码行数:69,代码来源:utils.php

示例14: setProfileDefaults

 /**
  * Set default values for custom data used in profile.
  *
  * @param int $customFieldId
  *   Custom field id.
  * @param string $elementName
  *   Custom field name.
  * @param array $defaults
  *   Associated array of fields.
  * @param int $contactId
  *   Contact id.
  * @param int $mode
  *   Profile mode.
  * @param mixed $value
  *   If passed - dont fetch value from db,.
  *                               just format the given value
  *
  */
 public static function setProfileDefaults($customFieldId, $elementName, &$defaults, $contactId = NULL, $mode = NULL, $value = NULL)
 {
     //get the type of custom field
     $customField = new CRM_Core_BAO_CustomField();
     $customField->id = $customFieldId;
     $customField->find(TRUE);
     if (!$contactId) {
         if ($mode == CRM_Profile_Form::MODE_CREATE) {
             $value = $customField->default_value;
         }
     } else {
         if (!isset($value)) {
             $info = self::getTableColumnGroup($customFieldId);
             $query = "SELECT {$info[0]}.{$info[1]} as value FROM {$info[0]} WHERE {$info[0]}.entity_id = {$contactId}";
             $result = CRM_Core_DAO::executeQuery($query);
             if ($result->fetch()) {
                 $value = $result->value;
             }
         }
         if ($customField->data_type == 'Country') {
             if (!$value) {
                 $config = CRM_Core_Config::singleton();
                 if ($config->defaultContactCountry) {
                     $value = $config->defaultContactCountry();
                 }
             }
         }
     }
     //set defaults if mode is registration
     if (!trim($value) && $value !== 0 && !in_array($mode, array(CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH))) {
         $value = $customField->default_value;
     }
     if ($customField->data_type == 'Money' && isset($value)) {
         $value = number_format($value, 2);
     }
     switch ($customField->html_type) {
         case 'CheckBox':
         case 'AdvMulti-Select':
         case 'Multi-Select':
             $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldId, FALSE);
             $defaults[$elementName] = array();
             $checkedValue = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($value, 1, -1));
             foreach ($customOption as $val) {
                 if (in_array($val['value'], $checkedValue)) {
                     if ($customField->html_type == 'CheckBox') {
                         $defaults[$elementName][$val['value']] = 1;
                     } elseif ($customField->html_type == 'Multi-Select' || $customField->html_type == 'AdvMulti-Select') {
                         $defaults[$elementName][$val['value']] = $val['value'];
                     }
                 }
             }
             break;
         case 'Select Date':
             if ($value) {
                 list($defaults[$elementName], $defaults[$elementName . '_time']) = CRM_Utils_Date::setDateDefaults($value, NULL, $customField->date_format, $customField->time_format);
             }
             break;
         case 'Autocomplete-Select':
             if ($customField->data_type == 'ContactReference') {
                 if (is_numeric($value)) {
                     $defaults[$elementName . '_id'] = $value;
                     $defaults[$elementName] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $value, 'sort_name');
                 }
             } else {
                 $defaults[$elementName] = $value;
             }
             break;
         default:
             $defaults[$elementName] = $value;
     }
 }
开发者ID:Hack4Eugene,项目名称:Hack4Cause2016,代码行数:89,代码来源:CustomField.php

示例15: updateSavedSearch

 /**
  * Update saved search for multi-select custom fields on DB upgrade
  *
  * @param CRM_Queue_TaskContext $ctx
  *
  * @return bool TRUE for success
  */
 public static function updateSavedSearch(CRM_Queue_TaskContext $ctx)
 {
     $sql = "SELECT id, form_values FROM civicrm_saved_search";
     $dao = CRM_Core_DAO::executeQuery($sql);
     while ($dao->fetch()) {
         $copy = $formValues = unserialize($dao->form_values);
         $update = FALSE;
         foreach ($copy as $field => $data_value) {
             if (preg_match('/^custom_/', $field) && is_array($data_value) && !array_key_exists("{$field}_operator", $formValues)) {
                 // Now check for CiviCRM_OP_OR as either key or value in the data_value array.
                 // This is the conclusive evidence of an old-style data format.
                 if (array_key_exists('CiviCRM_OP_OR', $data_value) || FALSE !== array_search('CiviCRM_OP_OR', $data_value)) {
                     // We have old style data. Mark this record to be updated.
                     $update = TRUE;
                     $op = 'and';
                     if (!preg_match('/^custom_([0-9]+)/', $field, $matches)) {
                         // fatal error?
                         continue;
                     }
                     $fieldID = $matches[1];
                     if (array_key_exists('CiviCRM_OP_OR', $data_value)) {
                         // This indicates data structure identified by jamie in the form:
                         // value1 => 1, value2 => , value3 => 1.
                         $data_value = array_keys($data_value, 1);
                         // If CiviCRM_OP_OR - change OP from default to OR
                         if ($data_value['CiviCRM_OP_OR'] == 1) {
                             $op = 'or';
                         }
                         unset($data_value['CiviCRM_OP_OR']);
                     } else {
                         // The value is here, but it is not set as a key.
                         // This is using the style identified by Monish - the existence of the value
                         // indicates an OR search and values are set in the form of:
                         // 0 => value1, 1 => value1, 3 => value2.
                         $key = array_search('CiviCRM_OP_OR', $data_value);
                         $op = 'or';
                         unset($data_value[$key]);
                     }
                     //If only Or operator has been chosen, means we need to select all values and
                     //so to execute OR operation between these values according to new data structure
                     if (count($data_value) == 0 && $op == 'or') {
                         $customOption = CRM_Core_BAO_CustomOption::getCustomOption($fieldID);
                         foreach ($customOption as $option) {
                             $data_value[] = CRM_Utils_Array::value('value', $option);
                         }
                     }
                     $formValues[$field] = $data_value;
                     $formValues["{$field}_operator"] = $op;
                 }
             }
         }
         if ($update) {
             $sql = "UPDATE civicrm_saved_search SET form_values = %0 WHERE id = %1";
             CRM_Core_DAO::executeQuery($sql, array(array(serialize($formValues), 'String'), array($dao->id, 'Integer')));
         }
     }
     return TRUE;
 }
开发者ID:nielosz,项目名称:civicrm-core,代码行数:65,代码来源:FourFive.php


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