CurrentEmployer cleanup
authorColeman Watts <coleman@civicrm.org>
Wed, 5 Mar 2014 16:23:42 +0000 (11:23 -0500)
committerColeman Watts <coleman@civicrm.org>
Wed, 5 Mar 2014 16:28:12 +0000 (11:28 -0500)
CRM/Contact/BAO/Contact.php
CRM/Contact/BAO/Contact/Utils.php
CRM/Contact/Form/Contact.php
CRM/Contact/Form/Inline/ContactInfo.php

index 90fefe0c9eb96b5f7a73b8764a8015863fbceab0..a253462abd86685f76287991f38f630e3909743d 100644 (file)
@@ -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
index 6169b972123a9a5a73714dc363e797d49e8dc329..3648974ebed70929660020287c45ab3361db02d4 100644 (file)
@@ -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"
index 3af21b4c87573d42a3304a010ab44c6781c13fcc..f60dbb4915a87f9fcda69f690c7751d85dce5294 100644 (file)
@@ -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'))) {
index 2fff7bc931d298e17f1e3ee43bdea7dfcece41c6..7f954afc7a22c7b87156a7dd3f6118c754525201 100644 (file)
@@ -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();
   }
 
   /**