CRM-19778 - Limit statuses in 'change case status' activity
authorColeman Watts <coleman@civicrm.org>
Sat, 21 Jan 2017 04:06:55 +0000 (23:06 -0500)
committerColeman Watts <coleman@civicrm.org>
Tue, 24 Jan 2017 15:52:08 +0000 (10:52 -0500)
CRM/Case/Form/Activity/ChangeCaseStatus.php

index c7955c27e6e1f22cdbf712e850574bce6b62a8b6..9cf971ea7cc80f99e8426b1a8a09d0d1040a7e73 100644 (file)
@@ -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.');
   }
 
 }