/** * Function to pre processing * * @return None * @access public */ function preProcess() { $this->_rgid = CRM_Utils_Request::retrieve('id', 'Positive', $this, false, 0); $this->_contactType = CRM_Utils_Request::retrieve('contact_type', 'String', $this, false, 0); if ($this->_rgid) { $rgDao =& new CRM_Dedupe_DAO_RuleGroup(); $rgDao->id = $this->_rgid; $rgDao->find(true); $this->_defaults['threshold'] = $rgDao->threshold; $this->_contactType = $rgDao->contact_type; $this->_defaults['level'] = $rgDao->level; $this->_defaults['name'] = $rgDao->name; $ruleDao =& new CRM_Dedupe_DAO_Rule(); $ruleDao->dedupe_rule_group_id = $this->_rgid; $ruleDao->find(); $count = 0; while ($ruleDao->fetch()) { $this->_defaults["where_{$count}"] = "{$ruleDao->rule_table}.{$ruleDao->rule_field}"; $this->_defaults["length_{$count}"] = $ruleDao->rule_length; $this->_defaults["weight_{$count}"] = $ruleDao->rule_weight; $count++; } } $supported =& CRM_Dedupe_BAO_RuleGroup::supportedFields($this->_contactType); if (is_array($supported)) { foreach ($supported as $table => $fields) { foreach ($fields as $field => $title) { $this->_fields["{$table}.{$field}"] = $title; } } } asort($this->_fields); }
/** * Pre processing. * * @return void */ public function preProcess() { // Ensure user has permission to be here if (!CRM_Core_Permission::check('administer dedupe rules')) { CRM_Utils_System::permissionDenied(); CRM_Utils_System::civiExit(); } $this->_options = CRM_Core_SelectValues::getDedupeRuleTypes(); $this->_rgid = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0); $this->_contactType = CRM_Utils_Request::retrieve('contact_type', 'String', $this, FALSE, 0); if ($this->_rgid) { $rgDao = new CRM_Dedupe_DAO_RuleGroup(); $rgDao->id = $this->_rgid; $rgDao->find(TRUE); $this->_defaults['threshold'] = $rgDao->threshold; $this->_contactType = $rgDao->contact_type; $this->_defaults['used'] = CRM_Utils_Array::key($rgDao->used, $this->_options); $this->_defaults['title'] = $rgDao->title; $this->_defaults['name'] = $rgDao->name; $this->_defaults['is_reserved'] = $rgDao->is_reserved; $this->assign('isReserved', $rgDao->is_reserved); $this->assign('ruleName', $rgDao->name); $ruleDao = new CRM_Dedupe_DAO_Rule(); $ruleDao->dedupe_rule_group_id = $this->_rgid; $ruleDao->find(); $count = 0; while ($ruleDao->fetch()) { $this->_defaults["where_{$count}"] = "{$ruleDao->rule_table}.{$ruleDao->rule_field}"; $this->_defaults["length_{$count}"] = $ruleDao->rule_length; $this->_defaults["weight_{$count}"] = $ruleDao->rule_weight; $count++; } } $supported = CRM_Dedupe_BAO_RuleGroup::supportedFields($this->_contactType); if (is_array($supported)) { foreach ($supported as $table => $fields) { foreach ($fields as $field => $title) { $this->_fields["{$table}.{$field}"] = $title; } } } asort($this->_fields); }
/** * Function to pre processing * * @return None * @access public */ function preProcess() { // Ensure user has permission to be here require_once 'CRM/Core/Permission.php'; if (!CRM_Core_Permission::check('administer dedupe rules')) { CRM_Utils_System::permissionDenied(); CRM_Utils_System::civiExit(); } $this->_rgid = CRM_Utils_Request::retrieve('id', 'Positive', $this, false, 0); $this->_contactType = CRM_Utils_Request::retrieve('contact_type', 'String', $this, false, 0); if ($this->_rgid) { $rgDao = new CRM_Dedupe_DAO_RuleGroup(); $rgDao->id = $this->_rgid; $rgDao->find(true); $this->_defaults['threshold'] = $rgDao->threshold; $this->_contactType = $rgDao->contact_type; $this->_defaults['level'] = $rgDao->level; $this->_defaults['name'] = $rgDao->name; $this->_defaults['is_default'] = $rgDao->is_default; $ruleDao = new CRM_Dedupe_DAO_Rule(); $ruleDao->dedupe_rule_group_id = $this->_rgid; $ruleDao->find(); $count = 0; while ($ruleDao->fetch()) { $this->_defaults["where_{$count}"] = "{$ruleDao->rule_table}.{$ruleDao->rule_field}"; $this->_defaults["length_{$count}"] = $ruleDao->rule_length; $this->_defaults["weight_{$count}"] = $ruleDao->rule_weight; $count++; } } $supported =& CRM_Dedupe_BAO_RuleGroup::supportedFields($this->_contactType); if (is_array($supported)) { foreach ($supported as $table => $fields) { foreach ($fields as $field => $title) { $this->_fields["{$table}.{$field}"] = $title; } } } asort($this->_fields); }
/** * 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; }