Merge remote-tracking branch 'upstream/4.3' into 4.3-master-2013-08-28-20-20-34
authorkurund <kurund@civicrm.org>
Wed, 28 Aug 2013 14:56:49 +0000 (20:26 +0530)
committerkurund <kurund@civicrm.org>
Wed, 28 Aug 2013 14:56:49 +0000 (20:26 +0530)
Conflicts:
sql/civicrm_generated.mysql
tests/phpunit/WebTest/Contact/RelationshipAddTest.php

CRM/Contact/BAO/Relationship.php
CRM/Contact/Page/View/Relationship.php
CRM/Contact/Selector.php
CRM/Core/PseudoConstant.php
sql/GenerateData.php
templates/CRM/Contact/Form/Relationship.tpl
tests/phpunit/WebTest/Contact/RelationshipAddTest.php

index d2d839c1821c0d07875979f1df812268f91c066d..a560b786bde177ab2667ec6cae346bc9b9b80f49 100644 (file)
@@ -432,16 +432,18 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
     //to delete relationship between household and individual                                                                                          \
     //or between individual and orgnization
     if (($action & CRM_Core_Action::DISABLE) || ($action & CRM_Core_Action::DELETE)) {
-    if ($relationship->relationship_type_id == 4 || $relationship->relationship_type_id == 7) {
-      $sharedContact = new CRM_Contact_DAO_Contact();
-      $sharedContact->id = $relationship->contact_id_a;
-      $sharedContact->find(TRUE);
-
-        if ($relationship->relationship_type_id == 4 && $relationship->contact_id_b == $sharedContact->employer_id) {
-        CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($relationship->contact_id_a);
+      $relTypes = CRM_Utils_Array::index(array('name_a_b'), CRM_Core_PseudoConstant::relationshipType('name'));
+      if ($relationship->relationship_type_id == $relTypes['Employee of']['id'] ||
+          $relationship->relationship_type_id == $relTypes['Household Member of']['id']) {
+        $sharedContact = new CRM_Contact_DAO_Contact();
+        $sharedContact->id = $relationship->contact_id_a;
+        $sharedContact->find(TRUE);
+
+          if ($relationship->relationship_type_id == 4 && $relationship->contact_id_b == $sharedContact->employer_id) {
+          CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($relationship->contact_id_a);
+        }
       }
     }
-    }
     return  $relationship;
   }
 
index e6444729c3d4a3d93e030af0bf2204b16037773e..06d5d99ee5878e9aaf3e6cfa8c3863e266e70442 100644 (file)
@@ -77,10 +77,13 @@ class CRM_Contact_Page_View_Relationship extends CRM_Core_Page {
 
     $employerId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'employer_id');
     $this->assign('isCurrentEmployer', FALSE);
+
+    $relTypes = CRM_Utils_Array::index(array('name_a_b'), CRM_Core_PseudoConstant::relationshipType('name'));
+    
     if ($viewRelationship[$this->_id]['employer_id'] == $this->_contactId) {
       $this->assign('isCurrentEmployer', TRUE);
     }
-    elseif ($relType == 4 &&
+    elseif ($relType == $relTypes['Employee of']['id'] &&
       ($viewRelationship[$this->_id]['cid'] == $employerId)
     ) {
       // make sure we are viewing employee of relationship
index c8776ef9f181a65bd4f758590e51aa66320dc9b5..4d465137a19de9742e491bd740b3f01165516f85 100644 (file)
@@ -918,7 +918,6 @@ SELECT 'civicrm_contact', contact_a.id, contact_a.id, '$cacheKey', contact_a.dis
 
     $sql = str_replace($replaceSQL, $insertSQL, $sql);
 
-
     CRM_Core_Error::ignoreException();
     $result = CRM_Core_DAO::executeQuery($sql);
     CRM_Core_Error::setCallback();
index 3082f4a017736b8bb9401ab7323a9e27a548274d..c53b37409b92cfa460e4f3b2fedabe7a09c169c5 100644 (file)
@@ -1043,6 +1043,7 @@ WHERE  id = %1";
       while ($relationshipTypeDAO->fetch()) {
 
         self::$relationshipType[$valueColumnName][$relationshipTypeDAO->id] = array(
+          'id' => $relationshipTypeDAO->id,
           $column_a_b => $relationshipTypeDAO->$column_a_b,
           $column_b_a => $relationshipTypeDAO->$column_b_a,
           'contact_type_a' => "$relationshipTypeDAO->contact_type_a",
index 984882a406e1b85f8d42b51d3b75933a4c567aba..071ed835634831065883c2fb28dded2e2e1b54da 100644 (file)
@@ -111,14 +111,6 @@ class CRM_GCD {
   CONST NUM_INDIVIDUAL_PER_HOUSEHOLD = 4;
   CONST NUM_ACTIVITY = 150;
 
-  // Relationship types from the table crm_relationship_type
-  CONST CHILD_OF = 1;
-  CONST SPOUSE_OF = 2;
-  CONST SIBLING_OF = 3;
-  CONST EMPLOYEE_OF = 4;
-  CONST HEAD_OF_HOUSEHOLD = 6;
-  CONST MEMBER_OF_HOUSEHOLD = 7;
-
   // Location types from the table crm_location_type
   CONST HOME = 1;
   CONST WORK = 2;
@@ -142,6 +134,10 @@ class CRM_GCD {
     }
     // Init DB
     $config = CRM_Core_Config::singleton();
+    
+    // Relationship types indexed by name_a_b from the table civicrm_relationship_type
+    $this->relTypes = CRM_Utils_Array::index(array('name_a_b'), CRM_Core_PseudoConstant::relationshipType('name'));
+    
   }
 
   /**
@@ -750,7 +746,7 @@ class CRM_GCD {
       $relationship->is_active = 1;
 
       // add child_of relationship for each child
-      $relationship->relationship_type_id = self::CHILD_OF;
+      $relationship->relationship_type_id = $this->relTypes['Child of']['id'];
       foreach (array(0, 1) as $parent) {
         foreach (array(2, 3) as $child) {
           $relationship->contact_id_a = $household_member[$child];
@@ -760,13 +756,13 @@ class CRM_GCD {
       }
 
       // add sibling_of relationship
-      $relationship->relationship_type_id = self::SIBLING_OF;
+      $relationship->relationship_type_id = $this->relTypes['Sibling of']['id'];
       $relationship->contact_id_a = $household_member[3];
       $relationship->contact_id_b = $household_member[2];
       $this->_insert($relationship);
 
       // add member_of_household relationships and shared address
-      $relationship->relationship_type_id = self::MEMBER_OF_HOUSEHOLD;
+      $relationship->relationship_type_id = $this->relTypes['Household Member of']['id'];
       $relationship->contact_id_b = $household_id;
       for ($i = 1; $i < 4; ++$i) {
         $relationship->contact_id_a = $household_member[$i];
@@ -784,13 +780,13 @@ class CRM_GCD {
       }
 
       // add head_of_household relationship 1 for head of house
-      $relationship->relationship_type_id = self::HEAD_OF_HOUSEHOLD;
+      $relationship->relationship_type_id = $this->relTypes['Head of Household for']['id'];
       $relationship->contact_id_a = $household_member[0];
       $relationship->contact_id_b = $household_id;
       $this->_insert($relationship);
 
       // add spouse_of relationship 1 for both the spouses
-      $relationship->relationship_type_id = self::SPOUSE_OF;
+      $relationship->relationship_type_id = $this->relTypes['Spouse of']['id'];
       $relationship->contact_id_a = $household_member[1];
       $relationship->contact_id_b = $household_member[0];
       $this->_insert($relationship);
@@ -799,7 +795,7 @@ class CRM_GCD {
     // Add current employer relationships
     $this->_query("INSERT INTO civicrm_relationship
       (contact_id_a, contact_id_b, relationship_type_id, is_active)
-      (SELECT id, employer_id, " . self::EMPLOYEE_OF . ", 1 FROM civicrm_contact WHERE employer_id IN (" . implode(',', $this->Organization) . "))"
+      (SELECT id, employer_id, " . $this->relTypes['Employee of']['id'] . ", 1 FROM civicrm_contact WHERE employer_id IN (" . implode(',', $this->Organization) . "))"
     );
   }
 
index 47be4f3194a914fbe6d992f6b6a4001f2fdccfcf..40295ddcc5b51fc8fb5b34aabc7720aeecea4fb2 100644 (file)
@@ -77,6 +77,8 @@
   {/if}
 
   {if $action eq 2 | $action eq 1} {* add and update actions *}
+               {* Retrieve the ID for the Employee / Employer relationship type *}
+               {crmAPI var="employmentRelationship" entity="RelationshipType" action="getvalue" version="3" name_a_b="Employee of" return="id"}
     <h3>{if $action eq 1}{ts}New Relationship{/ts}{else}{ts}Edit Relationship{/ts}{/if}</h3>
     <div class="crm-block crm-form-block crm-relationship-form-block">
             {if $action eq 1}
@@ -552,7 +554,7 @@ function buildRelationFields( relType ) {
     {/literal} {if $action EQ 1} {literal}
     if ( relType ) {
         var relTypeId = relType.split("_");
-        if ( relTypeId[0] == 4 ) {
+        if ( relTypeId[0] == {/literal}{$employmentRelationship}{literal} ) {
             if ( relTypeId[1] == 'a' ) {
                 cj('#addCurrentEmployee').show();
                 cj('#addCurrentEmployer').hide();
@@ -611,11 +613,11 @@ function changeCustomData( cType ) {
    function currentEmployer( )
    {
       var relType = document.getElementById('relationship_type_id').value;
-      if ( relType == '4_a_b' ) {
+      if ( relType == "{/literal}{$employmentRelationship}{literal}" + "_a_b" ) {
            cj('#current_employer').show();
            cj('#employee').show();
            cj('#employer').hide();
-      } else if ( relType == '4_b_a' ) {
+      } else if ( relType == "{/literal}{$employmentRelationship}{literal}" + "_b_a" ) {
      cj('#current_employer').show();
            cj('#employer').show();
            cj('#employee').hide();
index d8f29c6ca896e641447dd8a3b9f151f8adf9aaa2..a1b3e1376f4bf808ea4401b8281942b0346f4db4 100644 (file)
@@ -370,4 +370,65 @@ class WebTest_Contact_RelationshipAddTest extends CiviSeleniumTestCase {
     $pageUrl = array('url' => 'contact/view/rel', 'args' => "cid={$contactId[1]}&action=add&reset=1");
     $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl);
   }
+  
+  function testRelationshipAddCurrentEmployerTest() {
+    $this->webtestLogin();
+
+    //create a New Individual
+    $firstName = substr(sha1(rand()), 0, 7);
+    $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name");
+
+    // visit relationship tab of the Individual
+    $this->click("css=li#tab_rel a");
+
+    // wait for add Relationship link
+    $this->waitForElementPresent('link=Add Relationship');
+    $this->click('link=Add Relationship');
+
+    //choose the created relationship type
+    $this->waitForElementPresent("relationship_type_id");
+    $this->select('relationship_type_id', "label=Employee of");
+
+    // Because it tends to cause problems, all uses of sleep() must be justified in comments
+    // Sleep should never be used for wait for anything to load from the server
+    // Justification for this instance: wait until new contact dialog select is built
+    sleep(2);
+
+    // create a new organization
+    $orgName = 'WestsideCoop' . substr(sha1(rand()), 0, 7);
+    $this->webtestNewDialogContact($orgName, "", "info@" . $orgName . ".com", 5);
+
+    $this->waitForElementPresent("quick-save");
+
+    //fill in the relationship start date
+    $this->webtestFillDate('start_date', '-2 year');
+    $this->webtestFillDate('end_date', '+1 year');
+
+    $description = "Current employee test.";
+    $this->type("description", $description);
+
+    $this->waitForElementPresent("add_current_employee");
+    $this->click("add_current_employee");
+
+    //save the relationship
+    //$this->click("_qf_Relationship_upload");
+    $this->click("quick-save");
+    $this->waitForElementPresent("current-relationships");
+
+    //check the status message
+    $this->assertTrue($this->isTextPresent("New relationship created."));
+
+    $this->waitForElementPresent("xpath=//div[@id='current-relationships']//div//table/tbody//tr/td[9]/span/a[text()='View']");
+    $this->click("xpath=//div[@id='current-relationships']//div//table/tbody//tr/td[9]/span/a[text()='View']");
+
+    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->webtestVerifyTabularData(
+      array(
+        'Description' => $description,
+        'Current Employee?' => 'Yes',
+        'Status' => 'Enabled',
+      )
+    );
+    $this->assertTrue($this->isTextPresent("Employee of"),"Employee of relationship type not visible on View Relationship page.");
+  }
 }