3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2015
37 * This class generates form components for OpenCase Activity
40 class CRM_Case_Form_Activity_ChangeCaseType
{
43 * @param CRM_Core_Form $form
47 public static function preProcess(&$form) {
48 if (!isset($form->_caseId
)) {
49 CRM_Core_Error
::fatal(ts('Case Id not found.'));
54 * Set default values for the form. For edit/view mode
55 * the default values are retrieved from the database
58 * @param CRM_Core_Form $form
62 public static function setDefaultValues(&$form) {
65 $defaults['is_reset_timeline'] = 1;
67 $defaults['reset_date_time'] = array();
68 list($defaults['reset_date_time'], $defaults['reset_date_time_time']) = CRM_Utils_Date
::setDateDefaults(NULL, 'activityDateTime');
69 $defaults['case_type_id'] = $form->_caseTypeId
;
75 * @param CRM_Core_Form $form
77 public static function buildQuickForm(&$form) {
78 $form->removeElement('status_id');
79 $form->removeElement('priority_id');
81 $caseId = CRM_Utils_Array
::first($form->_caseId
);
82 $form->_caseType
= CRM_Case_PseudoConstant
::caseType();
83 $form->_caseTypeId
= CRM_Core_DAO
::getFieldValue('CRM_Case_DAO_Case',
87 if (!in_array($form->_caseTypeId
, $form->_caseType
)) {
88 $form->_caseType
[$form->_caseTypeId
] = CRM_Core_DAO
::getFieldValue('CRM_Case_DAO_CaseType', $form->_caseTypeId
, 'title');
91 $form->add('select', 'case_type_id', ts('New Case Type'),
92 $form->_caseType
, TRUE
96 $form->addYesNo('is_reset_timeline', ts('Reset Case Timeline?'), NULL, TRUE, array('onclick' => "return showHideByValue('is_reset_timeline','','resetTimeline','table-row','radio',false);"));
97 $form->addDateTime('reset_date_time', ts('Reset Start Date'), FALSE, array('formatType' => 'activityDateTime'));
101 * Global validation rules for the form.
103 * @param array $values
104 * Posted values of the form.
107 * @param CRM_Core_Form $form
110 * list of errors to be posted back to the form
112 public static function formRule($values, $files, $form) {
117 * Process the form submission.
120 * @param CRM_Core_Form $form
121 * @param array $params
125 public static function beginPostProcess(&$form, &$params) {
126 if ($form->_context
== 'case') {
127 $params['id'] = $form->_id
;
130 if (CRM_Utils_Array
::value('is_reset_timeline', $params) == 0) {
131 unset($params['reset_date_time']);
134 // store the date with proper format
135 $params['reset_date_time'] = CRM_Utils_Date
::processDate($params['reset_date_time'], $params['reset_date_time_time']);
140 * Process the form submission.
143 * @param CRM_Core_Form $form
144 * @param array $params
149 public static function endPostProcess(&$form, &$params, $activity) {
150 if (!$form->_caseId
) {
151 // always expecting a change, so case-id is a must.
155 $caseTypes = CRM_Case_PseudoConstant
::caseType('name');
156 $allCaseTypes = CRM_Case_PseudoConstant
::caseType('title', FALSE);
158 if (!empty($caseTypes[$params['case_type_id']])) {
159 $caseType = $caseTypes[$params['case_type_id']];
162 if (!$form->_currentlyViewedContactId ||
163 !$form->_currentUserId ||
164 !$params['case_type_id'] ||
167 CRM_Core_Error
::fatal('Required parameter missing for ChangeCaseType - end post processing');
170 $params['status_id'] = CRM_Core_OptionGroup
::getValue('activity_status', 'Completed', 'name');
171 $activity->status_id
= $params['status_id'];
172 $params['priority_id'] = CRM_Core_OptionGroup
::getValue('priority', 'Normal', 'name');
173 $activity->priority_id
= $params['priority_id'];
175 if ($activity->subject
== 'null') {
176 $activity->subject
= ts('Case type changed from %1 to %2',
178 1 => CRM_Utils_Array
::value($form->_defaults
['case_type_id'], $allCaseTypes),
179 2 => CRM_Utils_Array
::value($params['case_type_id'], $allCaseTypes),
185 // 1. initiate xml processor
186 $xmlProcessor = new CRM_Case_XMLProcessor_Process();
187 $caseId = CRM_Utils_Array
::first($form->_caseId
);
188 $xmlProcessorParams = array(
189 'clientID' => $form->_currentlyViewedContactId
,
190 'creatorID' => $form->_currentUserId
,
191 'standardTimeline' => 1,
192 'activityTypeName' => 'Change Case Type',
193 'activity_date_time' => CRM_Utils_Array
::value('reset_date_time', $params),
195 'resetTimeline' => CRM_Utils_Array
::value('is_reset_timeline', $params),
198 $xmlProcessor->run($caseType, $xmlProcessorParams);
200 $params['statusMsg'] = ts('Case Type changed successfully.');