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 | ||
f157740d SL |
38 | /** |
39 | * Must be set to entity table name (eg. civicrm_participant) by child class | |
40 | * @var string | |
41 | */ | |
42 | public static $tableName = 'civicrm_case'; | |
43 | /** | |
44 | * Must be set to entity shortname (eg. event) | |
45 | * @var string | |
46 | */ | |
47 | public static $entityShortname = 'case'; | |
888da08c MW |
48 | |
49 | /** | |
50 | * Process the form after the input has been submitted and validated. | |
51 | * | |
52 | * @return void | |
53 | */ | |
54 | public function postProcess() { | |
55 | $params = $this->exportValues(); | |
56 | ||
57 | if (!isset($params['field'])) { | |
58 | CRM_Core_Session::setStatus(ts('No updates have been saved.'), ts('Not Saved'), 'alert'); | |
59 | return; | |
60 | } | |
61 | ||
be2fb01f CW |
62 | $customFields = []; |
63 | $dateFields = [ | |
888da08c MW |
64 | 'case_created_date', |
65 | 'case_start_date', | |
66 | 'case_end_date', | |
67 | 'case_modified_date', | |
be2fb01f | 68 | ]; |
888da08c MW |
69 | foreach ($params['field'] as $key => $value) { |
70 | $value['id'] = $key; | |
71 | ||
72 | if (!empty($value['case_type'])) { | |
73 | $caseTypeId = $value['case_type_id'] = $value['case_type'][1]; | |
74 | } | |
75 | unset($value['case_type']); | |
76 | ||
77 | // Get the case status | |
78 | $daoClass = 'CRM_Case_DAO_Case'; | |
79 | $caseStatus = CRM_Utils_Array::value('case_status', $value); | |
80 | if (!$caseStatus) { | |
81 | // default to existing status ID | |
82 | $caseStatus = CRM_Core_DAO::getFieldValue($daoClass, $key, 'status_id'); | |
83 | } | |
84 | $value['status_id'] = $caseStatus; | |
85 | unset($value['case_status']); | |
86 | ||
87 | foreach ($dateFields as $val) { | |
88 | if (isset($value[$val])) { | |
89 | $value[$val] = CRM_Utils_Date::processDate($value[$val]); | |
90 | } | |
91 | } | |
92 | if (empty($customFields)) { | |
93 | if (empty($value['case_type_id'])) { | |
94 | $caseTypeId = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case', $key, 'case_type_id'); | |
95 | } | |
96 | ||
97 | // case type custom data | |
98 | $customFields = CRM_Core_BAO_CustomField::getFields('Case', FALSE, FALSE, $caseTypeId); | |
99 | ||
100 | $customFields = CRM_Utils_Array::crmArrayMerge($customFields, | |
101 | CRM_Core_BAO_CustomField::getFields('Case', | |
102 | FALSE, FALSE, NULL, NULL, TRUE | |
103 | ) | |
104 | ); | |
105 | } | |
106 | //check for custom data | |
3eb99314 | 107 | // @todo extract submit functions & |
108 | // extend CRM_Event_Form_Task_BatchTest::testSubmit with a data provider to test | |
109 | // handling of custom data, specifically checkbox fields. | |
888da08c MW |
110 | $value['custom'] = CRM_Core_BAO_CustomField::postProcess($params['field'][$key], |
111 | $key, | |
112 | 'Case', | |
113 | $caseTypeId | |
114 | ); | |
115 | ||
116 | $case = CRM_Case_BAO_Case::add($value); | |
117 | ||
118 | // add custom field values | |
119 | if (!empty($value['custom']) && is_array($value['custom'])) { | |
120 | CRM_Core_BAO_CustomValueTable::store($value['custom'], 'civicrm_case', $case->id); | |
121 | } | |
122 | } | |
123 | ||
124 | CRM_Core_Session::setStatus(ts('Your updates have been saved.'), ts('Saved'), 'success'); | |
125 | } | |
126 | ||
127 | } |