From 4de6aa4589269297c784840051a3e056347db48f Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 20 Jan 2017 23:06:55 -0500 Subject: [PATCH] CRM-19778 - Limit statuses in 'change case status' activity --- CRM/Case/Form/Activity/ChangeCaseStatus.php | 22 ++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/CRM/Case/Form/Activity/ChangeCaseStatus.php b/CRM/Case/Form/Activity/ChangeCaseStatus.php index c7955c27e6..9cf971ea7c 100644 --- a/CRM/Case/Form/Activity/ChangeCaseStatus.php +++ b/CRM/Case/Form/Activity/ChangeCaseStatus.php @@ -72,7 +72,26 @@ class CRM_Case_Form_Activity_ChangeCaseStatus { $form->removeElement('status_id'); $form->removeElement('priority_id'); + $caseTypes = array(); + $form->_caseStatus = CRM_Case_PseudoConstant::caseStatus(); + $statusNames = CRM_Case_PseudoConstant::caseStatus('name'); + + // Limit case statuses to allowed types for these case(s) + $allCases = civicrm_api3('Case', 'get', array('return' => 'case_type_id', 'id' => array('IN' => (array) $form->_caseId))); + foreach ($allCases['values'] as $case) { + $caseTypes[$case['case_type_id']] = $case['case_type_id']; + } + $caseTypes = civicrm_api3('CaseType', 'get', array('id' => array('IN' => $caseTypes))); + foreach ($caseTypes['values'] as $ct) { + if (!empty($ct['definition']['statuses'])) { + foreach ($form->_caseStatus as $id => $label) { + if (!in_array($statusNames[$id], $ct['definition']['statuses'])) { + unset($form->_caseStatus[$id]); + } + } + } + } foreach ($form->_caseId as $key => $val) { $form->_oldCaseStatus[] = $form->_defaultCaseStatus[] = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case', $val, 'status_id'); @@ -183,9 +202,6 @@ class CRM_Case_Form_Activity_ChangeCaseStatus { $activity->save(); } } - - // FIXME: does this do anything ? - $params['statusMsg'] = ts('Case Status changed successfully.'); } } -- 2.25.1