//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;
}
$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
$sql = str_replace($replaceSQL, $insertSQL, $sql);
-
CRM_Core_Error::ignoreException();
$result = CRM_Core_DAO::executeQuery($sql);
CRM_Core_Error::setCallback();
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",
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;
}
// 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'));
+
}
/**
$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];
}
// 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];
}
// 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);
// 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) . "))"
);
}
{/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}
{/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();
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();
$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.");
+ }
}