/** * Function to process the form * * @access public * @return None */ function postProcess() { require_once 'CRM/Core/BAO/DupeMatch.php'; $params = $this->exportValues(); if (!$this->_advanced) { $rule = array(); for ($count = 1; $count <= 5; $count++) { if ($params['match_on_' . $count] != '') { $rule[] = $params['match_on_' . $count]; } } if (count($rule) >= 1) { $rule = implode(' AND ', $rule); $dupematch = CRM_Core_BAO_DupeMatch::add($rule); } } else { $inValid = false; $rule = trim($params['match_on']); $tokens = preg_split('/[\\s]+/', $rule, -1, PREG_SPLIT_NO_EMPTY); //$tokens = preg_split('/([AND])|([OR()])/',$rule, -1 ,PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY); $openParen = $closeParen = $andCount = $orCount = $fieldCount = 0; foreach ($tokens as $token) { $token = trim($token); if ($token == '(') { $openParen++; } else { if ($token == ')') { $closeParen++; } else { if ($token == 'AND') { $andCount++; } else { if ($token == 'OR') { $orCount++; } else { $fieldCount++; } } } } } if ($openParen != $closeParen || $fieldCount - 1 != $andCount + $orCount) { $inValid = true; } // need to do proper validation $fields =& CRM_Contact_BAO_Contact::importableFields('Individual', 1); $ruleFields = preg_split('/[ANDOR()\\s]+/', $rule, -1, PREG_SPLIT_NO_EMPTY); foreach ($ruleFields as $value) { if (isset($value)) { if (!array_key_exists($value, $fields)) { $inValid = true; } } } if ($inValid) { CRM_Core_Session::setStatus(ts("The Duplicate Matching rule has not been saved, because the rule is invalid. Rules should contain only valid field names, 'AND', 'OR' or parentheses.")); return; } else { $dupematch = CRM_Core_BAO_DupeMatch::add($rule); } } CRM_Core_Session::setStatus(ts('The Duplicate Matching rule has been saved.')); }
/** * retrieve the list of suffix * * @param NULL * * @return object The default activity type object on success, * null otherwise * @static * @access public */ function &getDefault() { if ($GLOBALS['_CRM_CORE_BAO_DUPEMATCH']['_defaultIndividualSuffix'] == null) { $defaults = array(); $GLOBALS['_CRM_CORE_BAO_DUPEMATCH']['_defaultIndividualSuffix'] = CRM_Core_BAO_DupeMatch::retrieve($params, $defaults); } return $GLOBALS['_CRM_CORE_BAO_DUPEMATCH']['_defaultIndividualSuffix']; }