本文整理汇总了PHP中CRM_Contact_BAO_ContactType::isExtendsContactType方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contact_BAO_ContactType::isExtendsContactType方法的具体用法?PHP CRM_Contact_BAO_ContactType::isExtendsContactType怎么用?PHP CRM_Contact_BAO_ContactType::isExtendsContactType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Contact_BAO_ContactType
的用法示例。
在下文中一共展示了CRM_Contact_BAO_ContactType::isExtendsContactType方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processAction
/**
* Method processAction to execute the action
*
* @param CRM_Civirules_EventData_EventData $eventData
* @access public
*
*/
public function processAction(CRM_Civirules_EventData_EventData $eventData)
{
$contactId = $eventData->getContactId();
$subTypes = CRM_Contact_BAO_Contact::getContactSubType($contactId);
$contactType = CRM_Contact_BAO_Contact::getContactType($contactId);
$changed = false;
$action_params = $this->getActionParameters();
foreach ($action_params['sub_type'] as $sub_type) {
if (CRM_Contact_BAO_ContactType::isExtendsContactType($sub_type, $contactType)) {
$subTypes[] = $sub_type;
$changed = true;
}
}
if ($changed) {
$params['id'] = $contactId;
$params['contact_id'] = $contactId;
$params['contact_type'] = $contactType;
$params['contact_sub_type'] = $subTypes;
CRM_Contact_BAO_Contact::add($params);
}
}
示例2: preProcess
/**
* Build all the data structures needed to build the form.
*/
public function preProcess()
{
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add');
$this->_dedupeButtonName = $this->getButtonName('refresh', 'dedupe');
$this->_duplicateButtonName = $this->getButtonName('upload', 'duplicate');
CRM_Core_Resources::singleton()->addStyleFile('civicrm', 'css/contactSummary.css', 2, 'html-header');
$session = CRM_Core_Session::singleton();
if ($this->_action == CRM_Core_Action::ADD) {
// check for add contacts permissions
if (!CRM_Core_Permission::check('add contacts')) {
CRM_Utils_System::permissionDenied();
CRM_Utils_System::civiExit();
}
$this->_contactType = CRM_Utils_Request::retrieve('ct', 'String', $this, TRUE, NULL, 'REQUEST');
if (!in_array($this->_contactType, array('Individual', 'Household', 'Organization'))) {
CRM_Core_Error::statusBounce(ts('Could not get a contact id and/or contact type'));
}
$this->_isContactSubType = FALSE;
if ($this->_contactSubType = CRM_Utils_Request::retrieve('cst', 'String', $this)) {
$this->_isContactSubType = TRUE;
}
if ($this->_contactSubType && !CRM_Contact_BAO_ContactType::isExtendsContactType($this->_contactSubType, $this->_contactType, TRUE)) {
CRM_Core_Error::statusBounce(ts("Could not get a valid contact subtype for contact type '%1'", array(1 => $this->_contactType)));
}
$this->_gid = CRM_Utils_Request::retrieve('gid', 'Integer', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'GET');
$this->_tid = CRM_Utils_Request::retrieve('tid', 'Integer', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'GET');
$typeLabel = CRM_Contact_BAO_ContactType::contactTypePairs(TRUE, $this->_contactSubType ? $this->_contactSubType : $this->_contactType);
$typeLabel = implode(' / ', $typeLabel);
CRM_Utils_System::setTitle(ts('New %1', array(1 => $typeLabel)));
$session->pushUserContext(CRM_Utils_System::url('civicrm/dashboard', 'reset=1'));
$this->_contactId = NULL;
} else {
//update mode
if (!$this->_contactId) {
$this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
}
if ($this->_contactId) {
$defaults = array();
$params = array('id' => $this->_contactId);
$returnProperities = array('id', 'contact_type', 'contact_sub_type', 'modified_date', 'is_deceased');
CRM_Core_DAO::commonRetrieve('CRM_Contact_DAO_Contact', $params, $defaults, $returnProperities);
if (empty($defaults['id'])) {
CRM_Core_Error::statusBounce(ts('A Contact with that ID does not exist: %1', array(1 => $this->_contactId)));
}
$this->_contactType = CRM_Utils_Array::value('contact_type', $defaults);
$this->_contactSubType = CRM_Utils_Array::value('contact_sub_type', $defaults);
// check for permissions
$session = CRM_Core_Session::singleton();
if (!CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT)) {
CRM_Core_Error::statusBounce(ts('You do not have the necessary permission to edit this contact.'));
}
$displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
if ($defaults['is_deceased']) {
$displayName .= ' <span class="crm-contact-deceased">(deceased)</span>';
}
$displayName = ts('Edit %1', array(1 => $displayName));
// Check if this is default domain contact CRM-10482
if (CRM_Contact_BAO_Contact::checkDomainContact($this->_contactId)) {
$displayName .= ' (' . ts('default organization') . ')';
}
// omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container
CRM_Utils_System::setTitle($displayName);
$context = CRM_Utils_Request::retrieve('context', 'String', $this);
$qfKey = CRM_Utils_Request::retrieve('key', 'String', $this);
$urlParams = 'reset=1&cid=' . $this->_contactId;
if ($context) {
$urlParams .= "&context={$context}";
}
if (CRM_Utils_Rule::qfKey($qfKey)) {
$urlParams .= "&key={$qfKey}";
}
$session->pushUserContext(CRM_Utils_System::url('civicrm/contact/view', $urlParams));
$values = $this->get('values');
// get contact values.
if (!empty($values)) {
$this->_values = $values;
} else {
$params = array('id' => $this->_contactId, 'contact_id' => $this->_contactId, 'noRelationships' => TRUE, 'noNotes' => TRUE, 'noGroups' => TRUE);
$contact = CRM_Contact_BAO_Contact::retrieve($params, $this->_values, TRUE);
$this->set('values', $this->_values);
}
} else {
CRM_Core_Error::statusBounce(ts('Could not get a contact_id and/or contact_type'));
}
}
// parse street address, CRM-5450
$this->_parseStreetAddress = $this->get('parseStreetAddress');
if (!isset($this->_parseStreetAddress)) {
$addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options');
$this->_parseStreetAddress = FALSE;
if (!empty($addressOptions['street_address']) && !empty($addressOptions['street_address_parsing'])) {
$this->_parseStreetAddress = TRUE;
}
$this->set('parseStreetAddress', $this->_parseStreetAddress);
}
$this->assign('parseStreetAddress', $this->_parseStreetAddress);
$this->_editOptions = $this->get('contactEditOptions');
//.........这里部分代码省略.........
示例3: import
/**
* handle the values in import mode
*
* @param int $onDuplicate the code for what action to take on duplicates
* @param array $values the array of values belonging to this line
*
* @return boolean the result of this processing
* @access public
*/
function import($onDuplicate, &$values, $doGeocodeAddress = false)
{
$config =& CRM_Core_Config::singleton();
$this->_unparsedStreetAddressContacts = array();
if (!$doGeocodeAddress) {
// CRM-5854, reset the geocode method to null to prevent geocoding
$config->geocodeMethod = null;
}
// first make sure this is a valid line
//$this->_updateWithId = false;
$response = $this->summary($values);
$statusFieldName = $this->_statusFieldName;
if ($response != CRM_Import_Parser::VALID) {
$importRecordParams = array($statusFieldName => 'INVALID', "{$statusFieldName}Msg" => "Invalid (Error Code: {$response})");
$this->updateImportRecord($values[count($values) - 1], $importRecordParams);
return $response;
}
$params =& $this->getActiveFieldParams();
$formatted = array('contact_type' => $this->_contactType);
static $contactFields = null;
if ($contactFields == null) {
require_once "CRM/Contact/DAO/Contact.php";
$contactFields =& CRM_Contact_DAO_Contact::import();
}
//check if external identifier exists in database
if (CRM_Utils_Array::value('external_identifier', $params) && (CRM_Utils_Array::value('id', $params) || in_array($onDuplicate, array(CRM_Import_Parser::DUPLICATE_SKIP, CRM_Import_Parser::DUPLICATE_NOCHECK)))) {
require_once "CRM/Contact/BAO/Contact.php";
if ($internalCid = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $params['external_identifier'], 'id', 'external_identifier')) {
if ($internalCid != CRM_Utils_Array::value('id', $params)) {
$errorMessage = ts('External Identifier already exists in database.');
array_unshift($values, $errorMessage);
$importRecordParams = array($statusFieldName => 'ERROR', "{$statusFieldName}Msg" => $errorMessage);
$this->updateImportRecord($values[count($values) - 1], $importRecordParams);
return CRM_Import_Parser::ERROR;
}
}
}
if (!empty($this->_contactSubType)) {
$params['contact_sub_type'] = $this->_contactSubType;
}
if ($subType = CRM_Utils_Array::value('contact_sub_type', $params)) {
if (CRM_Contact_BAO_ContactType::isExtendsContactType($subType, $this->_contactType, false, 'label')) {
$subTypes = CRM_Contact_BAO_ContactType::subTypePairs($this->_contactType, false, null);
$params['contact_sub_type'] = array_search($subType, $subTypes);
} elseif (!CRM_Contact_BAO_ContactType::isExtendsContactType($subType, $this->_contactType)) {
$message = "Mismatched or Invalid Contact SubType.";
array_unshift($values, $message);
return CRM_Import_Parser::NO_MATCH;
}
}
//get contact id to format common data in update/fill mode,
//if external identifier is present, CRM-4423
if ($this->_updateWithId && !CRM_Utils_Array::value('id', $params) && CRM_Utils_Array::value('external_identifier', $params)) {
if ($cid = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $params['external_identifier'], 'id', 'external_identifier')) {
$formatted['id'] = $cid;
}
}
//format common data, CRM-4062
$this->formatCommonData($params, $formatted, $contactFields);
$relationship = false;
$createNewContact = true;
// Support Match and Update Via Contact ID
if ($this->_updateWithId) {
$createNewContact = false;
if (!CRM_Utils_Array::value('id', $params) && CRM_Utils_Array::value('external_identifier', $params)) {
if ($cid) {
$params['id'] = $cid;
} else {
//update contact if dedupe found contact id, CRM-4148
$dedupeParams = $formatted;
//special case to check dedupe if external id present.
//if we send external id dedupe will stop.
unset($dedupeParams['external_identifier']);
$checkDedupe = _civicrm_duplicate_formatted_contact($dedupeParams);
if (civicrm_duplicate($checkDedupe)) {
$matchingContactIds = explode(',', $checkDedupe['error_message']['params'][0]);
if (count($matchingContactIds) == 1) {
$params['id'] = array_pop($matchingContactIds);
} else {
$message = "More than one matching contact found for given criteria.";
array_unshift($values, $message);
$this->_retCode = CRM_Import_Parser::NO_MATCH;
}
} else {
$createNewContact = true;
}
}
}
$error = _civicrm_duplicate_formatted_contact($formatted);
if (civicrm_duplicate($error)) {
$matchedIDs = explode(',', $error['error_message']['params'][0]);
//.........这里部分代码省略.........
示例4: add
/**
* Takes an associative array and creates a contact object.
*
* The function extracts all the params it needs to initialize the create a
* contact object. the params array could contain additional unused name/value
* pairs
*
* @param array $params
* (reference) an assoc array of name/value pairs.
*
* @return CRM_Contact_BAO_Contact|CRM_Core_Error|NULL
* Created or updated contact object or error object.
* (error objects are being phased out in favour of exceptions)
*/
public static function add(&$params)
{
$contact = new CRM_Contact_DAO_Contact();
if (empty($params)) {
return NULL;
}
// Fix for validate contact sub type CRM-5143.
if (isset($params['contact_sub_type'])) {
if (empty($params['contact_sub_type'])) {
$params['contact_sub_type'] = 'null';
} else {
if (!CRM_Contact_BAO_ContactType::isExtendsContactType($params['contact_sub_type'], $params['contact_type'], TRUE)) {
// we'll need to fix tests to handle this
// CRM-7925
CRM_Core_Error::fatal(ts('The Contact Sub Type does not match the Contact type for this record'));
}
if (is_array($params['contact_sub_type'])) {
$params['contact_sub_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, $params['contact_sub_type']) . CRM_Core_DAO::VALUE_SEPARATOR;
} else {
$params['contact_sub_type'] = CRM_Core_DAO::VALUE_SEPARATOR . trim($params['contact_sub_type'], CRM_Core_DAO::VALUE_SEPARATOR) . CRM_Core_DAO::VALUE_SEPARATOR;
}
}
} else {
// Reset the value.
// CRM-101XX.
$params['contact_sub_type'] = 'null';
}
// Fixed contact source.
if (isset($params['contact_source'])) {
$params['source'] = $params['contact_source'];
}
// Fix for preferred communication method.
$prefComm = CRM_Utils_Array::value('preferred_communication_method', $params);
if ($prefComm && is_array($prefComm)) {
unset($params['preferred_communication_method']);
$newPref = array();
foreach ($prefComm as $k => $v) {
if ($v) {
$newPref[$k] = $v;
}
}
$prefComm = $newPref;
if (is_array($prefComm) && !empty($prefComm)) {
$prefComm = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($prefComm)) . CRM_Core_DAO::VALUE_SEPARATOR;
$contact->preferred_communication_method = $prefComm;
} else {
$contact->preferred_communication_method = '';
}
}
$allNull = $contact->copyValues($params);
$contact->id = CRM_Utils_Array::value('contact_id', $params);
if ($contact->contact_type == 'Individual') {
$allNull = FALSE;
// Format individual fields.
CRM_Contact_BAO_Individual::format($params, $contact);
} elseif ($contact->contact_type == 'Household') {
if (isset($params['household_name'])) {
$allNull = FALSE;
$contact->display_name = $contact->sort_name = CRM_Utils_Array::value('household_name', $params, '');
}
} elseif ($contact->contact_type == 'Organization') {
if (isset($params['organization_name'])) {
$allNull = FALSE;
$contact->display_name = $contact->sort_name = CRM_Utils_Array::value('organization_name', $params, '');
}
}
$privacy = CRM_Utils_Array::value('privacy', $params);
if ($privacy && is_array($privacy) && !empty($privacy)) {
$allNull = FALSE;
foreach (self::$_commPrefs as $name) {
$contact->{$name} = CRM_Utils_Array::value($name, $privacy, FALSE);
}
}
// Since hash was required, make sure we have a 0 value for it (CRM-1063).
// @todo - does this mean we can remove this block?
// Fixed in 1.5 by making hash optional, only do this in create mode, not update.
if ((!array_key_exists('hash', $contact) || !$contact->hash) && !$contact->id) {
$allNull = FALSE;
$contact->hash = md5(uniqid(rand(), TRUE));
}
// Even if we don't need $employerId, it's important to call getFieldValue() before
// the contact is saved because we want the existing value to be cached.
// createCurrentEmployerRelationship() needs the old value not the updated one. CRM-10788
$employerId = empty($contact->id) ? NULL : CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contact->id, 'employer_id');
if (!$allNull) {
$contact->save();
//.........这里部分代码省略.........
示例5: getRegistrationFields
/**
* Get all the registration fields.
*
* @param int $action
* What action are we doing.
* @param int $mode
* Mode.
*
* @param null $ctype
*
* @return array
* the fields that are needed for registration
*/
public static function getRegistrationFields($action, $mode, $ctype = NULL)
{
if ($mode & CRM_Profile_Form::MODE_REGISTER) {
$ufGroups = CRM_Core_BAO_UFGroup::getModuleUFGroup('User Registration');
} else {
$ufGroups = CRM_Core_BAO_UFGroup::getModuleUFGroup('Profile');
}
if (!is_array($ufGroups)) {
return FALSE;
}
$fields = array();
foreach ($ufGroups as $id => $title) {
if ($ctype) {
$fieldType = CRM_Core_BAO_UFField::getProfileType($id);
if ($fieldType != 'Contact' && $fieldType != $ctype && !CRM_Contact_BAO_ContactType::isExtendsContactType($fieldType, $ctype)) {
continue;
}
if (CRM_Contact_BAO_ContactType::isaSubType($fieldType)) {
$profileSubType = $fieldType;
}
}
$subset = self::getFields($id, TRUE, $action, NULL, NULL, FALSE, NULL, TRUE, $ctype);
// we do not allow duplicates. the first field is the winner
foreach ($subset as $name => $field) {
if (empty($fields[$name])) {
$fields[$name] = $field;
}
}
}
return $fields;
}
示例6: preProcess
/**
* build all the data structures needed to build the form
*
* @return void
* @access public
*/
function preProcess()
{
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add');
$this->_dedupeButtonName = $this->getButtonName('refresh', 'dedupe');
$this->_duplicateButtonName = $this->getButtonName('upload', 'duplicate');
$session = CRM_Core_Session::singleton();
if ($this->_action == CRM_Core_Action::ADD) {
// check for add contacts permissions
if (!CRM_Core_Permission::check('add contacts')) {
CRM_Utils_System::permissionDenied();
CRM_Utils_System::civiExit();
}
$this->_contactType = CRM_Utils_Request::retrieve('ct', 'String', $this, TRUE, NULL, 'REQUEST');
if (!in_array($this->_contactType, array('Individual', 'Household', 'Organization'))) {
CRM_Core_Error::statusBounce(ts('Could not get a contact id and/or contact type'));
}
$this->_isContactSubType = FALSE;
if ($this->_contactSubType = CRM_Utils_Request::retrieve('cst', 'String', $this)) {
$this->_isContactSubType = TRUE;
}
if ($this->_contactSubType && !CRM_Contact_BAO_ContactType::isExtendsContactType($this->_contactSubType, $this->_contactType, TRUE)) {
CRM_Core_Error::statusBounce(ts("Could not get a valid contact subtype for contact type '%1'", array(1 => $this->_contactType)));
}
$this->_gid = CRM_Utils_Request::retrieve('gid', 'Integer', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'GET');
$this->_tid = CRM_Utils_Request::retrieve('tid', 'Integer', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'GET');
$typeLabel = CRM_Contact_BAO_ContactType::contactTypePairs(TRUE, $this->_contactSubType ? $this->_contactSubType : $this->_contactType);
$typeLabel = implode(' / ', $typeLabel);
CRM_Utils_System::setTitle(ts('New %1', array(1 => $typeLabel)));
$session->pushUserContext(CRM_Utils_System::url('civicrm/dashboard', 'reset=1'));
$this->_contactId = NULL;
} else {
//update mode
if (!$this->_contactId) {
$this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
}
if ($this->_contactId) {
$defaults = array();
$params = array('id' => $this->_contactId);
$returnProperities = array('id', 'contact_type', 'contact_sub_type');
CRM_Core_DAO::commonRetrieve('CRM_Contact_DAO_Contact', $params, $defaults, $returnProperities);
if (!CRM_Utils_Array::value('id', $defaults)) {
CRM_Core_Error::statusBounce(ts('A Contact with that ID does not exist: %1', array(1 => $this->_contactId)));
}
$this->_contactType = CRM_Utils_Array::value('contact_type', $defaults);
$this->_contactSubType = CRM_Utils_Array::value('contact_sub_type', $defaults);
// check for permissions
$session = CRM_Core_Session::singleton();
if ($session->get('userID') != $this->_contactId && !CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT)) {
CRM_Core_Error::statusBounce(ts('You do not have the necessary permission to edit this contact.'));
}
list($displayName, $contactImage) = CRM_Contact_BAO_Contact::getDisplayAndImage($this->_contactId);
CRM_Utils_System::setTitle($displayName, $contactImage . ' ' . $displayName);
$context = CRM_Utils_Request::retrieve('context', 'String', $this);
$qfKey = CRM_Utils_Request::retrieve('key', 'String', $this);
$urlParams = 'reset=1&cid=' . $this->_contactId;
if ($context) {
$urlParams .= "&context={$context}";
}
if (CRM_Utils_Rule::qfKey($qfKey)) {
$urlParams .= "&key={$qfKey}";
}
$session->pushUserContext(CRM_Utils_System::url('civicrm/contact/view', $urlParams));
$values = $this->get('values');
// get contact values.
if (!empty($values)) {
$this->_values = $values;
} else {
$params = array('id' => $this->_contactId, 'contact_id' => $this->_contactId, 'noRelationships' => TRUE, 'noNotes' => TRUE, 'noGroups' => TRUE);
$contact = CRM_Contact_BAO_Contact::retrieve($params, $this->_values, TRUE);
$this->set('values', $this->_values);
}
} else {
CRM_Core_Error::statusBounce(ts('Could not get a contact_id and/or contact_type'));
}
}
// parse street address, CRM-5450
$this->_parseStreetAddress = $this->get('parseStreetAddress');
if (!isset($this->_parseStreetAddress)) {
$addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options');
$this->_parseStreetAddress = FALSE;
if (CRM_Utils_Array::value('street_address', $addressOptions) && CRM_Utils_Array::value('street_address_parsing', $addressOptions)) {
$this->_parseStreetAddress = TRUE;
}
$this->set('parseStreetAddress', $this->_parseStreetAddress);
}
$this->assign('parseStreetAddress', $this->_parseStreetAddress);
$this->_editOptions = $this->get('contactEditOptions');
if (CRM_Utils_System::isNull($this->_editOptions)) {
$this->_editOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_edit_options', TRUE, NULL, FALSE, 'name', TRUE, 'AND v.filter = 0');
$this->set('contactEditOptions', $this->_editOptions);
}
// build demographics only for Individual contact type
if ($this->_contactType != 'Individual' && array_key_exists('Demographics', $this->_editOptions)) {
unset($this->_editOptions['Demographics']);
//.........这里部分代码省略.........
示例7: getRegistrationFields
/**
* get all the registration fields
*
* @param int $action what action are we doing
* @param int $mode mode
*
* @return array the fields that are needed for registration
* @static
* @access public
*/
static function getRegistrationFields($action, $mode, $ctype = null)
{
if ($mode & CRM_Profile_Form::MODE_REGISTER) {
$ufGroups =& CRM_Core_BAO_UFGroup::getModuleUFGroup('User Registration');
} else {
$ufGroups =& CRM_Core_BAO_UFGroup::getModuleUFGroup('Profile');
}
if (!is_array($ufGroups)) {
return false;
}
$fields = array();
require_once "CRM/Core/BAO/UFField.php";
foreach ($ufGroups as $id => $title) {
if ($ctype) {
$fieldType = CRM_Core_BAO_UFField::getProfileType($id);
if ($fieldType != 'Contact' && $fieldType != $ctype && !CRM_Contact_BAO_ContactType::isExtendsContactType($fieldType, $ctype)) {
continue;
}
if (CRM_Contact_BAO_ContactType::isaSubType($fieldType)) {
$profileSubType = $fieldType;
}
}
$subset = self::getFields($id, true, $action, null, null, false, null, true, $ctype);
// we do not allow duplicates. the first field is the winner
foreach ($subset as $name => $field) {
if (!CRM_Utils_Array::value($name, $fields)) {
$fields[$name] = $field;
}
}
}
return $fields;
}
示例8: _civicrm_api3_deprecated_contact_check_params
/**
* @param array $params
* @param bool $dupeCheck
* @param bool $dupeErrorArray
* @param bool $requiredCheck
* @param int $dedupeRuleGroupID
*
* @return array|null
*/
function _civicrm_api3_deprecated_contact_check_params(&$params, $dupeCheck = TRUE, $dupeErrorArray = FALSE, $requiredCheck = TRUE, $dedupeRuleGroupID = NULL)
{
if (isset($params['id']) && is_numeric($params['id'])) {
$requiredCheck = FALSE;
}
if ($requiredCheck) {
if (isset($params['id'])) {
$required = array('Individual', 'Household', 'Organization');
}
$required = array('Individual' => array(array('first_name', 'last_name'), 'email'), 'Household' => array('household_name'), 'Organization' => array('organization_name'));
// contact_type has a limited number of valid values
if (empty($params['contact_type'])) {
return civicrm_api3_create_error("No Contact Type");
}
$fields = CRM_Utils_Array::value($params['contact_type'], $required);
if ($fields == NULL) {
return civicrm_api3_create_error("Invalid Contact Type: {$params['contact_type']}");
}
if ($csType = CRM_Utils_Array::value('contact_sub_type', $params)) {
if (!CRM_Contact_BAO_ContactType::isExtendsContactType($csType, $params['contact_type'])) {
return civicrm_api3_create_error("Invalid or Mismatched Contact Subtype: " . implode(', ', (array) $csType));
}
}
if (empty($params['contact_id']) && !empty($params['id'])) {
$valid = FALSE;
$error = '';
foreach ($fields as $field) {
if (is_array($field)) {
$valid = TRUE;
foreach ($field as $element) {
if (empty($params[$element])) {
$valid = FALSE;
$error .= $element;
break;
}
}
} else {
if (!empty($params[$field])) {
$valid = TRUE;
}
}
if ($valid) {
break;
}
}
if (!$valid) {
return civicrm_api3_create_error("Required fields not found for {$params['contact_type']} : {$error}");
}
}
}
if ($dupeCheck) {
// @todo switch to using api version by uncommenting these lines & removing following 11.
// Any change here is too scary for a stable release.
// $dupes = civicrm_api3('Contact', 'duplicatecheck', (array('match' => $params, 'dedupe_rule_id' => $dedupeRuleGroupID)));
// $ids = $dupes['count'] ? implode(',', array_keys($dupes['values'])) : NULL;
// check for record already existing
require_once 'CRM/Dedupe/Finder.php';
$dedupeParams = CRM_Dedupe_Finder::formatParams($params, $params['contact_type']);
// CRM-6431
// setting 'check_permission' here means that the dedupe checking will be carried out even if the
// person does not have permission to carry out de-dupes
// this is similar to the front end form
if (isset($params['check_permission'])) {
$dedupeParams['check_permission'] = $params['check_permission'];
}
$ids = implode(',', CRM_Dedupe_Finder::dupesByParams($dedupeParams, $params['contact_type'], 'Unsupervised', array(), $dedupeRuleGroupID));
if ($ids != NULL) {
if ($dupeErrorArray) {
$error = CRM_Core_Error::createError("Found matching contacts: {$ids}", CRM_Core_Error::DUPLICATE_CONTACT, 'Fatal', $ids);
return civicrm_api3_create_error($error->pop());
}
return civicrm_api3_create_error("Found matching contacts: {$ids}");
}
}
// check for organisations with same name
if (!empty($params['current_employer'])) {
$organizationParams = array();
$organizationParams['organization_name'] = $params['current_employer'];
require_once 'CRM/Dedupe/Finder.php';
$dedupParams = CRM_Dedupe_Finder::formatParams($organizationParams, 'Organization');
$dedupParams['check_permission'] = FALSE;
$dupeIds = CRM_Dedupe_Finder::dupesByParams($dedupParams, 'Organization', 'Supervised');
// check for mismatch employer name and id
if (!empty($params['employer_id']) && !in_array($params['employer_id'], $dupeIds)) {
return civicrm_api3_create_error('Employer name and Employer id Mismatch');
}
// show error if multiple organisation with same name exist
if (empty($params['employer_id']) && count($dupeIds) > 1) {
return civicrm_api3_create_error('Found more than one Organisation with same Name.');
}
}
//.........这里部分代码省略.........
示例9: _civicrm_api3_contact_check_params
/**
* Check parameters passed in.
*
* This function is on it's way out.
*
* @param array $params
* @param bool $dupeCheck
*
* @return null
* @throws API_Exception
* @throws CiviCRM_API3_Exception
*/
function _civicrm_api3_contact_check_params(&$params, $dupeCheck)
{
switch (strtolower(CRM_Utils_Array::value('contact_type', $params))) {
case 'household':
civicrm_api3_verify_mandatory($params, NULL, array('household_name'));
break;
case 'organization':
civicrm_api3_verify_mandatory($params, NULL, array('organization_name'));
break;
case 'individual':
civicrm_api3_verify_one_mandatory($params, NULL, array('first_name', 'last_name', 'email', 'display_name'));
break;
}
// Fixme: This really needs to be handled at a lower level. @See CRM-13123
if (isset($params['preferred_communication_method'])) {
$params['preferred_communication_method'] = CRM_Utils_Array::implodePadded($params['preferred_communication_method']);
}
if (!empty($params['contact_sub_type']) && !empty($params['contact_type'])) {
if (!CRM_Contact_BAO_ContactType::isExtendsContactType($params['contact_sub_type'], $params['contact_type'])) {
throw new API_Exception("Invalid or Mismatched Contact Subtype: " . implode(', ', (array) $params['contact_sub_type']));
}
}
if ($dupeCheck) {
// check for record already existing
$dedupeParams = CRM_Dedupe_Finder::formatParams($params, $params['contact_type']);
// CRM-6431
// setting 'check_permission' here means that the dedupe checking will be carried out even if the
// person does not have permission to carry out de-dupes
// this is similar to the front end form
if (isset($params['check_permission'])) {
$dedupeParams['check_permission'] = $params['check_permission'];
}
$ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, $params['contact_type'], 'Unsupervised', array());
if (count($ids) > 0) {
throw new API_Exception("Found matching contacts: " . implode(',', $ids), "duplicate", array("ids" => $ids));
}
}
// The BAO no longer supports the legacy param "current_employer" so here is a shim for api backward-compatability
if (!empty($params['current_employer'])) {
$organizationParams = array('organization_name' => $params['current_employer']);
$dedupParams = CRM_Dedupe_Finder::formatParams($organizationParams, 'Organization');
$dedupParams['check_permission'] = FALSE;
$dupeIds = CRM_Dedupe_Finder::dupesByParams($dedupParams, 'Organization', 'Supervised');
// check for mismatch employer name and id
if (!empty($params['employer_id']) && !in_array($params['employer_id'], $dupeIds)) {
throw new API_Exception('Employer name and Employer id Mismatch');
}
// show error if multiple organisation with same name exist
if (empty($params['employer_id']) && count($dupeIds) > 1) {
throw new API_Exception('Found more than one Organisation with same Name.');
}
if ($dupeIds) {
$params['employer_id'] = $dupeIds[0];
} else {
$result = civicrm_api3('Contact', 'create', array('organization_name' => $params['current_employer'], 'contact_type' => 'Organization'));
$params['employer_id'] = $result['id'];
}
}
return NULL;
}
示例10: civicrm_contact_check_params
/**
* Ensure that we have the right input parameters
*
* @todo We also need to make sure we run all the form rules on the params list
* to ensure that the params are valid
*
* @param array $params Associative array of property name/value
* pairs to insert in new contact.
* @param boolean $dupeCheck Should we check for duplicate contacts
* @param boolean $dupeErrorArray Should we return values of error
* object in array foramt
* @param boolean $requiredCheck Should we check if required params
* are present in params array
* @param int $dedupeRuleGroupID - the dedupe rule ID to use if present
*
* @return null on success, error message otherwise
* @access public
*/
function civicrm_contact_check_params(&$params, $dupeCheck = TRUE, $dupeErrorArray = FALSE, $requiredCheck = TRUE, $dedupeRuleGroupID = NULL)
{
if ($requiredCheck) {
$required = array('Individual' => array(array('first_name', 'last_name'), 'email'), 'Household' => array('household_name'), 'Organization' => array('organization_name'));
// cannot create a contact with empty params
if (empty($params)) {
return civicrm_create_error('Input Parameters empty');
}
if (!array_key_exists('contact_type', $params)) {
return civicrm_create_error('Contact Type not specified');
}
// contact_type has a limited number of valid values
$fields = CRM_Utils_Array::value($params['contact_type'], $required);
if ($fields == NULL) {
return civicrm_create_error("Invalid Contact Type: {$params['contact_type']}");
}
if ($csType = CRM_Utils_Array::value('contact_sub_type', $params)) {
if (!CRM_Contact_BAO_ContactType::isExtendsContactType($csType, $params['contact_type'])) {
return civicrm_create_error("Invalid or Mismatched Contact SubType: " . implode(', ', (array) $csType));
}
}
if (!CRM_Utils_Array::value('contact_id', $params)) {
$valid = FALSE;
$error = '';
foreach ($fields as $field) {
if (is_array($field)) {
$valid = TRUE;
foreach ($field as $element) {
if (!CRM_Utils_Array::value($element, $params)) {
$valid = FALSE;
$error .= $element;
break;
}
}
} else {
if (CRM_Utils_Array::value($field, $params)) {
$valid = TRUE;
}
}
if ($valid) {
break;
}
}
if (!$valid) {
return civicrm_create_error("Required fields not found for {$params['contact_type']} : {$error}");
}
}
}
if ($dupeCheck) {
// check for record already existing
require_once 'CRM/Dedupe/Finder.php';
$dedupeParams = CRM_Dedupe_Finder::formatParams($params, $params['contact_type']);
// CRM-6431
// setting 'check_permission' here means that the dedupe checking will be carried out even if the
// person does not have permission to carry out de-dupes
// this is similar to the front end form
if (isset($params['check_permission'])) {
$dedupeParams['check_permission'] = $fields['check_permission'];
}
$ids = implode(',', CRM_Dedupe_Finder::dupesByParams($dedupeParams, $params['contact_type'], 'Strict', array(), $dedupeRuleGroupID));
if ($ids != NULL) {
if ($dupeErrorArray) {
$error = CRM_Core_Error::createError("Found matching contacts: {$ids}", CRM_Core_Error::DUPLICATE_CONTACT, 'Fatal', $ids);
return civicrm_create_error($error->pop());
}
return civicrm_create_error("Found matching contacts: {$ids}", array($ids));
}
}
//check for organisations with same name
if (CRM_Utils_Array::value('current_employer', $params)) {
$organizationParams = array();
$organizationParams['organization_name'] = $params['current_employer'];
require_once 'CRM/Dedupe/Finder.php';
$dedupParams = CRM_Dedupe_Finder::formatParams($organizationParams, 'Organization');
$dedupParams['check_permission'] = FALSE;
$dupeIds = CRM_Dedupe_Finder::dupesByParams($dedupParams, 'Organization', 'Fuzzy');
// check for mismatch employer name and id
if (CRM_Utils_Array::value('employer_id', $params) && !in_array($params['employer_id'], $dupeIds)) {
return civicrm_create_error('Employer name and Employer id Mismatch');
}
// show error if multiple organisation with same name exist
if (!CRM_Utils_Array::value('employer_id', $params) && count($dupeIds) > 1) {
//.........这里部分代码省略.........
示例11: import
/**
* Handle the values in import mode.
*
* @param int $onDuplicate
* The code for what action to take on duplicates.
* @param array $values
* The array of values belonging to this line.
*
* @param bool $doGeocodeAddress
*
* @return bool
* the result of this processing
*/
public function import($onDuplicate, &$values, $doGeocodeAddress = FALSE)
{
$config = CRM_Core_Config::singleton();
$this->_unparsedStreetAddressContacts = array();
if (!$doGeocodeAddress) {
// CRM-5854, reset the geocode method to null to prevent geocoding
$config->geocodeMethod = NULL;
}
// first make sure this is a valid line
//$this->_updateWithId = false;
$response = $this->summary($values);
$statusFieldName = $this->_statusFieldName;
if ($response != CRM_Import_Parser::VALID) {
$importRecordParams = array($statusFieldName => 'INVALID', "{$statusFieldName}Msg" => "Invalid (Error Code: {$response})");
$this->updateImportRecord($values[count($values) - 1], $importRecordParams);
return $response;
}
$params =& $this->getActiveFieldParams();
$formatted = array('contact_type' => $this->_contactType);
static $contactFields = NULL;
if ($contactFields == NULL) {
$contactFields = CRM_Contact_DAO_Contact::import();
}
//check if external identifier exists in database
if (!empty($params['external_identifier']) && (!empty($params['id']) || in_array($onDuplicate, array(CRM_Import_Parser::DUPLICATE_SKIP, CRM_Import_Parser::DUPLICATE_NOCHECK)))) {
if ($internalCid = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $params['external_identifier'], 'id', 'external_identifier')) {
if ($internalCid != CRM_Utils_Array::value('id', $params)) {
$errorMessage = ts('External ID already exists in Database.');
array_unshift($values, $errorMessage);
$importRecordParams = array($statusFieldName => 'ERROR', "{$statusFieldName}Msg" => $errorMessage);
$this->updateImportRecord($values[count($values) - 1], $importRecordParams);
return CRM_Import_Parser::DUPLICATE;
}
}
}
if (!empty($this->_contactSubType)) {
$params['contact_sub_type'] = $this->_contactSubType;
}
if ($subType = CRM_Utils_Array::value('contact_sub_type', $params)) {
if (CRM_Contact_BAO_ContactType::isExtendsContactType($subType, $this->_contactType, FALSE, 'label')) {
$subTypes = CRM_Contact_BAO_ContactType::subTypePairs($this->_contactType, FALSE, NULL);
$params['contact_sub_type'] = array_search($subType, $subTypes);
} elseif (!CRM_Contact_BAO_ContactType::isExtendsContactType($subType, $this->_contactType)) {
$message = "Mismatched or Invalid Contact Subtype.";
array_unshift($values, $message);
return CRM_Import_Parser::NO_MATCH;
}
}
// Get contact id to format common data in update/fill mode,
// prioritising a dedupe rule check over an external_identifier check, but falling back on ext id.
if ($this->_updateWithId && empty($params['id'])) {
$possibleMatches = $this->getPossibleContactMatches($params);
foreach ($possibleMatches as $possibleID) {
$params['id'] = $formatted['id'] = $possibleID;
}
}
//format common data, CRM-4062
$this->formatCommonData($params, $formatted, $contactFields);
$relationship = FALSE;
$createNewContact = TRUE;
// Support Match and Update Via Contact ID
if ($this->_updateWithId && isset($params['id'])) {
$createNewContact = FALSE;
// @todo - it feels like all the rows from here to the end of the IF
// could be removed in favour of a simple check for whether the contact_type & id match
// the call to the deprecated function seems to add no value other that to do an additional
// check for the contact_id & type.
$error = _civicrm_api3_deprecated_duplicate_formatted_contact($formatted);
if (CRM_Core_Error::isAPIError($error, CRM_Core_ERROR::DUPLICATE_CONTACT)) {
$matchedIDs = explode(',', $error['error_message']['params'][0]);
if (count($matchedIDs) >= 1) {
$updateflag = TRUE;
foreach ($matchedIDs as $contactId) {
if ($params['id'] == $contactId) {
$contactType = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $params['id'], 'contact_type');
if ($formatted['contact_type'] == $contactType) {
//validation of subtype for update mode
//CRM-5125
$contactSubType = NULL;
if (!empty($params['contact_sub_type'])) {
$contactSubType = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $params['id'], 'contact_sub_type');
}
if (!empty($contactSubType) && (!CRM_Contact_BAO_ContactType::isAllowEdit($params['id'], $contactSubType) && $contactSubType != CRM_Utils_Array::value('contact_sub_type', $formatted))) {
$message = "Mismatched contact SubTypes :";
array_unshift($values, $message);
$updateflag = FALSE;
$this->_retCode = CRM_Import_Parser::NO_MATCH;
//.........这里部分代码省略.........
示例12: add
/**
* takes an associative array and creates a contact object
*
* the function extract all the params it needs to initialize the create a
* contact object. the params array could contain additional unused name/value
* pairs
*
* @param array $params (reference ) an assoc array of name/value pairs
*
* @return object CRM_Contact_BAO_Contact object
* @access public
* @static
*/
static function add(&$params)
{
$contact =& new CRM_Contact_DAO_Contact();
if (empty($params)) {
return;
}
//fix for validate contact sub type CRM-5143
$subType = CRM_Utils_Array::value('contact_sub_type', $params);
if ($subType && !CRM_Contact_BAO_ContactType::isExtendsContactType($subType, $params['contact_type'], true)) {
return;
}
//fixed contact source
if (isset($params['contact_source'])) {
$params['source'] = $params['contact_source'];
}
//fix for preferred communication method
$prefComm = CRM_Utils_Array::value('preferred_communication_method', $params);
if ($prefComm && is_array($prefComm)) {
unset($params['preferred_communication_method']);
$newPref = array();
foreach ($prefComm as $k => $v) {
if ($v) {
$newPref[$k] = $v;
}
}
$prefComm = $newPref;
if (is_array($prefComm) && !empty($prefComm)) {
$prefComm = CRM_Core_BAO_CustomOption::VALUE_SEPERATOR . implode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, array_keys($prefComm)) . CRM_Core_BAO_CustomOption::VALUE_SEPERATOR;
$contact->preferred_communication_method = $prefComm;
} else {
$contact->preferred_communication_method = '';
}
}
$allNull = $contact->copyValues($params);
$contact->id = CRM_Utils_Array::value('contact_id', $params);
if ($contact->contact_type == 'Individual') {
$allNull = false;
//format individual fields
require_once "CRM/Contact/BAO/Individual.php";
CRM_Contact_BAO_Individual::format($params, $contact);
} else {
if ($contact->contact_type == 'Household') {
if (isset($params['household_name'])) {
$allNull = false;
$contact->display_name = $contact->sort_name = CRM_Utils_Array::value('household_name', $params, '');
}
} else {
if ($contact->contact_type == 'Organization') {
if (isset($params['organization_name'])) {
$allNull = false;
$contact->display_name = $contact->sort_name = CRM_Utils_Array::value('organization_name', $params, '');
}
}
}
}
// privacy block
$privacy = CRM_Utils_Array::value('privacy', $params);
if ($privacy && is_array($privacy) && !empty($privacy)) {
$allNull = false;
foreach (self::$_commPrefs as $name) {
$contact->{$name} = CRM_Utils_Array::value($name, $privacy, false);
}
}
// since hash was required, make sure we have a 0 value for it, CRM-1063
// fixed in 1.5 by making hash optional
// only do this in create mode, not update
if ((!array_key_exists('hash', $contact) || !$contact->hash) && !$contact->id) {
$allNull = false;
$contact->hash = md5(uniqid(rand(), true));
}
if (!$allNull) {
$contact->save();
require_once 'CRM/Core/BAO/Log.php';
CRM_Core_BAO_Log::register($contact->id, 'civicrm_contact', $contact->id);
}
if ($contact->contact_type == 'Individual' && array_key_exists('current_employer', $params)) {
// create current employer
if ($params['current_employer']) {
require_once 'CRM/Contact/BAO/Contact/Utils.php';
CRM_Contact_BAO_Contact_Utils::createCurrentEmployerRelationship($contact->id, $params['current_employer']);
} else {
//unset if employer id exits
if ($employerId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contact->id, 'employer_id')) {
require_once 'CRM/Contact/BAO/Contact/Utils.php';
CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($contact->id, $employerId);
}
}
//.........这里部分代码省略.........
示例13: civicrm_contact_check_params
/**
* Ensure that we have the right input parameters
*
* @todo We also need to make sure we run all the form rules on the params list
* to ensure that the params are valid
*
* @param array $params Associative array of property name/value
* pairs to insert in new contact.
* @param boolean $dupeCheck Should we check for duplicate contacts
* @param boolean $dupeErrorArray Should we return values of error
* object in array foramt
* @param boolean $requiredCHeck Should we check if required params
* are present in params array
*
* @return null on success, error message otherwise
* @access public
*/
function civicrm_contact_check_params(&$params, $dupeCheck = true, $dupeErrorArray = false, $requiredCheck = true)
{
if ($requiredCheck) {
$required = array('Individual' => array(array('first_name', 'last_name'), 'email'), 'Household' => array('household_name'), 'Organization' => array('organization_name'));
// cannot create a contact with empty params
if (empty($params)) {
return civicrm_create_error('Input Parameters empty');
}
if (!array_key_exists('contact_type', $params)) {
return civicrm_create_error('Contact Type not specified');
}
// contact_type has a limited number of valid values
$fields = CRM_Utils_Array::value($params['contact_type'], $required);
if ($fields == null) {
return civicrm_create_error("Invalid Contact Type: {$params['contact_type']}");
}
if ($csType = CRM_Utils_Array::value('contact_sub_type', $params)) {
if (!CRM_Contact_BAO_ContactType::isExtendsContactType($csType, $params['contact_type'])) {
return civicrm_create_error("Invalid or Mismatched Contact SubType: {$csType}");
}
}
if (!CRM_Utils_Array::value('contact_id', $params)) {
$valid = false;
$error = '';
foreach ($fields as $field) {
if (is_array($field)) {
$valid = true;
foreach ($field as $element) {
if (!CRM_Utils_Array::value($element, $params)) {
$valid = false;
$error .= $element;
break;
}
}
} else {
if (CRM_Utils_Array::value($field, $params)) {
$valid = true;
}
}
if ($valid) {
break;
}
}
if (!$valid) {
return civicrm_create_error("Required fields not found for {$params['contact_type']} : {$error}");
}
}
}
if ($dupeCheck) {
// check for record already existing
require_once 'CRM/Dedupe/Finder.php';
$dedupeParams = CRM_Dedupe_Finder::formatParams($params, $params['contact_type']);
$ids = implode(',', CRM_Dedupe_Finder::dupesByParams($dedupeParams, $params['contact_type']));
if ($ids != null) {
if ($dupeErrorArray) {
$error = CRM_Core_Error::createError("Found matching contacts: {$ids}", CRM_Core_Error::DUPLICATE_CONTACT, 'Fatal', $ids);
return civicrm_create_error($error->pop());
}
return civicrm_create_error("Found matching contacts: {$ids}", $ids);
}
}
return null;
}
示例14: _civicrm_api3_contact_check_params
function _civicrm_api3_contact_check_params(&$params, $dupeCheck = true, $dupeErrorArray = false, $obsoletevalue = true, $dedupeRuleGroupID = null)
{
switch (strtolower(CRM_Utils_Array::value('contact_type', $params))) {
case 'household':
civicrm_api3_verify_mandatory($params, null, array('household_name'));
break;
case 'organization':
civicrm_api3_verify_mandatory($params, null, array('organization_name'));
break;
case 'individual':
civicrm_api3_verify_one_mandatory($params, null, array('first_name', 'last_name', 'email', 'display_name'));
break;
}
if (CRM_Utils_Array::value('contact_sub_type', $params) && CRM_Utils_Array::value('contact_type', $params)) {
if (!CRM_Contact_BAO_ContactType::isExtendsContactType($params['contact_sub_type'], $params['contact_type'])) {
return civicrm_api3_create_error("Invalid or Mismatched Contact SubType: " . implode(', ', (array) $params['contact_sub_type']));
}
}
if ($dupeCheck) {
// check for record already existing
require_once 'CRM/Dedupe/Finder.php';
$dedupeParams = CRM_Dedupe_Finder::formatParams($params, $params['contact_type']);
// CRM-6431
// setting 'check_permission' here means that the dedupe checking will be carried out even if the
// person does not have permission to carry out de-dupes
// this is similar to the front end form
if (isset($params['check_permission'])) {
$dedupeParams['check_permission'] = $params['check_permission'];
}
$ids = implode(',', CRM_Dedupe_Finder::dupesByParams($dedupeParams, $params['contact_type'], 'Strict', array()));
if ($ids != NULL) {
throw new Exception("Found matching contacts: {$ids}");
}
}
//check for organisations with same name
if (CRM_Utils_Array::value('current_employer', $params)) {
$organizationParams = array();
$organizationParams['organization_name'] = $params['current_employer'];
require_once 'CRM/Dedupe/Finder.php';
$dedupParams = CRM_Dedupe_Finder::formatParams($organizationParams, 'Organization');
$dedupParams['check_permission'] = FALSE;
$dupeIds = CRM_Dedupe_Finder::dupesByParams($dedupParams, 'Organization', 'Fuzzy');
// check for mismatch employer name and id
if (CRM_Utils_Array::value('employer_id', $params) && !in_array($params['employer_id'], $dupeIds)) {
return civicrm_api3_create_error('Employer name and Employer id Mismatch');
}
// show error if multiple organisation with same name exist
if (!CRM_Utils_Array::value('employer_id', $params) && count($dupeIds) > 1) {
return civicrm_api3_create_error('Found more than one Organisation with same Name.');
}
}
return NULL;
}