Exemple #1
0
 protected function getSchemaChecksum()
 {
     if (!$this->checksum) {
         CRM_Utils_Array::flatten($this->tables, $flat);
         ksort($flat);
         $this->checksum = md5(json_encode($flat));
     }
     return $this->checksum;
 }
 /**
  * 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;
 }
 /**
  * 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);
 }
 /**
  * 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;
 }