From fad0497c6cd4d50de069403018947b667b37fb36 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 5 Mar 2014 11:23:42 -0500 Subject: [PATCH] CurrentEmployer cleanup --- CRM/Contact/BAO/Contact.php | 18 +++-------- CRM/Contact/BAO/Contact/Utils.php | 40 ++----------------------- CRM/Contact/Form/Contact.php | 5 ---- CRM/Contact/Form/Inline/ContactInfo.php | 12 +------- 4 files changed, 7 insertions(+), 68 deletions(-) diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index 90fefe0c9e..a253462abd 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -223,21 +223,11 @@ class CRM_Contact_BAO_Contact extends CRM_Contact_DAO_Contact { ); } - if ($contact->contact_type == 'Individual' && - (isset($params['current_employer']) || - isset($params['employer_id']) - ) - ) { + if ($contact->contact_type == 'Individual' && (isset($params['current_employer']) || isset($params['employer_id']))) { + $newEmployer = !empty($params['employer_id']) ? $params['employer_id'] : CRM_Utils_Array::value('current_employer', $params); // create current employer - if (isset($params['employer_id'])) { - CRM_Contact_BAO_Contact_Utils::createCurrentEmployerRelationship($contact->id, - $params['employer_id'], $employerId - ); - } - elseif ($params['current_employer']) { - CRM_Contact_BAO_Contact_Utils::createCurrentEmployerRelationship($contact->id, - $params['current_employer'] - ); + if ($newEmployer) { + CRM_Contact_BAO_Contact_Utils::createCurrentEmployerRelationship($contact->id, $newEmployer, $employerId); } else { //unset if employer id exits diff --git a/CRM/Contact/BAO/Contact/Utils.php b/CRM/Contact/BAO/Contact/Utils.php index 6169b97212..3648974ebe 100644 --- a/CRM/Contact/BAO/Contact/Utils.php +++ b/CRM/Contact/BAO/Contact/Utils.php @@ -259,44 +259,8 @@ UNION * @access public * @static */ - static function createCurrentEmployerRelationship($contactID, $organization, $previousEmployerID = NULL) { - $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]; - - $dedupeParams = CRM_Dedupe_Finder::formatParams($organizationParams, 'Organization'); - - $dedupeParams['check_permission'] = FALSE; - $dupeIDs = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Organization', 'Supervised'); - - 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::create($newOrg); - $organizationId = $org->id; - } - } - - if ($organizationId) { + static function createCurrentEmployerRelationship($contactID, $organizationId, $previousEmployerID = NULL) { + if ($organizationId && is_numeric($organizationId)) { $cid = array('contact' => $contactID); // get the relationship type id of "Employee of" diff --git a/CRM/Contact/Form/Contact.php b/CRM/Contact/Form/Contact.php index 3af21b4c87..f60dbb4915 100644 --- a/CRM/Contact/Form/Contact.php +++ b/CRM/Contact/Form/Contact.php @@ -411,9 +411,6 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form { } } else { - $currentEmployer = CRM_Contact_BAO_Relationship::getCurrentEmployer(array($this->_contactId)); - $defaults['current_employer_id'] = CRM_Utils_Array::value('org_id', $currentEmployer[$this->_contactId]); - foreach ($defaults['email'] as $dontCare => & $val) { if (isset($val['signature_text'])) { $val['signature_text_hidden'] = $val['signature_text']; @@ -427,8 +424,6 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form { $defaults['contact_sub_type'] = $this->_oldSubtypes; } } - $this->assign('currentEmployer', CRM_Utils_Array::value('current_employer_id', $defaults)); - // set defaults for blocks ( custom data, address, communication preference, notes, tags and groups ) foreach ($this->_editOptions as $name => $label) { if (!in_array($name, array('Address', 'Notes'))) { diff --git a/CRM/Contact/Form/Inline/ContactInfo.php b/CRM/Contact/Form/Inline/ContactInfo.php index 2fff7bc931..7f954afc7a 100644 --- a/CRM/Contact/Form/Inline/ContactInfo.php +++ b/CRM/Contact/Form/Inline/ContactInfo.php @@ -59,17 +59,7 @@ class CRM_Contact_Form_Inline_ContactInfo extends CRM_Contact_Form_Inline { * @access public */ public function setDefaultValues() { - $defaults = parent::setDefaultValues(); - - if ($this->_contactType == 'Individual') { - // set current employer details - $currentEmployer = CRM_Contact_BAO_Relationship::getCurrentEmployer(array($this->_contactId)); - $defaults['current_employer_id'] = CRM_Utils_Array::value('org_id', $currentEmployer[$this->_contactId]); - - $this->assign('currentEmployer', CRM_Utils_Array::value('current_employer_id', $defaults)); - } - - return $defaults; + return parent::setDefaultValues(); } /** -- 2.25.1