3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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 +--------------------------------------------------------------------+
30 * @copyright CiviCRM LLC (c) 2004-2019
34 * This class provides the functionality for batch profile update for cases
36 class CRM_Case_Form_Task_Batch
extends CRM_Core_Form_Task_Batch
{
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';
44 * Process the form after the input has been submitted and validated.
48 public function postProcess() {
49 $params = $this->exportValues();
51 if (!isset($params['field'])) {
52 CRM_Core_Session
::setStatus(ts('No updates have been saved.'), ts('Not Saved'), 'alert');
56 $customFields = array();
63 foreach ($params['field'] as $key => $value) {
66 if (!empty($value['case_type'])) {
67 $caseTypeId = $value['case_type_id'] = $value['case_type'][1];
69 unset($value['case_type']);
71 // Get the case status
72 $daoClass = 'CRM_Case_DAO_Case';
73 $caseStatus = CRM_Utils_Array
::value('case_status', $value);
75 // default to existing status ID
76 $caseStatus = CRM_Core_DAO
::getFieldValue($daoClass, $key, 'status_id');
78 $value['status_id'] = $caseStatus;
79 unset($value['case_status']);
81 foreach ($dateFields as $val) {
82 if (isset($value[$val])) {
83 $value[$val] = CRM_Utils_Date
::processDate($value[$val]);
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');
91 // case type custom data
92 $customFields = CRM_Core_BAO_CustomField
::getFields('Case', FALSE, FALSE, $caseTypeId);
94 $customFields = CRM_Utils_Array
::crmArrayMerge($customFields,
95 CRM_Core_BAO_CustomField
::getFields('Case',
96 FALSE, FALSE, NULL, NULL, TRUE
100 //check for custom data
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.
104 $value['custom'] = CRM_Core_BAO_CustomField
::postProcess($params['field'][$key],
110 $case = CRM_Case_BAO_Case
::add($value);
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
);
118 CRM_Core_Session
::setStatus(ts('Your updates have been saved.'), ts('Saved'), 'success');