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


PHP CRM_Core_BAO_CustomField::getOptions方法代码示例

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


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

示例1: testHookFieldOptionsWithCustomFields

 /**
  * Ensure hook_civicrm_fieldOptions works with custom fields
  */
 public function testHookFieldOptionsWithCustomFields()
 {
     // Create a custom field group for testing.
     $custom_group_name = md5(microtime());
     $api_params = array('title' => $custom_group_name, 'extends' => 'Individual', 'is_active' => TRUE);
     $customGroup = $this->callAPISuccess('customGroup', 'create', $api_params);
     // Add a custom select field.
     $api_params = array('custom_group_id' => $customGroup['id'], 'label' => $custom_group_name . 1, 'html_type' => 'Select', 'data_type' => 'String', 'option_values' => array('foo' => 'Foo', 'bar' => 'Bar'));
     $result = $this->callAPISuccess('custom_field', 'create', $api_params);
     $customField1 = $result['id'];
     // Add a custom country field.
     $api_params = array('custom_group_id' => $customGroup['id'], 'label' => $custom_group_name . 2, 'html_type' => 'Select Country', 'data_type' => 'Country');
     $result = $this->callAPISuccess('custom_field', 'create', $api_params);
     $customField2 = $result['id'];
     // Add a custom boolean field.
     $api_params = array('custom_group_id' => $customGroup['id'], 'label' => $custom_group_name . 3, 'html_type' => 'Radio', 'data_type' => 'Boolean');
     $result = $this->callAPISuccess('custom_field', 'create', $api_params);
     $customField3 = $result['id'];
     $this->targetField = 'custom_' . $customField1;
     $this->replaceOptions = NULL;
     $this->appendOptions = array('baz' => 'Baz');
     $field = new CRM_Core_BAO_CustomField();
     $field->id = $customField1;
     $this->assertEquals(array('foo' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz'), $field->getOptions());
     $this->targetField = 'custom_' . $customField2;
     $this->replaceOptions = array('nowhere' => 'Nowhere');
     $field = new CRM_Core_BAO_CustomField();
     $field->id = $customField2;
     $this->assertEquals($this->replaceOptions + $this->appendOptions, $field->getOptions());
     $this->targetField = 'custom_' . $customField3;
     $this->replaceOptions = NULL;
     $this->appendOptions = array(2 => 'Maybe');
     $options = CRM_Core_PseudoConstant::get('CRM_Core_BAO_CustomField', $this->targetField);
     $this->assertEquals(array(1 => 'Yes', 0 => 'No', 2 => 'Maybe'), $options);
     $field->free();
 }
开发者ID:kcristiano,项目名称:civicrm-core,代码行数:39,代码来源:FieldOptionsTest.php

示例2: get

 /**
  * Low-level option getter, rarely accessed directly.
  * NOTE: Rather than calling this function directly use CRM_*_BAO_*::buildOptions()
  * @see http://wiki.civicrm.org/confluence/display/CRMDOC/Pseudoconstant+%28option+list%29+Reference
  *
  * NOTE: If someone undertakes a refactoring of this, please consider the use-case of
  * the Setting.getoptions API. There is no DAO/field, but it would be nice to use the
  * same 'pseudoconstant' struct in *.settings.php. This means loosening the coupling
  * between $field lookup and the $pseudoconstant evaluation.
  *
  * @param string $daoName
  * @param string $fieldName
  * @param array $params
  * - name       string  name of the option group
  * - flip       boolean results are return in id => label format if false
  *                            if true, the results are reversed
  * - grouping   boolean if true, return the value in 'grouping' column (currently unsupported for tables other than option_value)
  * - localize   boolean if true, localize the results before returning
  * - condition  string|array add condition(s) to the sql query - will be concatenated using 'AND'
  * - keyColumn  string the column to use for 'id'
  * - labelColumn string the column to use for 'label'
  * - orderColumn string the column to use for sorting, defaults to 'weight' column if one exists, else defaults to labelColumn
  * - onlyActive boolean return only the action option values
  * - fresh      boolean ignore cache entries and go back to DB
  * @param string $context : Context string
  *
  * @return array|bool
  *   array on success, FALSE on error.
  *
  */
 public static function get($daoName, $fieldName, $params = array(), $context = NULL)
 {
     CRM_Core_DAO::buildOptionsContext($context);
     $flip = !empty($params['flip']);
     // Merge params with defaults
     $params += array('grouping' => FALSE, 'localize' => FALSE, 'onlyActive' => $context == 'validate' || $context == 'get' ? FALSE : TRUE, 'fresh' => FALSE, 'context' => $context);
     $entity = CRM_Core_DAO_AllCoreTables::getBriefName(CRM_Core_DAO_AllCoreTables::getCanonicalClassName($daoName));
     // Custom fields are not in the schema
     if (strpos($fieldName, 'custom_') === 0 && is_numeric($fieldName[7])) {
         $customField = new CRM_Core_BAO_CustomField();
         $customField->id = (int) substr($fieldName, 7);
         $options = $customField->getOptions();
         if ($options && $flip) {
             $options = array_flip($options);
         }
         $customField->free();
         return $options;
     }
     // Core field: load schema
     $dao = new $daoName();
     $fieldSpec = $dao->getFieldSpec($fieldName);
     $dao->free();
     // Ensure we have the canonical name for this field
     $fieldName = CRM_Utils_Array::value('name', $fieldSpec, $fieldName);
     // Return false if field doesn't exist.
     if (empty($fieldSpec)) {
         return FALSE;
     } elseif (!empty($fieldSpec['pseudoconstant'])) {
         $pseudoconstant = $fieldSpec['pseudoconstant'];
         // if callback is specified..
         if (!empty($pseudoconstant['callback'])) {
             return call_user_func(Civi\Core\Resolver::singleton()->get($pseudoconstant['callback']));
         }
         // Merge params with schema defaults
         $params += array('condition' => CRM_Utils_Array::value('condition', $pseudoconstant, array()), 'keyColumn' => CRM_Utils_Array::value('keyColumn', $pseudoconstant), 'labelColumn' => CRM_Utils_Array::value('labelColumn', $pseudoconstant));
         if ($context == 'abbreviate') {
             switch ($fieldName) {
                 case 'state_province_id':
                     $params['labelColumn'] = 'abbreviation';
                     break;
                 case 'country_id':
                     $params['labelColumn'] = 'iso_code';
                     break;
                 default:
             }
         }
         // Fetch option group from option_value table
         if (!empty($pseudoconstant['optionGroupName'])) {
             if ($context == 'validate') {
                 $params['labelColumn'] = 'name';
             }
             if ($context == 'match') {
                 $params['keyColumn'] = 'name';
             }
             // Call our generic fn for retrieving from the option_value table
             $options = CRM_Core_OptionGroup::values($pseudoconstant['optionGroupName'], $flip, $params['grouping'], $params['localize'], $params['condition'] ? ' AND ' . implode(' AND ', (array) $params['condition']) : NULL, $params['labelColumn'] ? $params['labelColumn'] : 'label', $params['onlyActive'], $params['fresh'], $params['keyColumn'] ? $params['keyColumn'] : 'value');
             CRM_Utils_Hook::fieldOptions($entity, $fieldName, $options, $params);
             return $options;
         }
         // Fetch options from other tables
         if (!empty($pseudoconstant['table'])) {
             // Normalize params so the serialized cache string will be consistent.
             CRM_Utils_Array::remove($params, 'flip', 'fresh');
             ksort($params);
             $cacheKey = $daoName . $fieldName . serialize($params);
             // Retrieve cached options
             if (isset(self::$cache[$cacheKey]) && empty($params['fresh'])) {
                 $output = self::$cache[$cacheKey];
             } else {
                 $daoName = CRM_Core_DAO_AllCoreTables::getClassForTable($pseudoconstant['table']);
//.........这里部分代码省略.........
开发者ID:vincent1892,项目名称:civicrm-core,代码行数:101,代码来源:PseudoConstant.php


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