From 1b2dc6a64b3bd9f43806c8b5c14c59f6eb272635 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sat, 15 Feb 2014 15:48:24 -0800 Subject: [PATCH] CRM-13929 Refactor case form --- CRM/Case/Form/Activity/OpenCase.php | 62 +++++++++-------------------- templates/CRM/Case/Form/Case.tpl | 5 ++- xml/configuration/Settings.xml | 4 +- xml/schema/Case/Case.xml | 4 +- 4 files changed, 26 insertions(+), 49 deletions(-) diff --git a/CRM/Case/Form/Activity/OpenCase.php b/CRM/Case/Form/Activity/OpenCase.php index aab99ce3d0..b13f3ff88d 100644 --- a/CRM/Case/Form/Activity/OpenCase.php +++ b/CRM/Case/Form/Activity/OpenCase.php @@ -50,7 +50,7 @@ class CRM_Case_Form_Activity_OpenCase { static function preProcess(&$form) { //get multi client case configuration $xmlProcessorProcess = new CRM_Case_XMLProcessor_Process(); - $form->_allowMultiClient = (bool)$xmlProcessorProcess->getAllowMultipleCaseClients(); + $form->_allowMultiClient = (bool) $xmlProcessorProcess->getAllowMultipleCaseClients(); if ($form->_context == 'caseActivity') { $contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $form); @@ -131,32 +131,30 @@ class CRM_Case_Form_Activity_OpenCase { return $defaults; } + /** + * @param CRM_Case_Form_Case $form + */ static function buildQuickForm(&$form) { if ($form->_context == 'caseActivity') { return; } if ($form->_context == 'standalone') { - CRM_Contact_Form_NewContact::buildQuickForm($form); + $form->addEntityRef('client_id', ts('Client'), array('create' => TRUE, 'multiple' => $form->_allowMultiClient), TRUE); } - $caseType = array('' => '-select-') + CRM_Case_PseudoConstant::caseType(); - $element = $form->add('select', 'case_type_id', ts('Case Type'), - $caseType, TRUE, array( - 'onchange' => - "CRM.buildCustomData( 'Case', this.value );", - ) + $element = $form->addSelect( + 'case_type_id', + array('onchange' => "CRM.buildCustomData('Case', this.value);"), + TRUE ); if ($form->_caseTypeId) { $element->freeze(); } - $caseStatus = CRM_Case_PseudoConstant::caseStatus(); - $form->add('select', 'status_id', ts('Case Status'), - $caseStatus, TRUE - ); + $form->addSelect('status_id', array(), TRUE); - $form->add('text', 'duration', ts('Duration'), array('size' => 4, 'maxlength' => 8)); + $form->add('text', 'duration', ts('Activity Duration'), array('size' => 4, 'maxlength' => 8)); $form->addRule('duration', ts('Please enter the duration as number of minutes (integers only).'), 'positiveInteger'); if ($form->_currentlyViewedContactId) { @@ -166,9 +164,7 @@ class CRM_Case_Form_Activity_OpenCase { $form->addDate('start_date', ts('Case Start Date'), TRUE, array('formatType' => 'activityDateTime')); - $form->add('select', 'medium_id', ts('Medium'), - CRM_Case_PseudoConstant::encounterMedium(), TRUE - ); + $form->addSelect('medium_id', array('entity' => 'activity'), 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')); @@ -206,14 +202,9 @@ class CRM_Case_Form_Activity_OpenCase { return; } - // set the contact, when contact is selected - if (isset($params['contact_select_id']) && !empty($params['contact_select_id'][1])) { - $params['contact_id'] = $params['contact_select_id'][1]; - $form->_currentlyViewedContactId = $params['contact_id']; - } - elseif ($form->_allowMultiClient && $form->_context != 'case') { - $clients = explode(',', $params['contact'][1]); - $form->_currentlyViewedContactId = $clients[0]; + if ($form->_context == 'standalone') { + $params['client_id'] = explode(',', $params['client_id']); + $form->_currentlyViewedContactId = $params['client_id'][0]; } // for open case start date should be set to current date @@ -252,19 +243,6 @@ class CRM_Case_Form_Activity_OpenCase { } $errors = array(); - - if (!$form->_allowMultiClient) { - //check if contact is selected in standalone mode - if (isset($fields['contact_select_id'][1]) && !$fields['contact_select_id'][1]) { - $errors['contact[1]'] = ts('Please select a contact or create new contact'); - } - } - else { - //check selected contact for multi client option - if (isset($fields['contact'][1]) && !$fields['contact'][1]) { - $errors['contact[1]'] = ts('Please select a valid contact or create new contact'); - } - } return $errors; } @@ -295,11 +273,10 @@ class CRM_Case_Form_Activity_OpenCase { } // 1. create case-contact - if ($isMultiClient && $form->_context != 'case') { - $client = explode(',', $params['contact'][1]); - foreach ($client as $key => $cliId) { + if ($isMultiClient && $form->_context == 'standalone') { + foreach ($params['client_id'] as $cliId) { if (empty($cliId)) { - CRM_Core_Error::fatal('contact_id cannot be empty'); + CRM_Core_Error::fatal('client_id cannot be empty'); } $contactParams = array( 'case_id' => $params['case_id'], @@ -314,14 +291,13 @@ class CRM_Case_Form_Activity_OpenCase { 'contact_id' => $form->_currentlyViewedContactId, ); CRM_Case_BAO_Case::addCaseToContact($contactParams); - $client = $form->_currentlyViewedContactId; } // 2. initiate xml processor $xmlProcessor = new CRM_Case_XMLProcessor_Process(); $xmlProcessorParams = array( - 'clientID' => $client, + 'clientID' => $form->_currentlyViewedContactId, 'creatorID' => $form->_currentUserId, 'standardTimeline' => 1, 'activityTypeName' => 'Open Case', diff --git a/templates/CRM/Case/Form/Case.tpl b/templates/CRM/Case/Form/Case.tpl index 90864961ca..4fc581a95e 100644 --- a/templates/CRM/Case/Form/Case.tpl +++ b/templates/CRM/Case/Form/Case.tpl @@ -61,7 +61,8 @@ {elseif !$clientName and $action eq 1} {if $context eq 'standalone'} - {include file="CRM/Contact/Form/NewContact.tpl"} + {$form.client_id.label} + {$form.client_id.html} {/if} {/if} {* activity fields *} @@ -103,7 +104,7 @@ {$form.duration.label} {$form.duration.html} - {ts}Total time spent on this activity (in minutes).{/ts} + {ts}minutes{/ts} {/if} diff --git a/xml/configuration/Settings.xml b/xml/configuration/Settings.xml index 84c1398ff4..8006e9d071 100644 --- a/xml/configuration/Settings.xml +++ b/xml/configuration/Settings.xml @@ -7,7 +7,7 @@ 0 - 0 + 1 0 @@ -22,4 +22,4 @@ 0 - \ No newline at end of file + diff --git a/xml/schema/Case/Case.xml b/xml/schema/Case/Case.xml index 15ffa0cf54..8c669e604c 100644 --- a/xml/schema/Case/Case.xml +++ b/xml/schema/Case/Case.xml @@ -44,7 +44,7 @@ true true false - Case Type Id + Case Type Multivalued pseudo-fk to option_value table where option_group_name = case_type. case_type @@ -159,7 +159,7 @@ true true false - Case Status Id + Case Status Id of case status. case_status -- 2.25.1