本文整理汇总了PHP中CRM_Contact_BAO_Relationship::relatedMemberships方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contact_BAO_Relationship::relatedMemberships方法的具体用法?PHP CRM_Contact_BAO_Relationship::relatedMemberships怎么用?PHP CRM_Contact_BAO_Relationship::relatedMemberships使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Contact_BAO_Relationship
的用法示例。
在下文中一共展示了CRM_Contact_BAO_Relationship::relatedMemberships方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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]))));
}
示例2: 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');
}
示例3: import
//.........这里部分代码省略.........
}
}
static $relativeContact = array();
if (civicrm_duplicate($relatedNewContact)) {
if (count($matchedIDs) >= 1) {
$relContactId = $matchedIDs[0];
//add relative contact to count during update & fill mode.
//logic to make count distinct by contact id.
if ($this->_newRelatedContacts || !empty($relativeContact)) {
$reContact = array_keys($relativeContact, $relContactId);
if (empty($reContact)) {
$this->_newRelatedContacts[] = $relativeContact[] = $relContactId;
}
} else {
$this->_newRelatedContacts[] = $relativeContact[] = $relContactId;
}
}
} else {
$relContactId = $relatedNewContact->id;
$this->_newRelatedContacts[] = $relativeContact[] = $relContactId;
}
if (civicrm_duplicate($relatedNewContact) || $relatedNewContact instanceof CRM_Contact_BAO_Contact) {
//fix for CRM-1993.Checks for duplicate related contacts
if (count($matchedIDs) >= 1) {
//if more than one duplicate contact
//found, create relationship with first contact
// now create the relationship record
$relationParams = array();
$relationParams = array('relationship_type_id' => $key, 'contact_check' => array($relContactId => 1), 'is_active' => 1, 'skipRecentView' => true);
// we only handle related contact success, we ignore failures for now
// at some point wold be nice to have related counts as separate
$relationIds = array('contact' => $primaryContactId);
list($valid, $invalid, $duplicate, $saved, $relationshipIds) = CRM_Contact_BAO_Relationship::create($relationParams, $relationIds);
CRM_Contact_BAO_Relationship::relatedMemberships($primaryContactId, $relationParams, $relationIds);
//handle current employer, CRM-3532
if ($valid) {
require_once 'CRM/Core/PseudoConstant.php';
$allRelationships = CRM_Core_PseudoConstant::relationshipType('name');
$relationshipTypeId = str_replace(array('_a_b', '_b_a'), array('', ''), $key);
$relationshipType = str_replace($relationshipTypeId . '_', '', $key);
$orgId = $individualId = null;
if ($allRelationships[$relationshipTypeId]["name_{$relationshipType}"] == 'Employee of') {
$orgId = $relContactId;
$individualId = $primaryContactId;
} else {
if ($allRelationships[$relationshipTypeId]["name_{$relationshipType}"] == 'Employer of') {
$orgId = $primaryContactId;
$individualId = $relContactId;
}
}
if ($orgId && $individualId) {
$currentEmpParams[$individualId] = $orgId;
require_once 'CRM/Contact/BAO/Contact/Utils.php';
CRM_Contact_BAO_Contact_Utils::setCurrentEmployer($currentEmpParams);
}
}
}
}
}
}
}
if ($this->_updateWithId) {
//return warning if street address is unparsed, CRM-5886
return $this->processMessage($values, $statusFieldName, $this->_retCode);
}
//dupe checking
示例4: disableEnableRelationship
/**
* Disable/enable the relationship.
*
* @param int $id
* Relationship id.
*
* @param int $action
* @param array $params
* @param array $ids
* @param bool $active
*/
public static function disableEnableRelationship($id, $action, $params = array(), $ids = array(), $active = FALSE)
{
$relationship = self::clearCurrentEmployer($id, $action);
if ($id) {
// create $params array which is required to delete memberships
// of the related contacts.
if (empty($params)) {
$params = array('relationship_type_id' => "{$relationship->relationship_type_id}_a_b", 'contact_check' => array($relationship->contact_id_b => 1));
}
$contact_id_a = empty($params['contact_id_a']) ? $relationship->contact_id_a : $params['contact_id_a'];
// calling relatedMemberships to delete/add the memberships of
// related contacts.
if ($action & CRM_Core_Action::DISABLE) {
CRM_Contact_BAO_Relationship::relatedMemberships($contact_id_a, $params, $ids, CRM_Core_Action::DELETE, $active);
} elseif ($action & CRM_Core_Action::ENABLE) {
$ids['contact'] = empty($ids['contact']) ? $contact_id_a : $ids['contact'];
CRM_Contact_BAO_Relationship::relatedMemberships($contact_id_a, $params, $ids, empty($params['id']) ? CRM_Core_Action::ADD : CRM_Core_Action::UPDATE, $active);
}
}
}
示例5: clearCurrentEmployer
/**
* Clear cached current employer name.
*
* @param int $contactId
* Contact id ( mostly individual contact id).
* @param int $employerId
* Contact id ( mostly organization contact id).
*/
public static function clearCurrentEmployer($contactId, $employerId = NULL)
{
$query = "UPDATE civicrm_contact\nSET organization_name=NULL, employer_id = NULL\nWHERE id={$contactId}; ";
$dao = CRM_Core_DAO::executeQuery($query);
// need to handle related meberships. CRM-3792
if ($employerId) {
//1. disable corresponding relationship.
//2. delete related membership.
//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'"));
}
$relMembershipParams['relationship_type_id'] = $relTypeId . '_a_b';
$relMembershipParams['contact_check'][$employerId] = 1;
//get relationship id.
if (CRM_Contact_BAO_Relationship::checkDuplicateRelationship($relMembershipParams, $contactId, $employerId)) {
$relationship = new CRM_Contact_DAO_Relationship();
$relationship->contact_id_a = $contactId;
$relationship->contact_id_b = $employerId;
$relationship->relationship_type_id = $relTypeId;
if ($relationship->find(TRUE)) {
CRM_Contact_BAO_Relationship::setIsActive($relationship->id, FALSE);
CRM_Contact_BAO_Relationship::relatedMemberships($contactId, $relMembershipParams, $ids = array(), CRM_Core_Action::DELETE);
}
$relationship->free();
}
}
}
示例6: postProcess
//.........这里部分代码省略.........
//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) {
require_once "CRM/Case/BAO/Case.php";
CRM_Case_BAO_Case::createCaseRoleActivity($this->_caseId, $relationshipIds, $params['contact_check'], $this->_contactId);
}
$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.');
}
$note = new CRM_Core_DAO_Note();
$note->entity_id = $relationshipIds[0];
$note->entity_table = 'civicrm_relationship';
$noteIds = array();
if ($note->find(true)) {
$id = $note->id;
$noteIds["id"] = $id;
}
$noteParams = array('entity_id' => $relationshipIds[0], 'entity_table' => 'civicrm_relationship', 'note' => $params['note'], 'contact_id' => $this->_contactId);
CRM_Core_BAO_Note::add($noteParams, $noteIds);
// Membership for related contacts CRM-1657
if (CRM_Core_Permission::access('CiviMember') && !$duplicate) {
CRM_Contact_BAO_Relationship::relatedMemberships($this->_contactId, $params, $ids, $this->_action);
}
//handle current employee/employer relationship, CRM-3532
if ($this->_allRelationshipNames[$relationshipTypeId]["name_{$this->_rtype}"] == 'Employee of') {
$orgId = null;
if (CRM_Utils_Array::value('employee_of', $params)) {
$orgId = $params['employee_of'];
} else {
if ($this->_action & CRM_Core_Action::UPDATE) {
if (CRM_Utils_Array::value('is_current_employer', $params) && CRM_Utils_Array::value('is_active', $params)) {
if (CRM_Utils_Array::value('contactTarget', $ids) != CRM_Utils_Array::value('current_employer_id', $this->_values)) {
$orgId = CRM_Utils_Array::value('contactTarget', $ids);
}
} else {
if (CRM_Utils_Array::value('contactTarget', $ids) == CRM_Utils_Array::value('current_employer_id', $this->_values)) {
//clear current employer.
require_once 'CRM/Contact/BAO/Contact/Utils.php';
CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($this->_contactId);
}
}
}
}
//set current employer
if ($orgId) {
$currentEmpParams[$this->_contactId] = $orgId;
require_once 'CRM/Contact/BAO/Contact/Utils.php';
CRM_Contact_BAO_Contact_Utils::setCurrentEmployer($currentEmpParams);
}
} else {
if ($this->_allRelationshipNames[$relationshipTypeId]["name_{$this->_rtype}"] == 'Employer of') {
$individualIds = array();
if (CRM_Utils_Array::value('employer_of', $params)) {
$individualIds = array_keys($params['employer_of']);
} else {
if ($this->_action & CRM_Core_Action::UPDATE) {
if (CRM_Utils_Array::value('is_current_employer', $params)) {
if (CRM_Utils_Array::value('contactTarget', $ids) != CRM_Utils_Array::value('current_employee_id', $this->_values)) {
$individualIds[] = CRM_Utils_Array::value('contactTarget', $ids);
}
} else {
if (CRM_Utils_Array::value('contactTarget', $ids) == CRM_Utils_Array::value('current_employee_id', $this->_values)) {
// clear current employee
require_once 'CRM/Contact/BAO/Contact/Utils.php';
CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($ids['contactTarget']);
}
}
}
}
//set current employee
if (!empty($individualIds)) {
//build the employee params.
foreach ($individualIds as $key => $Id) {
$currentEmpParams[$Id] = $this->_contactId;
}
require_once 'CRM/Contact/BAO/Contact/Utils.php';
CRM_Contact_BAO_Contact_Utils::setCurrentEmployer($currentEmpParams);
}
}
}
CRM_Core_Session::setStatus($status);
if ($quickSave) {
$session =& CRM_Core_Session::singleton();
CRM_Utils_System::redirect($session->popUserContext());
}
}
示例7: disableEnableRelationship
/**
* Function to disable/enable the relationship
*
* @param int $id relationship id
*
* @return null
* @access public
* @static
*/
static function disableEnableRelationship($id, $action)
{
$relationship = self::clearCurrentEmployer($id, $action);
if (CRM_Core_Permission::access('CiviMember')) {
// create $params array which isrequired to delete memberships
// of the related contacts.
$params = array('relationship_type_id' => "{$relationship->relationship_type_id}_a_b", 'contact_check' => array($relationship->contact_id_b => 1));
$ids = array();
// calling relatedMemberships to delete/add the memberships of
// related contacts.
if ($action & CRM_Core_Action::DISABLE) {
CRM_Contact_BAO_Relationship::relatedMemberships($relationship->contact_id_a, $params, $ids, CRM_Core_Action::DELETE, FALSE);
} elseif ($action & CRM_Core_Action::ENABLE) {
$ids['contact'] = $relationship->contact_id_a;
CRM_Contact_BAO_Relationship::relatedMemberships($relationship->contact_id_a, $params, $ids, CRM_Core_Action::ADD, FALSE);
}
}
}
示例8: 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();
$action = CRM_Core_Action::ADD;
require_once 'CRM/Utils/Array.php';
if (CRM_Utils_Array::value('id', $params)) {
$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 (is_a($relationshipBAO, 'CRM_Core_Error')) {
return civicrm_create_error('Relationship can not be created');
} elseif ($relationshipBAO[1]) {
return civicrm_create_error('Relationship is not valid');
} elseif ($relationshipBAO[2]) {
return civicrm_create_error('Relationship already exists');
}
CRM_Contact_BAO_Relationship::relatedMemberships($params['contact_id_a'], $values, $ids, $action);
return civicrm_create_success(array('id' => implode(',', $relationshipBAO[4])));
}
示例9: import
//.........这里部分代码省略.........
if (CRM_Core_Error::isAPIError($relatedNewContact, CRM_Core_ERROR::DUPLICATE_CONTACT)) {
if (count($matchedIDs) >= 1) {
$relContactId = $matchedIDs[0];
//add relative contact to count during update & fill mode.
//logic to make count distinct by contact id.
if ($this->_newRelatedContacts || !empty($relativeContact)) {
$reContact = array_keys($relativeContact, $relContactId);
if (empty($reContact)) {
$this->_newRelatedContacts[] = $relativeContact[] = $relContactId;
}
} else {
$this->_newRelatedContacts[] = $relativeContact[] = $relContactId;
}
}
} else {
$relContactId = $relatedNewContact->id;
$this->_newRelatedContacts[] = $relativeContact[] = $relContactId;
}
if (CRM_Core_Error::isAPIError($relatedNewContact, CRM_Core_ERROR::DUPLICATE_CONTACT) || $relatedNewContact instanceof CRM_Contact_BAO_Contact) {
//fix for CRM-1993.Checks for duplicate related contacts
if (count($matchedIDs) >= 1) {
//if more than one duplicate contact
//found, create relationship with first contact
// now create the relationship record
$relationParams = array();
$relationParams = array('relationship_type_id' => $key, 'contact_check' => array($relContactId => 1), 'is_active' => 1, 'skipRecentView' => TRUE);
// we only handle related contact success, we ignore failures for now
// at some point wold be nice to have related counts as separate
$relationIds = array('contact' => $primaryContactId);
list($valid, $invalid, $duplicate, $saved, $relationshipIds) = CRM_Contact_BAO_Relationship::legacyCreateMultiple($relationParams, $relationIds);
if ($valid || $duplicate) {
$relationIds['contactTarget'] = $relContactId;
$action = $duplicate ? CRM_Core_Action::UPDATE : CRM_Core_Action::ADD;
CRM_Contact_BAO_Relationship::relatedMemberships($primaryContactId, $relationParams, $relationIds, $action);
}
//handle current employer, CRM-3532
if ($valid) {
$allRelationships = CRM_Core_PseudoConstant::relationshipType('name');
$relationshipTypeId = str_replace(array('_a_b', '_b_a'), array('', ''), $key);
$relationshipType = str_replace($relationshipTypeId . '_', '', $key);
$orgId = $individualId = NULL;
if ($allRelationships[$relationshipTypeId]["name_{$relationshipType}"] == 'Employee of') {
$orgId = $relContactId;
$individualId = $primaryContactId;
} elseif ($allRelationships[$relationshipTypeId]["name_{$relationshipType}"] == 'Employer of') {
$orgId = $primaryContactId;
$individualId = $relContactId;
}
if ($orgId && $individualId) {
$currentEmpParams[$individualId] = $orgId;
CRM_Contact_BAO_Contact_Utils::setCurrentEmployer($currentEmpParams);
}
}
}
}
}
}
}
if ($this->_updateWithId) {
//return warning if street address is unparsed, CRM-5886
return $this->processMessage($values, $statusFieldName, $this->_retCode);
}
//dupe checking
if (is_array($newContact) && civicrm_error($newContact)) {
$code = NULL;
if (($code = CRM_Utils_Array::value('code', $newContact['error_message'])) && $code == CRM_Core_Error::DUPLICATE_CONTACT) {
示例10: postProcess
//.........这里部分代码省略.........
$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 = '';
if ($valid) {
CRM_Core_Session::setStatus(ts('New relationship created.', array('count' => $valid, 'plural' => '%count new relationships created.')), ts('Saved'), 'success');
}
if ($invalid) {
CRM_Core_Session::setStatus(ts('%count relationship record was not created due to an invalid target contact type.', array('count' => $invalid, 'plural' => '%count relationship records were not created due to invalid target contact types.')), ts('%count invalid relationship record', array('count' => $invalid, 'plural' => '%count invalid relationship records')));
}
if ($duplicate) {
CRM_Core_Session::setStatus(ts('One relationship was not created because it already exists.', array('count' => $duplicate, 'plural' => '%count relationships were not created because they already exist.')), ts('%count duplicate relationship', array('count' => $duplicate, 'plural' => '%count duplicate relationships')));
}
if ($saved) {
CRM_Core_Session::setStatus(ts('Relationship record has been updated.'), ts('Saved'), 'success');
}
if (!empty($relationshipIds)) {
$note = new CRM_Core_DAO_Note();
$note->entity_id = $relationshipIds[0];
$note->entity_table = 'civicrm_relationship';
$noteIds = array();
if ($note->find(TRUE)) {
$id = $note->id;
$noteIds['id'] = $id;
}
$noteParams = array('entity_id' => $relationshipIds[0], 'entity_table' => 'civicrm_relationship', 'note' => $params['note'], 'contact_id' => $this->_contactId);
CRM_Core_BAO_Note::add($noteParams, $noteIds);
$params['relationship_ids'] = $relationshipIds;
}
// Membership for related contacts CRM-1657
if (CRM_Core_Permission::access('CiviMember') && !$duplicate) {
if ($this->_action & CRM_Core_Action::ADD) {
CRM_Contact_BAO_Relationship::relatedMemberships($this->_contactId, $params, $ids, $this->_action);
} elseif ($this->_action & CRM_Core_Action::UPDATE) {
//fixes for CRM-7985
//only if the relationship has been toggled to enable /disable
if (CRM_Utils_Array::value('is_active', $params) != $this->_enabled) {
$active = CRM_Utils_Array::value('is_active', $params) ? CRM_Core_Action::ENABLE : CRM_Core_Action::DISABLE;
CRM_Contact_BAO_Relationship::disableEnableRelationship($this->_relationshipId, $active);
}
}
}
//handle current employee/employer relationship, CRM-3532
if ($this->_allRelationshipNames[$relationshipTypeId]["name_{$this->_rtype}"] == 'Employee of') {
$orgId = NULL;
if (CRM_Utils_Array::value('employee_of', $params)) {
$orgId = $params['employee_of'];
} elseif ($this->_action & CRM_Core_Action::UPDATE) {
if (CRM_Utils_Array::value('is_current_employer', $params) && CRM_Utils_Array::value('is_active', $params)) {
if (CRM_Utils_Array::value('contactTarget', $ids) != CRM_Utils_Array::value('current_employer_id', $this->_values)) {
$orgId = CRM_Utils_Array::value('contactTarget', $ids);
}
} elseif (CRM_Utils_Array::value('contactTarget', $ids) == CRM_Utils_Array::value('current_employer_id', $this->_values)) {
//clear current employer.
CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($this->_contactId);
}
}
//set current employer
if ($orgId) {
$currentEmpParams[$this->_contactId] = $orgId;
CRM_Contact_BAO_Contact_Utils::setCurrentEmployer($currentEmpParams);
}
} elseif ($this->_allRelationshipNames[$relationshipTypeId]["name_{$this->_rtype}"] == 'Employer of') {
$individualIds = array();
if (CRM_Utils_Array::value('employer_of', $params)) {
$individualIds = array_keys($params['employer_of']);
} elseif ($this->_action & CRM_Core_Action::UPDATE) {
if (CRM_Utils_Array::value('is_current_employer', $params)) {
if (CRM_Utils_Array::value('contactTarget', $ids) != CRM_Utils_Array::value('current_employee_id', $this->_values)) {
$individualIds[] = CRM_Utils_Array::value('contactTarget', $ids);
}
} elseif (CRM_Utils_Array::value('contactTarget', $ids) == CRM_Utils_Array::value('current_employee_id', $this->_values)) {
// clear current employee
CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($ids['contactTarget']);
}
}
//set current employee
if (!empty($individualIds)) {
//build the employee params.
foreach ($individualIds as $key => $Id) {
$currentEmpParams[$Id] = $this->_contactId;
}
CRM_Contact_BAO_Contact_Utils::setCurrentEmployer($currentEmpParams);
}
}
if ($quickSave) {
$session = CRM_Core_Session::singleton();
CRM_Utils_System::redirect($session->popUserContext());
}
}
示例11: crm_update_relationship
/**
* Function to update relationship
*
* @param object $relationship A valid Relationship object.
* @param array $params Associative array of property name/value pairs to be updated. See Data Model for available properties.
*
* @return updated relationship object
*
* @access public
*
*/
function crm_update_relationship(&$relationship, $params)
{
$ids = array();
if (!isset($relationship->id) && !isset($relationship->contact_id_a) && !isset($relationship->contact_id_b)) {
return _crm_error('$relationship is not valid relationship type object');
}
$conactId = $relationship->contact_id_b;
$params['relationship_type_id'] = $relationship->relationship_type_id . '_a_b';
$ids['contact'] = $relationship->contact_id_a;
$ids['relationship'] = $relationship->id;
$ids['contactTarget'] = $relationship->contact_id_b;
$relationship = CRM_Contact_BAO_Relationship::add($params, $ids, $conactId);
if (CRM_Core_Permission::access('CiviMember')) {
$params['contact_check'] = array($relationship->contact_id_b => 1);
CRM_Contact_BAO_Relationship::relatedMemberships($relationship->contact_id_a, $params, $ids, CRM_Core_Action::ADD);
}
return $relationship;
}
示例12: disableEnableRelationship
/**
* Function to disable/enable the relationship
*
* @param int $id relationship id
*
* @return null
* @access public
* @static
*/
static function disableEnableRelationship($id, $action)
{
$relationship =& new CRM_Contact_DAO_Relationship();
$relationship->id = $id;
$relationship->find(true);
if (CRM_Core_Permission::access('CiviMember')) {
// create $params array which isrequired to delete memberships
// of the related contacts.
$params = array('relationship_type_id' => "{$relationship->relationship_type_id}_a_b", 'contact_check' => array($relationship->contact_id_b => 1));
$ids = array();
// calling relatedMemberships to delete/add the memberships of
// related contacts.
if ($action & CRM_Core_Action::DISABLE) {
//to delete relationship between household and individual
if ($relationship->relationship_type_id == 7) {
self::deleteSharedAddress($relationship->contact_id_a);
}
CRM_Contact_BAO_Relationship::relatedMemberships($relationship->contact_id_a, $params, $ids, CRM_Core_Action::DELETE);
}
if ($action & CRM_Core_Action::ENABLE) {
$ids['contact'] = $relationship->contact_id_a;
CRM_Contact_BAO_Relationship::relatedMemberships($relationship->contact_id_a, $params, $ids, CRM_Core_Action::ADD);
}
}
}
示例13: disableEnableRelationship
/**
* Function to disable/enable the relationship
*
* @param int $id relationship id
*
* @return null
* @access public
* @static
*/
static function disableEnableRelationship($id, $action)
{
$relationship = new CRM_Contact_DAO_Relationship();
$relationship->id = $id;
$relationship->find(true);
//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 && $action & CRM_Core_Action::DISABLE) {
require_once 'CRM/Contact/BAO/Contact/Utils.php';
CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($relationship->contact_id_a);
}
if (CRM_Core_Permission::access('CiviMember')) {
// create $params array which isrequired to delete memberships
// of the related contacts.
$params = array('relationship_type_id' => "{$relationship->relationship_type_id}_a_b", 'contact_check' => array($relationship->contact_id_b => 1));
$ids = array();
// calling relatedMemberships to delete/add the memberships of
// related contacts.
if ($action & CRM_Core_Action::DISABLE) {
CRM_Contact_BAO_Relationship::relatedMemberships($relationship->contact_id_a, $params, $ids, CRM_Core_Action::DELETE, false);
} else {
if ($action & CRM_Core_Action::ENABLE) {
$ids['contact'] = $relationship->contact_id_a;
CRM_Contact_BAO_Relationship::relatedMemberships($relationship->contact_id_a, $params, $ids, CRM_Core_Action::ADD, false);
}
}
}
}
示例14: postProcess
/**
* This function is called when the form is submitted
*
* @access public
*
* @return void
*/
public function postProcess()
{
// store the submitted values in an array
$params = $this->controller->exportValues($this->_name);
// action is taken depending upon the mode
if ($this->_action & CRM_Core_Action::DELETE) {
CRM_Contact_BAO_Relationship::del($this->_relationshipId);
return;
}
$ids = array('contact' => $this->_contactId);
$relationshipTypeId = str_replace(array('_', 'a', 'b'), '', $params['relationship_type_id']);
// CRM-14612 - Don't use adv-checkbox as it interferes with the form js
$params['is_permission_a_b'] = CRM_Utils_Array::value('is_permission_a_b', $params, 0);
$params['is_permission_b_a'] = CRM_Utils_Array::value('is_permission_b_a', $params, 0);
// Update mode (always single)
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 ($this->_isCurrentEmployer) {
// if relationship type changes, relationship is disabled, or "current employer" is unchecked,
// clear the current employer. CRM-3235.
$relChanged = $relationshipTypeId != $this->_values['relationship_type_id'];
if (!$params['is_active'] || !$params['is_current_employer'] || $relChanged) {
CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($this->_values['contact_id_a']);
// Refresh contact summary if in ajax mode
$this->ajaxResponse['reloadBlocks'] = array('#crm-contactinfo-content');
}
}
} else {
// Fill up this weird param with contact ids like the weird relationship bao expects
$params['contact_check'] = array_fill_keys(explode(',', $params['related_contact_id']), 1);
if (!$this->_rtype) {
list(, $this->_rtype) = explode('_', $params['relationship_type_id'], 2);
}
}
$params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], NULL, TRUE);
$params['end_date'] = CRM_Utils_Date::processDate($params['end_date'], NULL, TRUE);
// Process custom data
$customFields = CRM_Core_BAO_CustomField::getFields('Relationship', FALSE, FALSE, $relationshipTypeId);
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_relationshipId, 'Relationship');
// Save relationships
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);
}
if ($valid) {
CRM_Core_Session::setStatus(ts('Relationship created.', array('count' => $valid, 'plural' => '%count relationships created.')), ts('Saved'), 'success');
}
if ($invalid) {
CRM_Core_Session::setStatus(ts('%count relationship record was not created due to an invalid contact type.', array('count' => $invalid, 'plural' => '%count relationship records were not created due to invalid contact types.')), ts('%count invalid relationship record', array('count' => $invalid, 'plural' => '%count invalid relationship records')));
}
if ($duplicate) {
CRM_Core_Session::setStatus(ts('One relationship was not created because it already exists.', array('count' => $duplicate, 'plural' => '%count relationships were not created because they already exist.')), ts('%count duplicate relationship', array('count' => $duplicate, 'plural' => '%count duplicate relationships')));
}
if ($saved) {
CRM_Core_Session::setStatus(ts('Relationship record has been updated.'), ts('Saved'), 'success');
}
// Save notes
if ($this->_action & CRM_Core_Action::UPDATE || $params['note']) {
foreach ($relationshipIds as $id) {
$noteParams = array('entity_id' => $id, 'entity_table' => 'civicrm_relationship');
$existing = civicrm_api3('note', 'get', $noteParams);
if (!empty($existing['id'])) {
$noteParams['id'] = $existing['id'];
}
$noteParams['note'] = $params['note'];
$noteParams['contact_id'] = $this->_contactId;
if (!empty($existing['id']) || $params['note']) {
$action = $params['note'] ? 'create' : 'delete';
civicrm_api3('note', $action, $noteParams);
}
}
}
// Membership for related contacts CRM-1657
if (CRM_Core_Permission::access('CiviMember') && !$duplicate) {
$params['relationship_ids'] = $relationshipIds;
if ($this->_action & CRM_Core_Action::ADD) {
CRM_Contact_BAO_Relationship::relatedMemberships($this->_contactId, $params, $ids, $this->_action);
} elseif ($this->_action & CRM_Core_Action::UPDATE) {
//fixes for CRM-7985
//only if the relationship has been toggled to enable /disable
if (CRM_Utils_Array::value('is_active', $params) != $this->_enabled) {
$active = !empty($params['is_active']) ? CRM_Core_Action::ENABLE : CRM_Core_Action::DISABLE;
CRM_Contact_BAO_Relationship::disableEnableRelationship($this->_relationshipId, $active);
}
}
// Refresh contact tabs with related data
$this->ajaxResponse['updateTabs'] = array('#tab_member' => CRM_Contact_BAO_Contact::getCountComponent('membership', $this->_contactId));
}
// Set current employee/employer relationship, CRM-3532
//.........这里部分代码省略.........