Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
f299f7db | 6 | | Copyright CiviCRM LLC (c) 2004-2020 | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
f299f7db | 31 | * @copyright CiviCRM LLC (c) 2004-2020 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
35 | * This class provides the functionality to email a group of contacts | |
36 | */ | |
37 | class CRM_Activity_Form_Task_FileOnCase extends CRM_Activity_Form_Task { | |
38 | ||
39 | /** | |
fe482240 | 40 | * The title of the group. |
6a488035 TO |
41 | * |
42 | * @var string | |
43 | */ | |
44 | protected $_title; | |
45 | ||
46 | /** | |
fe482240 | 47 | * Variable to store redirect path. |
62d3ee27 | 48 | * @var string |
6a488035 TO |
49 | */ |
50 | protected $_userContext; | |
51 | ||
52 | /** | |
fe482240 | 53 | * Variable to store contact Ids. |
62d3ee27 | 54 | * @var array |
6a488035 TO |
55 | */ |
56 | public $_contacts; | |
57 | ||
58 | /** | |
fe482240 | 59 | * Build all the data structures needed to build the form. |
f72119d9 | 60 | */ |
00be9182 | 61 | public function preProcess() { |
6a488035 TO |
62 | parent::preProcess(); |
63 | $session = CRM_Core_Session::singleton(); | |
64 | $this->_userContext = $session->readUserContext(); | |
65 | ||
66 | CRM_Utils_System::setTitle(ts('File on Case')); | |
6a488035 TO |
67 | } |
68 | ||
69 | /** | |
fe482240 | 70 | * Build the form object. |
6a488035 | 71 | */ |
00be9182 | 72 | public function buildQuickForm() { |
be2fb01f | 73 | $this->addEntityRef('unclosed_case_id', ts('Select Case'), ['entity' => 'Case'], TRUE); |
f212d37d | 74 | $this->addDefaultButtons(ts('Save')); |
6a488035 TO |
75 | } |
76 | ||
6a488035 | 77 | /** |
fe482240 | 78 | * Process the form after the input has been submitted and validated. |
6a488035 | 79 | */ |
6a488035 | 80 | public function postProcess() { |
353ffa53 TO |
81 | $formparams = $this->exportValues(); |
82 | $caseId = $formparams['unclosed_case_id']; | |
6a488035 TO |
83 | $filedActivities = 0; |
84 | foreach ($this->_activityHolderIds as $key => $id) { | |
be2fb01f CW |
85 | $targetContactValues = $defaults = []; |
86 | $params = ['id' => $id]; | |
6a488035 TO |
87 | CRM_Activity_BAO_Activity::retrieve($params, $defaults); |
88 | if (CRM_Case_BAO_Case::checkPermission($id, 'File On Case', $defaults['activity_type_id'])) { | |
89 | ||
90 | if (!CRM_Utils_Array::crmIsEmptyArray($defaults['target_contact'])) { | |
91 | $targetContactValues = array_combine(array_unique($defaults['target_contact']), | |
92 | explode(';', trim($defaults['target_contact_value'])) | |
93 | ); | |
94 | $targetContactValues = implode(',', array_keys($targetContactValues)); | |
95 | } | |
96 | ||
be2fb01f | 97 | $params = [ |
6a488035 TO |
98 | 'caseID' => $caseId, |
99 | 'activityID' => $id, | |
100 | 'newSubject' => empty($defaults['subject']) ? '' : $defaults['subject'], | |
101 | 'targetContactIds' => $targetContactValues, | |
102 | 'mode' => 'file', | |
be2fb01f | 103 | ]; |
6a488035 TO |
104 | |
105 | $error_msg = CRM_Activity_Page_AJAX::_convertToCaseActivity($params); | |
106 | if (empty($error_msg['error_msg'])) { | |
107 | $filedActivities++; | |
108 | } | |
109 | else { | |
110 | CRM_Core_Session::setStatus($error_msg['error_msg'], ts("Error"), "error"); | |
111 | } | |
112 | } | |
113 | else { | |
0d48f1cc TO |
114 | CRM_Core_Session::setStatus( |
115 | ts('Not permitted to file activity %1 %2.', [ | |
353ffa53 | 116 | 1 => empty($defaults['subject']) ? '' : $defaults['subject'], |
389bcebf | 117 | 2 => $defaults['activity_date_time'], |
be2fb01f | 118 | ]), |
6a488035 TO |
119 | ts("Error"), "error"); |
120 | } | |
121 | } | |
122 | ||
123 | CRM_Core_Session::setStatus($filedActivities, ts("Filed Activities"), "success"); | |
be2fb01f | 124 | CRM_Core_Session::setStatus("", ts('Total Selected Activities: %1', [1 => count($this->_activityHolderIds)]), "info"); |
6a488035 | 125 | } |
96025800 | 126 | |
6a488035 | 127 | } |