From 71331d2a9a196586103384aaf045debb6bd2ae3f Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 6 Mar 2014 21:36:17 -0500 Subject: [PATCH] Relationship form tweaks --- CRM/Contact/Form/Relationship.php | 34 +++++++++++++------------------ 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/CRM/Contact/Form/Relationship.php b/CRM/Contact/Form/Relationship.php index 6bbfd4575e..12e452ce1b 100644 --- a/CRM/Contact/Form/Relationship.php +++ b/CRM/Contact/Form/Relationship.php @@ -360,15 +360,15 @@ class CRM_Contact_Form_Relationship extends CRM_Core_Form { $contactField->freeze(); } - $this->add('checkbox', 'is_current_employer', $this->_contactType == 'Organization' ? ts('Current Employee') : ts('Current Employer')); + $this->add('advcheckbox', 'is_current_employer', $this->_contactType == 'Organization' ? ts('Current Employee') : ts('Current Employer')); $this->addDate('start_date', ts('Start Date'), FALSE, array('formatType' => 'searchDate')); $this->addDate('end_date', ts('End Date'), FALSE, array('formatType' => 'searchDate')); - $this->add('checkbox', 'is_active', ts('Enabled?')); + $this->add('advcheckbox', 'is_active', ts('Enabled?')); - $this->add('checkbox', 'is_permission_a_b'); - $this->add('checkbox', 'is_permission_b_a'); + $this->add('advcheckbox', 'is_permission_a_b'); + $this->add('advcheckbox', 'is_permission_b_a'); $this->add('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Relationship', 'description')); @@ -417,30 +417,24 @@ class CRM_Contact_Form_Relationship extends CRM_Core_Form { $ids = array('contact' => $this->_contactId); - // Boolean fields (checkboxes) are nonexistant when submitted if unchecked - cast them to boolean - // FIXME: Dear Quickform, this sucks. - $params['is_current_employer'] = !empty($params['is_current_employer']); - $params['is_active'] = !empty($params['is_active']); - $params['is_permission_a_b'] = !empty($params['is_permission_a_b']); - $params['is_permission_b_a'] = !empty($params['is_permission_b_a']); - - $relationshipTypeId = str_replace(array('_', 'a', 'b'), '', $params['relationship_type_id']); + + // 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 relationship type changes, relationship is disabled, or "current employer" is unchecked, - // clear the current employer. CRM-3235. - $isDisabled = !$params['is_active'] || !$params['is_current_employer']; - $relChanged = $relationshipTypeId != $this->_values['relationship_type_id']; - if ($this->_isCurrentEmployer && ($isDisabled || $relChanged)) { - CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($this->_values['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']); + } } - } - // Create mode - save 1 or more new relationships + // Create mode (could be 1 or more relationships) 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); -- 2.25.1