本文整理汇总了PHP中CRM_Contact_BAO_Relationship::createMultiple方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contact_BAO_Relationship::createMultiple方法的具体用法?PHP CRM_Contact_BAO_Relationship::createMultiple怎么用?PHP CRM_Contact_BAO_Relationship::createMultiple使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Contact_BAO_Relationship
的用法示例。
在下文中一共展示了CRM_Contact_BAO_Relationship::createMultiple方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addRelationships
/**
* Add relationships from form.
*/
public function addRelationships()
{
if (!is_array($this->_contactIds)) {
// Could this really happen?
return;
}
$relationshipTypeParts = explode('_', $this->params['relationship_type_id']);
$params = array('relationship_type_id' => $relationshipTypeParts[0], 'is_active' => 1);
$secondaryRelationshipSide = $relationshipTypeParts[1];
$primaryRelationshipSide = $relationshipTypeParts[2];
$primaryFieldName = 'contact_id_' . $primaryRelationshipSide;
$secondaryFieldName = 'contact_id_' . $secondaryRelationshipSide;
$relationshipLabel = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $params['relationship_type_id'], "label_{$secondaryRelationshipSide}_{$primaryRelationshipSide}");
$params[$secondaryFieldName] = $this->_contactIds;
$params[$primaryFieldName] = $this->params['contact_check'];
$outcome = CRM_Contact_BAO_Relationship::createMultiple($params, $primaryRelationshipSide);
$relatedContactName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $params[$primaryFieldName], 'display_name');
$status = array(ts('%count %2 %3 relationship created', array('count' => $outcome['valid'], 'plural' => '%count %2 %3 relationships created', 2 => $relationshipLabel, 3 => $relatedContactName)));
if ($outcome['duplicate']) {
$status[] = ts('%count was skipped because the contact is already %2 %3', array('count' => $outcome['duplicate'], 'plural' => '%count were skipped because the contacts are already %2 %3', 2 => $relationshipLabel, 3 => $relatedContactName));
}
if ($outcome['invalid']) {
$status[] = ts('%count relationship was not created because the contact is not of the right type for this relationship', array('count' => $outcome['invalid'], 'plural' => '%count relationships were not created because the contact is not of the right type for this relationship'));
}
$status = '<ul><li>' . implode('</li><li>', $status) . '</li></ul>';
CRM_Core_Session::setStatus($status, ts('Relationship created.', array('count' => $outcome['valid'], 'plural' => 'Relationships created.')), 'success', array('expires' => 0));
}
示例2: postProcess
/**
* This function is called when the form is submitted.
*/
public function postProcess()
{
// Store the submitted values in an array.
$params = $this->controller->exportValues($this->_name);
// 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);
// action is taken depending upon the mode
if ($this->_action & CRM_Core_Action::DELETE) {
CRM_Contact_BAO_Relationship::del($this->_relationshipId);
// CRM-15881 UPDATES
// Since the line above nullifies the organization_name and employer_id fiels in the contact record, we need to reload all blocks to reflect this chage on the user interface.
$this->ajaxResponse['reloadBlocks'] = array('#crm-contactinfo-content');
return;
}
$relationshipTypeParts = explode('_', $params['relationship_type_id']);
$params['relationship_type_id'] = $relationshipTypeParts[0];
if (!$this->_rtype) {
// Do we need to wrap this in an if - when is rtype used & is relationship_type_id always set then?
$this->_rtype = $params['relationship_type_id'];
}
$params['contact_id_' . $relationshipTypeParts[1]] = $this->_contactId;
// Update mode (always single)
if ($this->_action & CRM_Core_Action::UPDATE) {
$update = TRUE;
$params['id'] = $this->_relationshipId;
$ids['relationship'] = $this->_relationshipId;
$relation = CRM_Contact_BAO_Relationship::getRelationshipByID($this->_relationshipId);
if ($relation->contact_id_a == $this->_contactId) {
// I couldn't replicate this path in testing. See below.
$params['contact_id_a'] = $this->_contactId;
$params['contact_id_b'] = array($params['related_contact_id']);
$outcome = CRM_Contact_BAO_Relationship::createMultiple($params, $relationshipTypeParts[1]);
$relationshipIds = $outcome['relationship_ids'];
} else {
// The only reason we have changed this to use the api & not the above is that this was broken.
// Recommend extracting all of update into a function that uses the api
// and ensuring api / bao take care of 'other stuff' in this form
// the contact_id_a & b can't be changed on this form so don't really need setting.
$params['contact_id_b'] = $this->_contactId;
$params['contact_id_a'] = $params['related_contact_id'];
$result = civicrm_api3('relationship', 'create', $params);
$relationshipIds = array($result['id']);
}
$ids['contactTarget'] = $relation->contact_id_a == $this->_contactId ? $relation->contact_id_b : $relation->contact_id_a;
// @todo this belongs in the BAO.
if ($this->_isCurrentEmployer) {
// if relationship type changes, relationship is disabled, or "current employer" is unchecked,
// clear the current employer. CRM-3235.
$relChanged = $params['relationship_type_id'] != $this->_values['relationship_type_id'];
if (!$params['is_active'] || !$params['is_current_employer'] || $relChanged) {
// CRM-15881 UPDATES
// If not is_active then is_current_employer needs to be set false as well! Logically a contact cannot be a current employee of a disabled employer relationship.
// If this is not done, then the below process will go ahead and disable the organization_name and employer_id fields in the contact record (which is what is wanted) but then further down will be re-enabled becuase is_current_employer is not false, therefore undoing what was done correctly.
if (!$params['is_active']) {
$params['is_current_employer'] = FALSE;
}
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');
}
}
if (empty($outcome['saved']) && !empty($update)) {
$outcome['saved'] = $update;
}
$this->setMessage($outcome);
} else {
$params['contact_id_' . $relationshipTypeParts[2]] = explode(',', $params['related_contact_id']);
$outcome = CRM_Contact_BAO_Relationship::createMultiple($params, $relationshipTypeParts[1]);
$relationshipIds = $outcome['relationship_ids'];
if (empty($outcome['saved']) && !empty($update)) {
$outcome['saved'] = $update;
}
$this->setMessage($outcome);
}
// if this is called from case view,
//create an activity for case role removal.CRM-4480
// @todo this belongs in the BAO.
if ($this->_caseId) {
CRM_Case_BAO_Case::createCaseRoleActivity($this->_caseId, $relationshipIds, $params['contact_check'], $this->_contactId);
}
// Save notes
// @todo this belongs in the BAO.
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);
}
}
//.........这里部分代码省略.........