Commit | Line | Data |
---|---|---|
888da08c MW |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
888da08c | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
888da08c MW |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * @package CRM | |
6b83d5bd | 30 | * @copyright CiviCRM LLC (c) 2004-2019 |
888da08c MW |
31 | */ |
32 | ||
33 | /** | |
34 | * This class provides the functionality for batch profile update for cases | |
35 | */ | |
36 | class CRM_Case_Form_Task_Batch extends CRM_Core_Form_Task_Batch { | |
37 | ||
38 | // Must be set to entity table name (eg. civicrm_participant) by child class | |
39 | static $tableName = 'civicrm_case'; | |
40 | // Must be set to entity shortname (eg. event) | |
41 | static $entityShortname = 'case'; | |
42 | ||
43 | /** | |
44 | * Process the form after the input has been submitted and validated. | |
45 | * | |
46 | * @return void | |
47 | */ | |
48 | public function postProcess() { | |
49 | $params = $this->exportValues(); | |
50 | ||
51 | if (!isset($params['field'])) { | |
52 | CRM_Core_Session::setStatus(ts('No updates have been saved.'), ts('Not Saved'), 'alert'); | |
53 | return; | |
54 | } | |
55 | ||
56 | $customFields = array(); | |
57 | $dateFields = array( | |
58 | 'case_created_date', | |
59 | 'case_start_date', | |
60 | 'case_end_date', | |
61 | 'case_modified_date', | |
62 | ); | |
63 | foreach ($params['field'] as $key => $value) { | |
64 | $value['id'] = $key; | |
65 | ||
66 | if (!empty($value['case_type'])) { | |
67 | $caseTypeId = $value['case_type_id'] = $value['case_type'][1]; | |
68 | } | |
69 | unset($value['case_type']); | |
70 | ||
71 | // Get the case status | |
72 | $daoClass = 'CRM_Case_DAO_Case'; | |
73 | $caseStatus = CRM_Utils_Array::value('case_status', $value); | |
74 | if (!$caseStatus) { | |
75 | // default to existing status ID | |
76 | $caseStatus = CRM_Core_DAO::getFieldValue($daoClass, $key, 'status_id'); | |
77 | } | |
78 | $value['status_id'] = $caseStatus; | |
79 | unset($value['case_status']); | |
80 | ||
81 | foreach ($dateFields as $val) { | |
82 | if (isset($value[$val])) { | |
83 | $value[$val] = CRM_Utils_Date::processDate($value[$val]); | |
84 | } | |
85 | } | |
86 | if (empty($customFields)) { | |
87 | if (empty($value['case_type_id'])) { | |
88 | $caseTypeId = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case', $key, 'case_type_id'); | |
89 | } | |
90 | ||
91 | // case type custom data | |
92 | $customFields = CRM_Core_BAO_CustomField::getFields('Case', FALSE, FALSE, $caseTypeId); | |
93 | ||
94 | $customFields = CRM_Utils_Array::crmArrayMerge($customFields, | |
95 | CRM_Core_BAO_CustomField::getFields('Case', | |
96 | FALSE, FALSE, NULL, NULL, TRUE | |
97 | ) | |
98 | ); | |
99 | } | |
100 | //check for custom data | |
3eb99314 | 101 | // @todo extract submit functions & |
102 | // extend CRM_Event_Form_Task_BatchTest::testSubmit with a data provider to test | |
103 | // handling of custom data, specifically checkbox fields. | |
888da08c MW |
104 | $value['custom'] = CRM_Core_BAO_CustomField::postProcess($params['field'][$key], |
105 | $key, | |
106 | 'Case', | |
107 | $caseTypeId | |
108 | ); | |
109 | ||
110 | $case = CRM_Case_BAO_Case::add($value); | |
111 | ||
112 | // add custom field values | |
113 | if (!empty($value['custom']) && is_array($value['custom'])) { | |
114 | CRM_Core_BAO_CustomValueTable::store($value['custom'], 'civicrm_case', $case->id); | |
115 | } | |
116 | } | |
117 | ||
118 | CRM_Core_Session::setStatus(ts('Your updates have been saved.'), ts('Saved'), 'success'); | |
119 | } | |
120 | ||
121 | } |