当前位置: 首页>>代码示例>>PHP>>正文


PHP CRM_Contact_BAO_Contact_Utils::setCurrentEmployer方法代码示例

本文整理汇总了PHP中CRM_Contact_BAO_Contact_Utils::setCurrentEmployer方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contact_BAO_Contact_Utils::setCurrentEmployer方法的具体用法?PHP CRM_Contact_BAO_Contact_Utils::setCurrentEmployer怎么用?PHP CRM_Contact_BAO_Contact_Utils::setCurrentEmployer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CRM_Contact_BAO_Contact_Utils的用法示例。


在下文中一共展示了CRM_Contact_BAO_Contact_Utils::setCurrentEmployer方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: import


//.........这里部分代码省略.........
                 }
                 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
     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) {
             $urls = array();
             // need to fix at some stage and decide if the error will return an
             // array or string, crude hack for now
             if (is_array($newContact['error_message']['params'][0])) {
                 $cids = $newContact['error_message']['params'][0];
             } else {
                 $cids = explode(',', $newContact['error_message']['params'][0]);
             }
             foreach ($cids as $cid) {
                 $urls[] = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $cid, true);
             }
             $url_string = implode("\n", $urls);
             // If we duplicate more than one record, skip no matter what
             if (count($cids) > 1) {
                 $errorMessage = ts('Record duplicates multiple contacts');
                 $importRecordParams = array($statusFieldName => 'ERROR', "{$statusFieldName}Msg" => $errorMessage);
                 //combine error msg to avoid mismatch between error file columns.
开发者ID:bhirsch,项目名称:voipdev,代码行数:67,代码来源:Contact.php

示例2: 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());
     }
 }
开发者ID:hampelm,项目名称:Ginsberg-CiviDemo,代码行数:101,代码来源:Relationship.php

示例3: processOnBehalfOrganization

 /**
  * Add on behalf of organization and it's location.
  *
  * This situation occurs when on behalf of is enabled for the contribution page and the person
  * signing up does so on behalf of an organization.
  *
  * @param array $behalfOrganization
  *   array of organization info.
  * @param int $contactID
  *   individual contact id. One.
  *   who is doing the process of signup / contribution.
  *
  * @param array $values
  *   form values array.
  * @param array $params
  * @param array $fields
  *   Array of fields from the onbehalf profile relevant to the organization.
  */
 public static function processOnBehalfOrganization(&$behalfOrganization, &$contactID, &$values, &$params, $fields = NULL)
 {
     $isNotCurrentEmployer = FALSE;
     $dupeIDs = array();
     $orgID = NULL;
     if (!empty($behalfOrganization['organization_id'])) {
         $orgID = $behalfOrganization['organization_id'];
         unset($behalfOrganization['organization_id']);
     } else {
         // get the Employee relationship type id
         $relTypeId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', 'Employee of', 'id', 'name_a_b');
         // keep relationship params ready
         $relParams['relationship_type_id'] = $relTypeId . '_a_b';
         $relParams['is_permission_a_b'] = 1;
         $relParams['is_active'] = 1;
         $isNotCurrentEmployer = TRUE;
     }
     // formalities for creating / editing organization.
     $behalfOrganization['contact_type'] = 'Organization';
     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'] = $orgID = $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
     if ($isNotCurrentEmployer) {
         $relParams['contact_check'][$orgID] = 1;
         $cid = array('contact' => $contactID);
         CRM_Contact_BAO_Relationship::legacyCreateMultiple($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;
         //make this employee of relationship as current
         //employer / employee relationship,  CRM-3532
         if ($isNotCurrentEmployer && $orgID != CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'employer_id')) {
             $isNotCurrentEmployer = FALSE;
         }
         if (!$isNotCurrentEmployer && $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;
     }
 }
开发者ID:hyebahi,项目名称:civicrm-core,代码行数:94,代码来源:Confirm.php

示例4: processOnBehalfOrganization

 /**
  * Function to add on behalf of organization and it's location  
  *
  * @param $behalfOrganization array  array of organization info
  * @param $values             array  form values array
  * @param $contactID          int    individual contact id. One
  * who is doing the process of signup / contribution. 
  *
  * @return void
  * @access public
  */
 static function processOnBehalfOrganization(&$behalfOrganization, &$contactID, &$values, &$params)
 {
     $isCurrentEmployer = false;
     if ($behalfOrganization['organization_id'] && $behalfOrganization['org_option']) {
         $orgID = $behalfOrganization['organization_id'];
         unset($behalfOrganization['organization_id']);
         $isCurrentEmployer = true;
     }
     // formalities for creating / editing organization.
     require_once "CRM/Core/BAO/LocationType.php";
     $locType = CRM_Core_BAO_LocationType::getDefault();
     $behalfOrganization['contact_type'] = 'Organization';
     foreach (array('phone', 'email', 'address') as $locFld) {
         $behalfOrganization[$locFld][1]['is_primary'] = 1;
         $behalfOrganization[$locFld][1]['location_type_id'] = $locType->id;
     }
     // get the relationship type id
     require_once "CRM/Contact/DAO/RelationshipType.php";
     $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
         require_once 'CRM/Dedupe/Finder.php';
         $dedupeParams = CRM_Dedupe_Finder::formatParams($behalfOrganization, 'Organization');
         $dupeIDs = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Organization', 'Strict');
         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']);
     }
     // create organization, add location
     $org = CRM_Contact_BAO_Contact::create($behalfOrganization);
     // create relationship
     $relParams['contact_check'][$org->id] = 1;
     $cid = array('contact' => $contactID);
     $relationship = CRM_Contact_BAO_Relationship::create($relParams, $cid);
     // take a note of new/updated organiation contact-id.
     $orgID = $org->id;
     // 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;
             require_once 'CRM/Contact/BAO/Contact/Utils.php';
             CRM_Contact_BAO_Contact_Utils::setCurrentEmployer($currentEmpParams);
         }
         // contribution / signup will be done using this
         // organization id.
         $contactID = $orgID;
     }
 }
开发者ID:bhirsch,项目名称:civicrm,代码行数:92,代码来源:Confirm.php

示例5: import


//.........这里部分代码省略.........
                 }
                 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) {
             $urls = array();
             // need to fix at some stage and decide if the error will return an
             // array or string, crude hack for now
             if (is_array($newContact['error_message']['params'][0])) {
                 $cids = $newContact['error_message']['params'][0];
             } else {
                 $cids = explode(',', $newContact['error_message']['params'][0]);
             }
             foreach ($cids as $cid) {
                 $urls[] = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $cid, TRUE);
             }
             $url_string = implode("\n", $urls);
             // If we duplicate more than one record, skip no matter what
             if (count($cids) > 1) {
                 $errorMessage = ts('Record duplicates multiple contacts');
                 $importRecordParams = array($statusFieldName => 'ERROR', "{$statusFieldName}Msg" => $errorMessage);
                 //combine error msg to avoid mismatch between error file columns.
开发者ID:kcristiano,项目名称:civicrm-core,代码行数:67,代码来源:Contact.php

示例6: postProcess


//.........这里部分代码省略.........
     $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);
             }
         }
     }
     $params['relationship_ids'] = $relationshipIds;
     // Refresh contact tabs which might have been affected
     $this->ajaxResponse['updateTabs'] = array('#tab_member' => CRM_Contact_BAO_Contact::getCountComponent('membership', $this->_contactId), '#tab_contribute' => CRM_Contact_BAO_Contact::getCountComponent('contribution', $this->_contactId));
     // Set current employee/employer relationship, CRM-3532
     if ($params['is_current_employer'] && $this->_allRelationshipNames[$params['relationship_type_id']]["name_a_b"] == 'Employee of') {
         $employerParams = array();
         foreach ($relationshipIds as $id) {
             // Fixme this is dumb why do we have to look this up again?
             $rel = CRM_Contact_BAO_Relationship::getRelationshipByID($id);
             $employerParams[$rel->contact_id_a] = $rel->contact_id_b;
         }
         // @todo this belongs in the BAO.
         CRM_Contact_BAO_Contact_Utils::setCurrentEmployer($employerParams);
         // Refresh contact summary if in ajax mode
         $this->ajaxResponse['reloadBlocks'] = array('#crm-contactinfo-content');
     }
 }
开发者ID:BorislavZlatanov,项目名称:civicrm-core,代码行数:101,代码来源:Relationship.php

示例7: 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());
     }
 }
开发者ID:TheCraftyCanvas,项目名称:aegir-platforms,代码行数:101,代码来源:Relationship.php

示例8: postProcess


//.........这里部分代码省略.........
     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
     if ($params['is_current_employer'] && $this->_allRelationshipNames[$relationshipTypeId]["name_a_b"] == 'Employee of') {
         $employerParams = array();
         foreach ($relationshipIds as $id) {
             // Fixme this is dumb why do we have to look this up again?
             $rel = CRM_Contact_BAO_Relationship::getContactIds($id);
             $employerParams[$rel->contact_id_a] = $rel->contact_id_b;
         }
         CRM_Contact_BAO_Contact_Utils::setCurrentEmployer($employerParams);
         // Refresh contact summary if in ajax mode
         $this->ajaxResponse['reloadBlocks'] = array('#crm-contactinfo-content');
     }
 }
开发者ID:prashantgajare,项目名称:civicrm-core,代码行数:101,代码来源:Relationship.php


注:本文中的CRM_Contact_BAO_Contact_Utils::setCurrentEmployer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。