From 7a5c0c6c3fcdecba1d746d2eed4b8ed65a428bb6 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 16 Dec 2015 15:25:08 -0500 Subject: [PATCH] CRM-17646 - Ensure user-facing case type options go through hook_fieldOptions --- CRM/Case/BAO/Query.php | 13 ++---------- CRM/Case/Form/Activity/ChangeCaseType.php | 6 ++---- CRM/Case/Form/Activity/OpenCase.php | 24 +++++++++++------------ CRM/Case/Form/Case.php | 15 ++++++-------- CRM/Logging/ReportSummary.php | 2 +- CRM/Report/Form/Case/Detail.php | 6 ++---- CRM/Report/Form/Case/Summary.php | 4 ++-- 7 files changed, 26 insertions(+), 44 deletions(-) diff --git a/CRM/Case/BAO/Query.php b/CRM/Case/BAO/Query.php index 64a592d27b..c13fc984a8 100644 --- a/CRM/Case/BAO/Query.php +++ b/CRM/Case/BAO/Query.php @@ -674,17 +674,8 @@ case_relation_type.id = case_relationship.relationship_type_id )"; $configured = CRM_Case_BAO_Case::isCaseConfigured(); $form->assign('notConfigured', !$configured['configured']); - $form->add('select', 'case_type_id', - ts('Case Type'), - CRM_Case_PseudoConstant::caseType('title', FALSE), - FALSE, array('class' => 'crm-select2', 'multiple' => 'multiple') - ); - - $form->add('select', 'case_status_id', - ts('Case Status'), - CRM_Case_PseudoConstant::caseStatus('label', FALSE), - FALSE, array('class' => 'crm-select2', 'multiple' => 'multiple') - ); + $form->addField('case_type_id', array('context' => 'search', 'entity' => 'Case')); + $form->addField('case_status_id', array('context' => 'search', 'entity' => 'Case')); CRM_Core_Form_Date::buildDateRange($form, 'case_from', 1, '_start_date_low', '_start_date_high', ts('From'), FALSE); CRM_Core_Form_Date::buildDateRange($form, 'case_to', 1, '_end_date_low', '_end_date_high', ts('From'), FALSE); diff --git a/CRM/Case/Form/Activity/ChangeCaseType.php b/CRM/Case/Form/Activity/ChangeCaseType.php index 1d617db5a6..2ad60558dd 100644 --- a/CRM/Case/Form/Activity/ChangeCaseType.php +++ b/CRM/Case/Form/Activity/ChangeCaseType.php @@ -76,7 +76,7 @@ class CRM_Case_Form_Activity_ChangeCaseType { $form->removeElement('priority_id'); $caseId = CRM_Utils_Array::first($form->_caseId); - $form->_caseType = CRM_Case_PseudoConstant::caseType(); + $form->_caseType = CRM_Case_BAO_Case::buildOptions('case_type_id', 'create'); $form->_caseTypeId = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case', $caseId, 'case_type_id' @@ -85,9 +85,7 @@ class CRM_Case_Form_Activity_ChangeCaseType { $form->_caseType[$form->_caseTypeId] = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseType', $form->_caseTypeId, 'title'); } - $form->add('select', 'case_type_id', ts('New Case Type'), - $form->_caseType, TRUE - ); + $form->addField('case_type_id', array('context' => 'create', 'entity' => 'Case')); // timeline $form->addYesNo('is_reset_timeline', ts('Reset Case Timeline?'), NULL, TRUE, array('onclick' => "return showHideByValue('is_reset_timeline','','resetTimeline','table-row','radio',false);")); diff --git a/CRM/Case/Form/Activity/OpenCase.php b/CRM/Case/Form/Activity/OpenCase.php index cd56766a80..1960c212b9 100644 --- a/CRM/Case/Form/Activity/OpenCase.php +++ b/CRM/Case/Form/Activity/OpenCase.php @@ -71,7 +71,7 @@ class CRM_Case_Form_Activity_OpenCase { // check if the case type id passed in url is a valid one $caseTypeId = CRM_Utils_Request::retrieve('ctype', 'Positive', $form); - $caseTypes = CRM_Case_PseudoConstant::caseType(); + $caseTypes = CRM_Case_BAO_Case::buildOptions('case_type_id', 'create'); $form->_caseTypeId = array_key_exists($caseTypeId, $caseTypes) ? $caseTypeId : NULL; // check if the case status id passed in url is a valid one @@ -150,21 +150,19 @@ class CRM_Case_Form_Activity_OpenCase { ), TRUE); } - $caseTypes = CRM_Case_PseudoConstant::caseType(); - $element = $form->add('select', - 'case_type_id', ts('Case Type'), $caseTypes, - TRUE, array('onchange' => "CRM.buildCustomData('Case', this.value);") - ); - + $element = $form->addField('case_type_id', array( + 'context' => 'create', + 'entity' => 'Case', + 'onchange' => "CRM.buildCustomData('Case', this.value);", + ), TRUE); if ($form->_caseTypeId) { $element->freeze(); } - $csElement = $form->add('select', 'status_id', ts('Case Status'), - CRM_Case_PseudoConstant::caseStatus(), - FALSE - ); - + $csElement = $form->addField('status_id', array( + 'context' => 'create', + 'entity' => 'Case', + ), TRUE); if ($form->_caseStatusId) { $csElement->freeze(); } @@ -179,7 +177,7 @@ class CRM_Case_Form_Activity_OpenCase { $form->addDate('start_date', ts('Case Start Date'), TRUE, array('formatType' => 'activityDateTime')); - $form->addSelect('medium_id', array('entity' => 'activity'), TRUE); + $form->addField('medium_id', array('entity' => 'activity', 'context' => 'create'), TRUE); // calling this field activity_location to prevent conflict with contact location fields $form->add('text', 'activity_location', ts('Location'), CRM_Core_DAO::getAttribute('CRM_Activity_DAO_Activity', 'location')); diff --git a/CRM/Case/Form/Case.php b/CRM/Case/Form/Case.php index 6d54dbae27..cb886e3028 100644 --- a/CRM/Case/Form/Case.php +++ b/CRM/Case/Form/Case.php @@ -111,17 +111,14 @@ class CRM_Case_Form_Case extends CRM_Core_Form { if (!$this->_caseId) { $caseAttributes = array( - 'case_type' => CRM_Case_PseudoConstant::caseType(), - 'case_status' => CRM_Case_PseudoConstant::caseStatus(), - 'encounter_medium' => CRM_Case_PseudoConstant::encounterMedium(), + 'case_type_id' => ts('Case Type'), + 'status_id' => ts('Case Status'), + 'medium_id' => ts('Activity Medium'), ); - foreach ($caseAttributes as $key => $values) { - if (empty($values)) { - CRM_Core_Error::fatal(ts('You do not have any active %1', - array(1 => str_replace('_', ' ', $key)) - )); - break; + foreach ($caseAttributes as $key => $label) { + if (!CRM_Case_BAO_Case::buildOptions($key, 'create')) { + CRM_Core_Error::fatal(ts('You do not have any active %1', array(1 => $label))); } } } diff --git a/CRM/Logging/ReportSummary.php b/CRM/Logging/ReportSummary.php index 431dfa692e..45c8759cc3 100644 --- a/CRM/Logging/ReportSummary.php +++ b/CRM/Logging/ReportSummary.php @@ -167,7 +167,7 @@ class CRM_Logging_ReportSummary extends CRM_Report_Form { ), 'bracket_info' => array( 'entity_column' => 'case_type_id', - 'options' => CRM_Case_PseudoConstant::caseType('title', FALSE), + 'options' => CRM_Case_BAO_Case::buildOptions('case_type_id', 'search'), ), ), ); diff --git a/CRM/Report/Form/Case/Detail.php b/CRM/Report/Form/Case/Detail.php index 1ba1742bce..3ae4c7597c 100644 --- a/CRM/Report/Form/Case/Detail.php +++ b/CRM/Report/Form/Case/Detail.php @@ -54,8 +54,6 @@ class CRM_Report_Form_Case_Detail extends CRM_Report_Form { protected $_customGroupExtends = array('Case'); - /** - */ /** */ public function __construct() { @@ -120,12 +118,12 @@ class CRM_Report_Form_Case_Detail extends CRM_Report_Form { 'status_id' => array( 'title' => ts('Case Status'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, - 'options' => $this->case_statuses, + 'options' => CRM_Case_BAO_Case::buildOptions('status_id', 'search'), ), 'case_type_id' => array( 'title' => ts('Case Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, - 'options' => $this->case_types, + 'options' => CRM_Case_BAO_Case::buildOptions('case_type_id', 'search'), ), 'is_deleted' => array( 'title' => ts('Deleted?'), diff --git a/CRM/Report/Form/Case/Summary.php b/CRM/Report/Form/Case/Summary.php index 2c7eb1fe9d..6d30e3ecdb 100644 --- a/CRM/Report/Form/Case/Summary.php +++ b/CRM/Report/Form/Case/Summary.php @@ -126,12 +126,12 @@ class CRM_Report_Form_Case_Summary extends CRM_Report_Form { 'case_type_id' => array( 'title' => ts('Case Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, - 'options' => $this->case_types, + 'options' => CRM_Case_BAO_Case::buildOptions('case_type_id', 'search'), ), 'status_id' => array( 'title' => ts('Status'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, - 'options' => $this->case_statuses, + 'options' => CRM_Case_BAO_Case::buildOptions('status_id', 'search'), ), 'is_deleted' => array( 'title' => ts('Deleted?'), -- 2.25.1