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
{
39 * Must be set to entity table name (eg. civicrm_participant) by child class
42 public static $tableName = 'civicrm_case';
44 * Must be set to entity shortname (eg. event)
47 public static $entityShortname = 'case';
50 * Process the form after the input has been submitted and validated.
54 public function postProcess() {
55 $params = $this->exportValues();
57 if (!isset($params['field'])) {
58 CRM_Core_Session
::setStatus(ts('No updates have been saved.'), ts('Not Saved'), 'alert');
69 foreach ($params['field'] as $key => $value) {
72 if (!empty($value['case_type'])) {
73 $caseTypeId = $value['case_type_id'] = $value['case_type'][1];
75 unset($value['case_type']);
77 // Get the case status
78 $daoClass = 'CRM_Case_DAO_Case';
79 $caseStatus = CRM_Utils_Array
::value('case_status', $value);
81 // default to existing status ID
82 $caseStatus = CRM_Core_DAO
::getFieldValue($daoClass, $key, 'status_id');
84 $value['status_id'] = $caseStatus;
85 unset($value['case_status']);
87 foreach ($dateFields as $val) {
88 if (isset($value[$val])) {
89 $value[$val] = CRM_Utils_Date
::processDate($value[$val]);
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');
97 // case type custom data
98 $customFields = CRM_Core_BAO_CustomField
::getFields('Case', FALSE, FALSE, $caseTypeId);
100 $customFields = CRM_Utils_Array
::crmArrayMerge($customFields,
101 CRM_Core_BAO_CustomField
::getFields('Case',
102 FALSE, FALSE, NULL, NULL, TRUE
106 //check for custom data
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.
110 $value['custom'] = CRM_Core_BAO_CustomField
::postProcess($params['field'][$key],
116 $case = CRM_Case_BAO_Case
::add($value);
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
);
124 CRM_Core_Session
::setStatus(ts('Your updates have been saved.'), ts('Saved'), 'success');