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


PHP CRM_Utils_Array::flatten方法代码示例

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


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

示例1: getSchemaChecksum

 protected function getSchemaChecksum()
 {
     if (!$this->checksum) {
         CRM_Utils_Array::flatten($this->tables, $flat);
         ksort($flat);
         $this->checksum = md5(json_encode($flat));
     }
     return $this->checksum;
 }
开发者ID:nielosz,项目名称:civicrm-core,代码行数:9,代码来源:Reflection.php

示例2: formatParams

 /**
  * A hackish function needed to massage CRM_Contact_Form_$ctype::formRule()
  * object into a valid $params array for dedupe
  *
  * @param array $fields  contact structure from formRule()
  * @param string $ctype  contact type of the given contact
  *
  * @return array  valid $params array for dedupe
  */
 static function formatParams($fields, $ctype)
 {
     $flat = array();
     CRM_Utils_Array::flatten($fields, $flat);
     $replace_these = array('individual_prefix' => 'prefix_id', 'individual_suffix' => 'suffix_id', 'gender' => 'gender_id');
     //handle for individual_suffix, individual_prefix, gender
     foreach (array('individual_suffix', 'individual_prefix', 'gender') as $name) {
         if (CRM_Utils_Array::value($name, $fields)) {
             $flat[$replace_these[$name]] = $flat[$name];
             unset($flat[$name]);
         }
     }
     // handle {birth,deceased}_date
     foreach (array('birth_date', 'deceased_date') as $date) {
         if (CRM_Utils_Array::value($date, $fields)) {
             $flat[$date] = $fields[$date];
             if (is_array($flat[$date])) {
                 $flat[$date] = CRM_Utils_Date::format($flat[$date]);
             }
             $flat[$date] = CRM_Utils_Date::processDate($flat[$date]);
         }
     }
     if (CRM_Utils_Array::value('contact_source', $flat)) {
         $flat['source'] = $flat['contact_source'];
         unset($flat['contact_source']);
     }
     // handle preferred_communication_method
     if (array_key_exists('preferred_communication_method', $fields)) {
         $methods = array_intersect($fields['preferred_communication_method'], array('1'));
         $methods = array_keys($methods);
         sort($methods);
         if ($methods) {
             $flat['preferred_communication_method'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, $methods) . CRM_Core_DAO::VALUE_SEPARATOR;
         }
     }
     // handle custom data
     $tree = CRM_Core_BAO_CustomGroup::getTree($ctype, CRM_Core_DAO::$_nullObject, NULL, -1);
     CRM_Core_BAO_CustomGroup::postProcess($tree, $fields, TRUE);
     foreach ($tree as $key => $cg) {
         if (!is_int($key)) {
             continue;
         }
         foreach ($cg['fields'] as $cf) {
             $flat[$cf['column_name']] = CRM_Utils_Array::value('data', $cf['customValue']);
         }
     }
     // if the key is dotted, keep just the last part of it
     foreach ($flat as $key => $value) {
         if (substr_count($key, '.')) {
             $last = array_pop(explode('.', $key));
             // make sure the first occurence is kept, not the last
             if (!isset($flat[$last])) {
                 $flat[$last] = $value;
             }
             unset($flat[$key]);
         }
     }
     // drop the -digit (and -Primary, for CRM-3902) postfixes (so event registration's $flat['email-5'] becomes $flat['email'])
     // FIXME: CRM-5026 should be fixed here; the below clobbers all address info; we should split off address fields and match
     // the -digit to civicrm_address.location_type_id and -Primary to civicrm_address.is_primary
     foreach ($flat as $key => $value) {
         $matches = array();
         if (preg_match('/(.*)-(\\d+|Primary)$/', $key, $matches)) {
             $flat[$matches[1]] = $value;
             unset($flat[$key]);
         }
     }
     $params = array();
     $supportedFields = CRM_Dedupe_BAO_RuleGroup::supportedFields($ctype);
     if (is_array($supportedFields)) {
         foreach ($supportedFields as $table => $fields) {
             if ($table == 'civicrm_address') {
                 // for matching on civicrm_address fields, we also need the location_type_id
                 $fields['location_type_id'] = '';
                 // FIXME: we also need to do some hacking for id and name fields, see CRM-3902’s comments
                 $fixes = array('address_name' => 'name', 'country' => 'country_id', 'state_province' => 'state_province_id', 'county' => 'county_id');
                 foreach ($fixes as $orig => $target) {
                     if (CRM_Utils_Array::value($orig, $flat)) {
                         $params[$table][$target] = $flat[$orig];
                     }
                 }
             }
             foreach ($fields as $field => $title) {
                 if (CRM_Utils_Array::value($field, $flat)) {
                     $params[$table][$field] = $flat[$field];
                 }
             }
         }
     }
     return $params;
 }
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:100,代码来源:Finder.php

示例3: assertTreeEquals

 /**
  * Assert that two array-trees are exactly equal, notwithstanding
  * the sorting of keys
  *
  * @param array $expected
  * @param array $actual
  */
 public function assertTreeEquals($expected, $actual)
 {
     $e = array();
     $a = array();
     CRM_Utils_Array::flatten($expected, $e, '', ':::');
     CRM_Utils_Array::flatten($actual, $a, '', ':::');
     ksort($e);
     ksort($a);
     $this->assertEquals($e, $a);
 }
开发者ID:nielosz,项目名称:civicrm-core,代码行数:17,代码来源:CiviUnitTestCase.php

示例4: render

 /**
  * Render a message.
  *
  * @param string $name
  *   The name previously registered with addMessage().
  * @param TokenRow|int $row
  *   The object or ID for the row previously registered with addRow().
  * @return string
  *   Fully rendered message, with tokens merged.
  */
 public function render($name, $row)
 {
     if (!is_object($row)) {
         $row = $this->getRow($row);
     }
     $message = $this->getMessage($name);
     $row->fill($message['format']);
     $useSmarty = !empty($row->context['smarty']);
     // FIXME preg_callback.
     $tokens = $this->rowValues[$row->tokenRow][$message['format']];
     $flatTokens = array();
     \CRM_Utils_Array::flatten($tokens, $flatTokens, '', '.');
     $filteredTokens = array();
     foreach ($flatTokens as $k => $v) {
         $filteredTokens['{' . $k . '}'] = $useSmarty ? \CRM_Utils_Token::tokenEscapeSmarty($v) : $v;
     }
     $event = new TokenRenderEvent($this);
     $event->message = $message;
     $event->context = $row->context;
     $event->row = $row;
     $event->string = strtr($message['string'], $filteredTokens);
     $this->dispatcher->dispatch(Events::TOKEN_RENDER, $event);
     return $event->string;
 }
开发者ID:kcristiano,项目名称:civicrm-core,代码行数:34,代码来源:TokenProcessor.php


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