本文整理汇总了PHP中CRM_Contact_BAO_Relationship::create方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contact_BAO_Relationship::create方法的具体用法?PHP CRM_Contact_BAO_Relationship::create怎么用?PHP CRM_Contact_BAO_Relationship::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Contact_BAO_Relationship
的用法示例。
在下文中一共展示了CRM_Contact_BAO_Relationship::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: civicrm_api3_relationship_create
/**
* Add or update a relationship
*
* @param array $params input parameters
*
* @throws API_Exception
* @example RelationshipCreate.php Std Create example
*
* @return array API Result Array
* {@getfields relationship_create}
* @static void
* @access public
*/
function civicrm_api3_relationship_create($params)
{
$values = array();
_civicrm_api3_relationship_format_params($params, $values);
$ids = array();
$action = CRM_Core_Action::ADD;
if (!empty($params['id'])) {
$ids['contactTarget'] = $values['contact_id_b'];
$action = CRM_Core_Action::UPDATE;
}
$values['relationship_type_id'] = $values['relationship_type_id'] . '_a_b';
if (!empty($params['contact_id_b'])) {
$values['contact_check'] = array($params['contact_id_b'] => $params['contact_id_b']);
}
if (!empty($values['contact_id_a'])) {
$ids['contact'] = $values['contact_id_a'];
}
$relationshipBAO = CRM_Contact_BAO_Relationship::create($values, $ids);
if ($relationshipBAO[1]) {
throw new API_Exception('Relationship is not valid');
} elseif ($relationshipBAO[2]) {
throw new API_Exception('Relationship already exists');
}
// Handle related memberships CRM-13652
if (!empty($params['contact_id_a'])) {
CRM_Contact_BAO_Relationship::relatedMemberships($params['contact_id_a'], $values, $ids, $action);
}
$id = $relationshipBAO[4][0];
$values = array();
_civicrm_api3_object_to_array($relationshipBAO[5][$id], $values[$id]);
return civicrm_api3_create_success($values, $params, 'relationship', 'create');
}
示例2: civicrm_api3_relationship_create
/**
* Add or update a relationship
*
* @param array $params input parameters
*
* @example RelationshipCreate.php Std Create example
*
* @return array API Result Array
* {@getfields relationship_create}
* @static void
* @access public
*
*/
function civicrm_api3_relationship_create($params)
{
// check entities exist
$orig_values = _civicrm_api3_relationship_check_params($params);
$values = array();
_civicrm_api3_relationship_format_params($params, $values);
$ids = array();
require_once 'CRM/Core/Action.php';
$action = CRM_Core_Action::ADD;
require_once 'CRM/Utils/Array.php';
if (CRM_Utils_Array::value('id', $params)) {
$params = array_merge($params, $orig_values);
$ids['relationship'] = $params['id'];
$ids['contactTarget'] = $params['contact_id_b'];
$action = CRM_Core_Action::UPDATE;
}
$values['relationship_type_id'] = $params['relationship_type_id'] . '_a_b';
$values['contact_check'] = array($params['contact_id_b'] => $params['contact_id_b']);
$ids['contact'] = $params['contact_id_a'];
$relationshipBAO = CRM_Contact_BAO_Relationship::create($values, $ids);
if ($relationshipBAO[1]) {
return civicrm_api3_create_error('Relationship is not valid');
} elseif ($relationshipBAO[2]) {
return civicrm_api3_create_error('Relationship already exists');
}
CRM_Contact_BAO_Relationship::relatedMemberships($params['contact_id_a'], $values, $ids, $action);
$relationID = $relationshipBAO[4][0];
return civicrm_api3_create_success(array($relationID => array('id' => $relationID, 'moreIDs' => implode(',', $relationshipBAO[4]))));
}
示例3: civicrm_relationship_create
/**
* Add or update a relationship
*
* @param array $params (reference ) input parameters
*
* @return array (reference) id of created or updated record
* @static void
* @access public
*/
function civicrm_relationship_create(&$params)
{
_civicrm_initialize();
if (empty($params)) {
return civicrm_create_error('No input parameter present');
}
if (!is_array($params)) {
return civicrm_create_error(ts('Input parameter is not an array'));
}
if (!isset($params['contact_id_a']) && !isset($params['contact_id_b']) && !isset($params['relationship_type_id'])) {
return civicrm_create_error(ts('Missing required parameters'));
}
$values = array();
require_once 'CRM/Contact/BAO/Relationship.php';
$error = _civicrm_relationship_format_params($params, $values);
if (civicrm_error($error)) {
return $error;
}
$ids = array();
require_once 'CRM/Utils/Array.php';
if (CRM_Utils_Array::value('id', $params)) {
$ids['relationship'] = $params['id'];
$ids['contactTarget'] = $params['contact_id_b'];
}
$values['relationship_type_id'] = $params['relationship_type_id'] . '_a_b';
$values['contact_check'] = array($params['contact_id_b'] => $params['contact_id_b']);
$ids['contact'] = $params['contact_id_a'];
$relationshipBAO = CRM_Contact_BAO_Relationship::create($values, $ids);
if (is_a($relationshipBAO, 'CRM_Core_Error')) {
return civicrm_create_error("Relationship can not be created");
} else {
if ($relationshipBAO[1]) {
return civicrm_create_error("Relationship is not valid");
} else {
if ($relationshipBAO[2]) {
return civicrm_create_error("Relationship already exist");
}
}
}
return civicrm_create_success(array('id' => implode(",", $relationshipBAO[4])));
}
示例4: civicrm_relationship_create
/**
* Add or update a relationship
*
* @param array $params (reference ) input parameters
*
* @return array (reference) id of created or updated record
* @static void
* @access public
*/
function civicrm_relationship_create(&$params)
{
_civicrm_initialize();
// check params for required fields (add/update)
$error = _civicrm_relationship_check_params($params);
if (civicrm_error($error)) {
return $error;
}
$values = array();
require_once 'CRM/Contact/BAO/Relationship.php';
$error = _civicrm_relationship_format_params($params, $values);
if (civicrm_error($error)) {
return $error;
}
$ids = array();
require_once 'CRM/Utils/Array.php';
if (CRM_Utils_Array::value('id', $params)) {
$ids['relationship'] = $params['id'];
$ids['contactTarget'] = $params['contact_id_b'];
}
$values['relationship_type_id'] = $params['relationship_type_id'] . '_a_b';
$values['contact_check'] = array($params['contact_id_b'] => $params['contact_id_b']);
$ids['contact'] = $params['contact_id_a'];
$relationshipBAO = CRM_Contact_BAO_Relationship::create($values, $ids);
if (is_a($relationshipBAO, 'CRM_Core_Error')) {
return civicrm_create_error('Relationship can not be created');
} else {
if ($relationshipBAO[1]) {
return civicrm_create_error('Relationship is not valid');
} else {
if ($relationshipBAO[2]) {
return civicrm_create_error('Relationship already exists');
}
}
}
return civicrm_create_success(array('id' => implode(',', $relationshipBAO[4])));
}
示例5: relationship
static function relationship(&$config)
{
// CRM_Core_Error::debug_var( 'GET' , $_GET , true, true );
// CRM_Core_Error::debug_var( 'POST', $_POST, true, true );
$relType = CRM_Utils_Array::value('rel_type', $_POST);
$relContactID = CRM_Utils_Array::value('rel_contact', $_POST);
$sourceContactID = CRM_Utils_Array::value('contact_id', $_POST);
$relationshipID = CRM_Utils_Array::value('rel_id', $_POST);
$caseID = CRM_Utils_Array::value('case_id', $_POST);
$relationParams = array('relationship_type_id' => $relType . '_a_b', 'contact_check' => array($relContactID => 1), 'is_active' => 1, 'case_id' => $caseID, 'start_date' => date("Ymd"));
if ($relationshipID == 'null') {
$relationIds = array('contact' => $sourceContactID);
} else {
$relationIds = array('contact' => $sourceContactID, 'relationship' => $relationshipID, 'contactTarget' => $relContactID);
}
require_once "CRM/Contact/BAO/Relationship.php";
$return = CRM_Contact_BAO_Relationship::create($relationParams, $relationIds);
$relationshipID = $return[4][0];
// we should return phone and email
require_once "CRM/Case/BAO/Case.php";
$caseRelationship = CRM_Case_BAO_Case::getCaseRoles($sourceContactID, $caseID, $relationshipID);
//create an activity for case role assignment.CRM-4480
CRM_Case_BAO_Case::createCaseRoleActivity($caseID, $relationshipID, $relContactID);
$relation = $caseRelationship[$relationshipID];
$relation['rel_id'] = $relationshipID;
echo json_encode($relation);
exit;
}
示例6: createCurrentEmployerRelationship
/**
* Create Current employer relationship for a individual
*
* @param int $contactID contact id of the individual
* @param $organizationId
* @param null $previousEmployerID
*
* @internal param string $organization it can be name or id of organization
*
* @access public
* @static
*/
static function createCurrentEmployerRelationship($contactID, $organizationId, $previousEmployerID = NULL, $newContact = FALSE)
{
if ($organizationId && is_numeric($organizationId)) {
$cid = array('contact' => $contactID);
// get the relationship type id of "Employee of"
$relTypeId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', 'Employee of', 'id', 'name_a_b');
if (!$relTypeId) {
CRM_Core_Error::fatal(ts("You seem to have deleted the relationship type 'Employee of'"));
}
// create employee of relationship
$relationshipParams = array('is_active' => TRUE, 'relationship_type_id' => $relTypeId . '_a_b', 'contact_check' => array($organizationId => TRUE));
list($valid, $invalid, $duplicate, $saved, $relationshipIds) = CRM_Contact_BAO_Relationship::create($relationshipParams, $cid);
// In case we change employer, clean previous employer related records.
if (!$previousEmployerID && !$newContact) {
$previousEmployerID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'employer_id');
}
if ($previousEmployerID && $previousEmployerID != $organizationId) {
self::clearCurrentEmployer($contactID, $previousEmployerID);
}
// set current employer
self::setCurrentEmployer(array($contactID => $organizationId));
$relationshipParams['relationship_ids'] = $relationshipIds;
// handle related meberships. CRM-3792
self::currentEmployerRelatedMembership($contactID, $organizationId, $relationshipParams, $duplicate, $previousEmployerID);
}
}
示例7: relationship
static function relationship()
{
$relType = CRM_Utils_Array::value('rel_type', $_POST);
$relContactID = CRM_Utils_Array::value('rel_contact', $_POST);
$sourceContactID = CRM_Utils_Array::value('contact_id', $_POST);
$relationshipID = CRM_Utils_Array::value('rel_id', $_POST);
$caseID = CRM_Utils_Array::value('case_id', $_POST);
$relationParams = array('relationship_type_id' => $relType . '_a_b', 'contact_check' => array($relContactID => 1), 'is_active' => 1, 'case_id' => $caseID, 'start_date' => date("Ymd"));
$relationIds = array('contact' => $sourceContactID);
if ($relationshipID && $relationshipID != 'null') {
$relationIds['relationship'] = $relationshipID;
$relationIds['contactTarget'] = $relContactID;
}
$return = CRM_Contact_BAO_Relationship::create($relationParams, $relationIds);
$status = 'process-relationship-fail';
if (CRM_Utils_Array::value(0, $return[4])) {
$relationshipID = $return[4][0];
$status = 'process-relationship-success';
}
$caseRelationship = array();
if ($relationshipID && $relationshipID != 'null') {
// we should return phone and email
$caseRelationship = CRM_Case_BAO_Case::getCaseRoles($sourceContactID, $caseID, $relationshipID);
//create an activity for case role assignment.CRM-4480
CRM_Case_BAO_Case::createCaseRoleActivity($caseID, $relationshipID, $relContactID);
}
$relation = CRM_Utils_Array::value($relationshipID, $caseRelationship, array());
$relation['rel_id'] = $relationshipID;
$relation['status'] = $status;
echo json_encode($relation);
CRM_Utils_System::civiExit();
}
示例8: createCurrentEmployerRelationship
/**
* Create Current employer relationship for a individual
*
* @param int $contactID contact id of the individual
* @param string $organization it can be name or id of organization
*
* @access public
* @static
*/
static function createCurrentEmployerRelationship($contactID, $organization)
{
require_once 'CRM/Contact/BAO/Relationship.php';
$organizationId = null;
// if organization id is passed.
if (is_numeric($organization)) {
$organizationId = $organization;
} else {
$orgName = explode('::', $organization);
trim($orgName[0]);
$organizationParams = array();
$organizationParams['organization_name'] = $orgName[0];
require_once 'CRM/Dedupe/Finder.php';
$dedupeParams = CRM_Dedupe_Finder::formatParams($organizationParams, 'Organization');
$dedupeParams['check_permission'] = false;
$dupeIDs = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Organization', 'Fuzzy');
if (is_array($dupeIDs) && !empty($dupeIDs)) {
// we should create relationship only w/ first org CRM-4193
foreach ($dupeIDs as $orgId) {
$organizationId = $orgId;
break;
}
} else {
//create new organization
$newOrg = array('contact_type' => 'Organization', 'organization_name' => trim($orgName[0]));
$org = CRM_Contact_BAO_Contact::add($newOrg);
$organizationId = $org->id;
}
}
if ($organizationId) {
$cid = array('contact' => $contactID);
// get the relationship type id of "Employee of"
$relTypeId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', 'Employee of', 'id', 'name_a_b');
if (!$relTypeId) {
CRM_Core_Error::fatal(ts("You seem to have deleted the relationship type 'Employee of'"));
}
// create employee of relationship
$relationshipParams = array('is_active' => true, 'relationship_type_id' => $relTypeId . '_a_b', 'contact_check' => array($organizationId => true));
list($valid, $invalid, $duplicate, $saved, $relationshipIds) = CRM_Contact_BAO_Relationship::create($relationshipParams, $cid);
// In case we change employer, clean prveovious employer related records.
$previousEmployerID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'employer_id');
if ($previousEmployerID && $previousEmployerID != $organizationId) {
self::clearCurrentEmployer($contactID, $previousEmployerID);
}
// set current employer
self::setCurrentEmployer(array($contactID => $organizationId));
// handle related meberships. CRM-3792
self::currentEmployerRelatedMembership($contactID, $organizationId, $relationshipParams, $duplicate);
}
}
示例9: postProcess
/**
* This function is called when the form is submitted
*
* @access public
* @return None
*/
function postProcess()
{
// store the submitted values in an array
$params = $this->controller->exportValues($this->_name);
$this->set('searchDone', 0);
if (CRM_Utils_Array::value('_qf_Relationship_refresh', $_POST)) {
$this->search($params);
$this->set('searchDone', 1);
return;
}
// action is taken depending upon the mode
$ids = array();
$ids['contact'] = $this->_contactId;
if ($this->_action & CRM_CORE_ACTION_DELETE) {
CRM_Contact_BAO_Relationship::del($this->_relationshipId);
return;
}
if ($this->_action & CRM_CORE_ACTION_UPDATE) {
$ids['relationship'] = $this->_relationshipId;
$relation = CRM_Contact_BAO_Relationship::getContactIds($this->_relationshipId);
$ids['contactTarget'] = $relation->contact_id_a == $this->_contactId ? $relation->contact_id_b : $relation->contact_id_a;
}
list($valid, $invalid, $duplicate, $saved) = CRM_Contact_BAO_Relationship::create($params, $ids);
$status = '';
if ($valid) {
$status .= ' ' . ts('%count new relationship record created.', array('count' => $valid, 'plural' => '%count new relationship records created.'));
}
if ($invalid) {
$status .= ' ' . ts('%count relationship record not created due to invalid target contact type.', array('count' => $invalid, 'plural' => '%count relationship records not created due to invalid target contact type.'));
}
if ($duplicate) {
$status .= ' ' . ts('%count relationship record not created - duplicate of existing relationship.', array('count' => $duplicate, 'plural' => '%count relationship records not created - duplicate of existing relationship.'));
}
if ($saved) {
$status .= ts('Relationship record has been updated.');
}
CRM_Core_Session::setStatus($status);
}
示例10: postProcess
/**
* This function is called when the form is submitted
*
* @access public
*
* @return None
*/
public function postProcess()
{
$quickSave = FALSE;
if (CRM_Utils_Array::value('_qf_Relationship_refresh_save', $_POST) || CRM_Utils_Array::value('_qf_Relationship_refresh_savedetails', $_POST)) {
//CRM-15873
//Parse custom file uploads
$pageName = $this->getAttribute('name');
$data =& $this->controller->container();
foreach ($this->controller->get('uploadNames') as $name) {
$this->controller->_actions['upload']->upload($this, $data, $pageName, $name);
}
$quickSave = TRUE;
}
// store the submitted values in an array
$params = $this->controller->exportValues($this->_name);
$this->set('searchDone', 0);
$this->set('callAjax', FALSE);
if (CRM_Utils_Array::value('_qf_Relationship_refresh', $_POST) || $quickSave) {
if (is_numeric($params['contact_select_id'][1])) {
if ($quickSave) {
$params['contact_check'] = array($params['contact_select_id'][1] => 1);
}
} else {
$this->set('callAjax', TRUE);
$this->set('relType', $params['relationship_type_id']);
$this->set('relContact', $params['contact'][1]);
$quickSave = FALSE;
}
$this->set('searchDone', 1);
if (!$quickSave) {
return;
}
}
// action is taken depending upon the mode
$ids = array();
$ids['contact'] = $this->_contactId;
// modify params for ajax call
$this->modifyParams($params);
if ($this->_action & CRM_Core_Action::DELETE) {
CRM_Contact_BAO_Relationship::del($this->_relationshipId);
return;
}
$relationshipTypeId = str_replace(array('_a_b', '_b_a'), array('', ''), $params['relationship_type_id']);
if ($this->_action & CRM_Core_Action::UPDATE) {
$ids['relationship'] = $this->_relationshipId;
$relation = CRM_Contact_BAO_Relationship::getContactIds($this->_relationshipId);
$ids['contactTarget'] = $relation->contact_id_a == $this->_contactId ? $relation->contact_id_b : $relation->contact_id_a;
//if relationship type change and previously it was
//employer / emplyee relationship with current employer
//than clear the current employer. CRM-3235.
//make sure we has to have employer id before firing queries, CRM-7306
$employerId = CRM_Utils_Array::value('current_employee_id', $this->_values);
$isDisabled = TRUE;
if (CRM_Utils_Array::value('is_active', $params)) {
$isDisabled = FALSE;
}
$relChanged = TRUE;
if ($relationshipTypeId == $this->_values['relationship_type_id']) {
$relChanged = FALSE;
}
if ($employerId && ($isDisabled || $relChanged)) {
CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($this->_values['current_employee_id']);
}
//if field key doesn't exists in params that means the user has unchecked checkbox,
//hence fill FALSE to params
$params['is_active'] = $isDisabled ? FALSE : TRUE;
$params['is_permission_a_b'] = CRM_Utils_Array::value('is_permission_a_b', $params, FALSE);
$params['is_permission_b_a'] = CRM_Utils_Array::value('is_permission_b_a', $params, FALSE);
} elseif ($quickSave) {
if (CRM_Utils_Array::value('add_current_employee', $params) && $this->_allRelationshipNames[$relationshipTypeId]['name_a_b'] == 'Employee of') {
$params['employee_of'] = $params['contact_select_id'][1];
} elseif (CRM_Utils_Array::value('add_current_employer', $params) && $this->_allRelationshipNames[$relationshipTypeId]['name_b_a'] == 'Employer of') {
$params['employer_of'] = array($params['contact_select_id'][1] => 1);
}
if (!$this->_rtype) {
$this->_rtype = str_replace($relationshipTypeId . '_', '', $params['relationship_type_id']);
}
}
if (!$params['note']) {
$params['note'] = 'null';
}
$params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], NULL, TRUE);
$params['end_date'] = CRM_Utils_Date::processDate($params['end_date'], NULL, TRUE);
//special case to handle if all checkboxes are unchecked
$customFields = CRM_Core_BAO_CustomField::getFields('Relationship', FALSE, FALSE, $relationshipTypeId);
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_relationshipId, 'Relationship');
list($valid, $invalid, $duplicate, $saved, $relationshipIds) = CRM_Contact_BAO_Relationship::create($params, $ids);
// if this is called from case view,
//create an activity for case role removal.CRM-4480
if ($this->_caseId) {
CRM_Case_BAO_Case::createCaseRoleActivity($this->_caseId, $relationshipIds, $params['contact_check'], $this->_contactId);
}
$status = '';
//.........这里部分代码省略.........
示例11: processSharedAddressRelationship
/**
* Function to create relationship between contacts who share an address
*
* Note that currently we create relationship only for Individual contacts
* Individual + Household and Individual + Orgnization
*
* @param int $masterAddressId master address id
* @param array $params associated array of submitted values
*
* @return void
* @access public
* @static
*/
static function processSharedAddressRelationship($masterAddressId, $params)
{
if (!$masterAddressId) {
return;
}
// get the contact type of contact being edited / created
$currentContactType = CRM_Contact_BAO_Contact::getContactType($params['contact_id']);
$currentContactId = $params['contact_id'];
// if current contact is not of type individual return
if ($currentContactType != 'Individual') {
return;
}
// get the contact id and contact type of shared contact
// check the contact type of shared contact, return if it is of type Individual
$query = 'SELECT cc.id, cc.contact_type
FROM civicrm_contact cc INNER JOIN civicrm_address ca ON cc.id = ca.contact_id
WHERE ca.id = %1';
$dao = CRM_Core_DAO::executeQuery($query, array(1 => array($masterAddressId, 'Integer')));
$dao->fetch();
// if current contact is not of type individual return, since we don't create relationship between
// 2 individuals
if ($dao->contact_type == 'Individual') {
return;
}
$sharedContactType = $dao->contact_type;
$sharedContactId = $dao->id;
// create relationship between ontacts who share an address
if ($sharedContactType == 'Organization') {
return CRM_Contact_BAO_Contact_Utils::createCurrentEmployerRelationship($currentContactId, $sharedContactId);
} else {
// get the relationship type id of "Household Member of"
$relationshipType = 'Household Member of';
}
$cid = array('contact' => $currentContactId);
$relTypeId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $relationshipType, 'id', 'name_a_b');
if (!$relTypeId) {
CRM_Core_Error::fatal(ts("You seem to have deleted the relationship type '%1'", array(1 => $relationshipType)));
}
// create relationship
$relationshipParams = array('is_active' => TRUE, 'relationship_type_id' => $relTypeId . '_a_b', 'contact_check' => array($sharedContactId => TRUE));
list($valid, $invalid, $duplicate, $saved, $relationshipIds) = CRM_Contact_BAO_Relationship::create($relationshipParams, $cid);
}
示例12: import
//.........这里部分代码省略.........
$this->_retCode = CRM_IMPORT_PARSER_NO_MATCH;
}
}
} else {
$paramsValues = array('contact_id' => $params['id']);
$contact = crm_get_contact($paramsValues);
if (is_a($contact, CRM_Contact_BAO_Contact)) {
if ($formatted['contact_type'] == $contact->contact_type) {
$newContact = crm_update_contact_formatted($contact->id, $formatted, true);
$this->_retCode = CRM_IMPORT_PARSER_VALID;
} else {
$message = "Mismatched contact Types :";
array_unshift($values, $message);
$this->_retCode = CRM_IMPORT_PARSER_NO_MATCH;
}
} else {
$message = "No contact found for this contact ID:" . $params['id'];
array_unshift($values, $message);
$this->_retCode = CRM_IMPORT_PARSER_NO_MATCH;
}
}
if (is_a($newContact, CRM_Contact_BAO_Contact)) {
$relationship = true;
} else {
if (is_a($error, CRM_Core_Error)) {
$newContact = $error;
$relationship = true;
}
}
if ($newContact && !is_a($newContact, CRM_Core_Error)) {
$this->_newContacts[] = $newContact->id;
}
} else {
$newContact = crm_create_contact_formatted($formatted, $onDuplicate);
$relationship = true;
}
if ($relationship) {
if (CRM_Import_Parser_Contact::isDuplicate($newContact)) {
foreach ($newContact->_errors[0]['params'] as $cid) {
$primaryContactId = $cid;
}
} else {
$primaryContactId = $newContact->id;
}
if (CRM_Import_Parser_Contact::isDuplicate($newContact) || is_a($newContact, CRM_Contact_BAO_Contact)) {
//relationship contact insert
foreach ($params as $key => $field) {
list($id, $first, $second) = explode('_', $key);
if (!($first == 'a' && $second == 'b') && !($first == 'b' && $second == 'a')) {
continue;
}
$relationType = new CRM_Contact_DAO_RelationshipType();
$relationType->id = $id;
$relationType->find(true);
$name_a_b = $relationType->name_a_b;
if ($params[$key]['contact_type']) {
$formatting = array('contact_type' => $params[$key]['contact_type']);
} else {
$fld = array_keys($params[$key]);
foreach (CRM_Core_SelectValues::contactType() as $cType => $val) {
if ($cType) {
$contactFields =& CRM_Contact_BAO_Contact::importableFields($cType);
if (array_key_exists($fld[0], $contactFields)) {
$formatting['contact_type'] = $cType;
$params[$key]['contact_type'] = $cType;
$field['contact_type'] = $cType;
示例13: relationship
static function relationship()
{
$relType = CRM_Utils_Request::retrieve('rel_type', 'Positive', CRM_Core_DAO::$_nullObject, TRUE);
$relContactID = CRM_Utils_Request::retrieve('rel_contact', 'Positive', CRM_Core_DAO::$_nullObject, TRUE);
$relationshipID = CRM_Utils_Array::value('rel_id', $_REQUEST);
// this used only to determine add or update mode
$caseID = CRM_Utils_Request::retrieve('case_id', 'Positive', CRM_Core_DAO::$_nullObject, TRUE);
// check if there are multiple clients for this case, if so then we need create
// relationship and also activities for each contacts
// get case client list
$clientList = CRM_Case_BAO_Case::getCaseClients($caseID);
$ret = array('is_error' => 0);
foreach ($clientList as $sourceContactID) {
$relationParams = array('relationship_type_id' => $relType . '_a_b', 'contact_check' => array($relContactID => 1), 'is_active' => 1, 'case_id' => $caseID, 'start_date' => date("Ymd"));
$relationIds = array('contact' => $sourceContactID);
// check if we are editing/updating existing relationship
if ($relationshipID && $relationshipID != 'null') {
// here we need to retrieve appropriate relationshipID based on client id and relationship type id
$caseRelationships = new CRM_Contact_DAO_Relationship();
$caseRelationships->case_id = $caseID;
$caseRelationships->relationship_type_id = $relType;
$caseRelationships->contact_id_a = $sourceContactID;
$caseRelationships->find();
while ($caseRelationships->fetch()) {
$relationIds['relationship'] = $caseRelationships->id;
$relationIds['contactTarget'] = $relContactID;
}
$caseRelationships->free();
}
// create new or update existing relationship
$return = CRM_Contact_BAO_Relationship::create($relationParams, $relationIds);
if (!empty($return[4][0])) {
$relationshipID = $return[4][0];
//create an activity for case role assignment.CRM-4480
CRM_Case_BAO_Case::createCaseRoleActivity($caseID, $relationshipID, $relContactID);
} else {
$ret = array('is_error' => 1, 'error_message' => ts('The relationship type definition for the case role is not valid for the client and / or staff contact types. You can review and edit relationship types at <a href="%1">Administer >> Option Lists >> Relationship Types</a>.', array(1 => CRM_Utils_System::url('civicrm/admin/reltype', 'reset=1'))));
}
}
CRM_Utils_JSON::output($ret);
}
示例14: testRelCreateWithinDiffTypeStudentSponsor
function testRelCreateWithinDiffTypeStudentSponsor()
{
//check for Student to Sponcer
$relTypeParams = array('name_a_b' => 'StudentToSponsor', 'name_b_a' => 'SponsorToStudent', 'contact_type_a' => 'Individual', 'contact_sub_type_a' => $this->student, 'contact_type_b' => 'Organization', 'contact_sub_type_b' => $this->sponsor);
$relTypeIds = array();
$relType = CRM_Contact_BAO_RelationshipType::add($relTypeParams, $relTypeIds);
$params = array('relationship_type_id' => $relType->id . '_a_b', 'is_active' => 1, 'contact_check' => array($this->organization_sponsor => 1));
$ids = array('contact' => $this->indivi_student);
list($valid, $invalid, $duplicate, $saved, $relationshipIds) = CRM_Contact_BAO_Relationship::create($params, $ids);
$this->assertEquals($valid, 1, 'In line ' . __LINE__);
$this->assertEquals(empty($relationshipIds), FALSE, 'In line ' . __LINE__);
$this->relationshipTypeDelete($relType->id);
}
示例15: processOnBehalfOrganization
/**
* Function to add on behalf of organization and it's location
*
* @param $behalfOrganization array array of organization info
* @param $contactID int individual contact id. One
* who is doing the process of signup / contribution.
*
* @param $values array form values array
* @param $params
* @param null $fields
*
* @return void
* @access public
*/
static function processOnBehalfOrganization(&$behalfOrganization, &$contactID, &$values, &$params, $fields = NULL)
{
$isCurrentEmployer = FALSE;
$orgID = NULL;
if (!empty($behalfOrganization['organization_id']) && !empty($behalfOrganization['org_option'])) {
$orgID = $behalfOrganization['organization_id'];
unset($behalfOrganization['organization_id']);
$isCurrentEmployer = TRUE;
}
// formalities for creating / editing organization.
$behalfOrganization['contact_type'] = 'Organization';
// get the relationship type id
$relType = new CRM_Contact_DAO_RelationshipType();
$relType->name_a_b = 'Employee of';
$relType->find(TRUE);
$relTypeId = $relType->id;
// keep relationship params ready
$relParams['relationship_type_id'] = $relTypeId . '_a_b';
$relParams['is_permission_a_b'] = 1;
$relParams['is_active'] = 1;
if (!$orgID) {
// check if matching organization contact exists
$dedupeParams = CRM_Dedupe_Finder::formatParams($behalfOrganization, 'Organization');
$dedupeParams['check_permission'] = FALSE;
$dupeIDs = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Organization', 'Unsupervised');
// CRM-6243 says to pick the first org even if more than one match
if (count($dupeIDs) >= 1) {
$behalfOrganization['contact_id'] = $dupeIDs[0];
// don't allow name edit
unset($behalfOrganization['organization_name']);
}
} else {
// if found permissioned related organization, allow location edit
$behalfOrganization['contact_id'] = $orgID;
// don't allow name edit
unset($behalfOrganization['organization_name']);
}
// handling for image url
if (!empty($behalfOrganization['image_URL'])) {
CRM_Contact_BAO_Contact::processImageParams($behalfOrganization);
}
// create organization, add location
$orgID = CRM_Contact_BAO_Contact::createProfileContact($behalfOrganization, $fields, $orgID, NULL, NULL, 'Organization');
// create relationship
$relParams['contact_check'][$orgID] = 1;
$cid = array('contact' => $contactID);
CRM_Contact_BAO_Relationship::create($relParams, $cid);
// if multiple match - send a duplicate alert
if ($dupeIDs && count($dupeIDs) > 1) {
$values['onbehalf_dupe_alert'] = 1;
// required for IPN
$params['onbehalf_dupe_alert'] = 1;
}
// make sure organization-contact-id is considered for recording
// contribution/membership etc..
if ($contactID != $orgID) {
// take a note of contact-id, so we can send the
// receipt to individual contact as well.
// required for mailing/template display ..etc
$values['related_contact'] = $contactID;
// required for IPN
$params['related_contact'] = $contactID;
//make this employee of relationship as current
//employer / employee relationship, CRM-3532
if ($isCurrentEmployer && $orgID != CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'employer_id')) {
$isCurrentEmployer = FALSE;
}
if (!$isCurrentEmployer && $orgID) {
//build current employer params
$currentEmpParams[$contactID] = $orgID;
CRM_Contact_BAO_Contact_Utils::setCurrentEmployer($currentEmpParams);
}
// contribution / signup will be done using this
// organization id.
$contactID = $orgID;
}
}