diff --git a/CRM/Activity/Page/AJAX.php b/CRM/Activity/Page/AJAX.php index 787c18d26d14..700069b61812 100644 --- a/CRM/Activity/Page/AJAX.php +++ b/CRM/Activity/Page/AJAX.php @@ -150,7 +150,7 @@ public static function getCaseRoles() { $params = CRM_Core_Page_AJAX::defaultSortAndPagerParams(); - $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($contactID, $caseID); + $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($contactID, $caseID, NULL, FALSE); $caseTypeName = CRM_Case_BAO_Case::getCaseType($caseID, 'name'); $xmlProcessor = new CRM_Case_XMLProcessor_Process(); $caseRoles = $xmlProcessor->get($caseTypeName, 'CaseRoles'); @@ -179,6 +179,8 @@ public static function getCaseRoles() { $rel['name'] = '(not assigned)'; $rel['phone'] = ''; $rel['email'] = ''; + $rel['is_active'] = ''; + $rel['end_date'] = ''; $rel['source'] = 'caseRoles'; $caseRelationships[] = $rel; } @@ -198,15 +200,25 @@ public static function getCaseRoles() { // sort clientRelationships array using jquery call params foreach ($caseRelationships as $key => $row) { - $sortArray[$key] = $row[$params['_raw_values']['sort'][0]]; + if (isset($row[$params['_raw_values']['sort'][0]])) { + $sortArray[$key] = $row[$params['_raw_values']['sort'][0]]; // FIXME: this line is throwing php notices (undefined index). I added an isset above and while it throws less erros - they are still present. + } + } + if (!empty($row[$params['_raw_values']['sort'][0]])) { + $sort_type = "SORT_" . strtoupper($params['_raw_values']['order'][0]); + array_multisort($sortArray, constant($sort_type), $caseRelationships); // FIXME: this line is throwing php notices (undefined index). I added an isset above and while it throws less erros - they are still present. } - $sort_type = "SORT_" . strtoupper($params['_raw_values']['order'][0]); - array_multisort($sortArray, constant($sort_type), $caseRelationships); $relationships = array(); // set user name, email and edit columns links foreach ($caseRelationships as $key => &$row) { + // add disabled class if role is inactive + if (isset($row['is_active'])) { + if ($row['is_active'] == '0') { + $row['DT_RowClass'] = 'disabled'; + } + } $typeLabel = $row['relation']; // Add "
(Case Manager)" to label if (!empty($row['relation_type']) && $row['relation_type'] == $managerRoleId) { @@ -221,6 +233,13 @@ public static function getCaseRoles() { if ($row['email']) { $row['email'] = ''; } + // view end date if set + if (!empty($row['end_date'])) { + $row['end_date'] = date("F d, Y", strtotime($row['end_date'])); + } + else { + $row['end_date'] = ''; + } // edit links $row['actions'] = ''; if ($hasAccessToAllCases) { @@ -228,12 +247,14 @@ public static function getCaseRoles() { $contactType = $contactType == 'Contact' ? '' : $contactType; switch ($row['source']) { case 'caseRel': - $row['actions'] = '' . - '' . - '' . - '' . - '' . - ''; + if (empty($row['end_date'])) { + $row['actions'] = '' . + '' . + '' . + '' . + '' . + ''; + } break; case 'caseRoles': diff --git a/CRM/Case/BAO/Case.php b/CRM/Case/BAO/Case.php index 06102fe28a38..0adae6d20a77 100644 --- a/CRM/Case/BAO/Case.php +++ b/CRM/Case/BAO/Case.php @@ -856,6 +856,8 @@ public static function getCaseRoles($contactID, $caseID, $relationshipID = NULL, civicrm_email.email as email, civicrm_phone.phone as phone, con.id as civicrm_contact_id, + rel.is_active as is_active, + rel.end_date as end_date, IF(rel.contact_id_a = %1, civicrm_relationship_type.label_a_b, civicrm_relationship_type.label_b_a) as relation, civicrm_relationship_type.id as relation_type, IF(rel.contact_id_a = %1, "a_b", "b_a") as relationship_direction @@ -890,6 +892,8 @@ public static function getCaseRoles($contactID, $caseID, $relationshipID = NULL, $values[$rid]['name'] = $dao->sort_name; $values[$rid]['email'] = $dao->email; $values[$rid]['phone'] = $dao->phone; + $values[$rid]['is_active'] = $dao->is_active; + $values[$rid]['end_date'] = $dao->end_date; $values[$rid]['relation_type'] = $dao->relation_type; $values[$rid]['rel_id'] = $dao->civicrm_relationship_id; $values[$rid]['client_id'] = $contactID; @@ -1919,7 +1923,7 @@ public static function getCaseManagerContact($caseType, $caseId) { FROM civicrm_contact LEFT JOIN civicrm_relationship ON (civicrm_relationship.contact_id_b = civicrm_contact.id AND civicrm_relationship.relationship_type_id = %1) AND civicrm_relationship.is_active LEFT JOIN civicrm_case ON civicrm_case.id = civicrm_relationship.case_id - WHERE civicrm_case.id = %2 AND is_active = 1"; + WHERE civicrm_case.id = %2"; $managerRoleParams = array( 1 => array($managerRoleId, 'Integer'), @@ -1927,10 +1931,28 @@ public static function getCaseManagerContact($caseType, $caseId) { ); $dao = CRM_Core_DAO::executeQuery($managerRoleQuery, $managerRoleParams); - if ($dao->fetch()) { + // Pull an array of ALL case managers related to the case. + $caseManagerNameArray = array(); + while ($dao->fetch()) { + $caseManagerNameArray[$dao->casemanager_id]['casemanager_id'] = $dao->casemanager_id; + $caseManagerNameArray[$dao->casemanager_id]['is_active'] = $dao->is_active; + $caseManagerNameArray[$dao->casemanager_id]['end_date'] = $dao->end_date; + $caseManagerNameArray[$dao->casemanager_id]['casemanager'] = $dao->casemanager; + } + $dao->free(); + // Look for an active case manager, when no active case manager (like a closed case) show the most recently expired case manager. + // Get the index of the manager if set to active + $activekey = array_search(1, array_combine(array_keys($caseManagerNameArray), array_column($caseManagerNameArray, 'is_active'))); + if (!empty ($activekey)) { + $caseManagerName = sprintf('%s', + CRM_Utils_System::url('civicrm/contact/view', array('cid' => $activekey)), $caseManagerNameArray[$activekey]['casemanager'] + ); + } + else { + // if there is no active case manager, get the index of the most recent end_date + $max = array_search(max(array_combine(array_keys($caseManagerNameArray), array_column($caseManagerNameArray, 'end_date'))), array_combine(array_keys($caseManagerNameArray), array_column($caseManagerNameArray, 'end_date'))); $caseManagerName = sprintf('%s', - CRM_Utils_System::url('civicrm/contact/view', array('cid' => $dao->casemanager_id)), - $dao->casemanager + CRM_Utils_System::url('civicrm/contact/view', array('cid' => $max)), $caseManagerNameArray[$max]['casemanager'] ); } } diff --git a/CRM/Case/Form/CaseView.php b/CRM/Case/Form/CaseView.php index cd386d276bac..ece664719ff9 100644 --- a/CRM/Case/Form/CaseView.php +++ b/CRM/Case/Form/CaseView.php @@ -94,13 +94,20 @@ public function preProcess() { $statuses = CRM_Case_PseudoConstant::caseStatus('label', FALSE); $caseTypeName = CRM_Case_BAO_Case::getCaseType($this->_caseID, 'name'); $caseType = CRM_Case_BAO_Case::getCaseType($this->_caseID); + $statusClass = civicrm_api3('OptionValue', 'getsingle', [ + 'option_group_id' => "case_status", + 'value' => $values['case_status_id'], + 'return' => 'grouping', + ]); $this->_caseDetails = array( 'case_type' => $caseType, 'case_status' => CRM_Utils_Array::value($values['case_status_id'], $statuses), 'case_subject' => CRM_Utils_Array::value('subject', $values), 'case_start_date' => $values['case_start_date'], + 'status_class' => $statusClass['grouping'], ); + $this->_caseType = $caseTypeName; $this->assign('caseDetails', $this->_caseDetails); @@ -460,7 +467,7 @@ public function postProcess() { * To include acivities related to current case id $form->_caseID. */ public static function activityForm($form, $aTypes = array()) { - $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($form->_contactID, $form->_caseID); + $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($form->_contactID, $form->_caseID, NULL, FALSE); //build reporter select $reporters = array("" => ts(' - any reporter - ')); foreach ($caseRelationships as $key => & $value) { diff --git a/templates/CRM/Case/Form/CaseView.tpl b/templates/CRM/Case/Form/CaseView.tpl index f0f975cce1d9..4ae0abab78ef 100644 --- a/templates/CRM/Case/Form/CaseView.tpl +++ b/templates/CRM/Case/Form/CaseView.tpl @@ -167,6 +167,24 @@
+
+ {assign var=check value='Show inactive relationships'} + {if $caseDetails.status_class eq 'Opened'}{assign var=statusclass value='1'}{else}{assign var=statusclass value='0'}{/if} + {html_checkboxes name='inactive' options=$check selected=$statusclass} +
+ {literal} + + {/literal} @@ -174,6 +192,7 @@ + {if $relId neq 'client' and $hasAccessToAllCases} {/if} @@ -184,9 +203,19 @@
{ts}Name{/ts} {ts}Phone{/ts} {ts}Email{/ts}{ts}End Date{/ts}{ts}Actions{/ts}