Merge pull request #15825 from seamuslee001/dev_core_183_logging
[civicrm-core.git] / CRM / Activity / Form / Task / FileOnCase.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 */
17
18/**
19 * This class provides the functionality to email a group of contacts
20 */
21class CRM_Activity_Form_Task_FileOnCase extends CRM_Activity_Form_Task {
22
23 /**
fe482240 24 * The title of the group.
6a488035
TO
25 *
26 * @var string
27 */
28 protected $_title;
29
30 /**
fe482240 31 * Variable to store redirect path.
62d3ee27 32 * @var string
6a488035
TO
33 */
34 protected $_userContext;
35
36 /**
fe482240 37 * Variable to store contact Ids.
62d3ee27 38 * @var array
6a488035
TO
39 */
40 public $_contacts;
41
42 /**
fe482240 43 * Build all the data structures needed to build the form.
f72119d9 44 */
00be9182 45 public function preProcess() {
6a488035
TO
46 parent::preProcess();
47 $session = CRM_Core_Session::singleton();
48 $this->_userContext = $session->readUserContext();
49
50 CRM_Utils_System::setTitle(ts('File on Case'));
6a488035
TO
51 }
52
53 /**
fe482240 54 * Build the form object.
6a488035 55 */
00be9182 56 public function buildQuickForm() {
be2fb01f 57 $this->addEntityRef('unclosed_case_id', ts('Select Case'), ['entity' => 'Case'], TRUE);
f212d37d 58 $this->addDefaultButtons(ts('Save'));
6a488035
TO
59 }
60
6a488035 61 /**
fe482240 62 * Process the form after the input has been submitted and validated.
6a488035 63 */
6a488035 64 public function postProcess() {
353ffa53
TO
65 $formparams = $this->exportValues();
66 $caseId = $formparams['unclosed_case_id'];
6a488035
TO
67 $filedActivities = 0;
68 foreach ($this->_activityHolderIds as $key => $id) {
be2fb01f
CW
69 $targetContactValues = $defaults = [];
70 $params = ['id' => $id];
6a488035
TO
71 CRM_Activity_BAO_Activity::retrieve($params, $defaults);
72 if (CRM_Case_BAO_Case::checkPermission($id, 'File On Case', $defaults['activity_type_id'])) {
73
74 if (!CRM_Utils_Array::crmIsEmptyArray($defaults['target_contact'])) {
75 $targetContactValues = array_combine(array_unique($defaults['target_contact']),
76 explode(';', trim($defaults['target_contact_value']))
77 );
78 $targetContactValues = implode(',', array_keys($targetContactValues));
79 }
80
be2fb01f 81 $params = [
6a488035
TO
82 'caseID' => $caseId,
83 'activityID' => $id,
84 'newSubject' => empty($defaults['subject']) ? '' : $defaults['subject'],
85 'targetContactIds' => $targetContactValues,
86 'mode' => 'file',
be2fb01f 87 ];
6a488035
TO
88
89 $error_msg = CRM_Activity_Page_AJAX::_convertToCaseActivity($params);
90 if (empty($error_msg['error_msg'])) {
91 $filedActivities++;
92 }
93 else {
94 CRM_Core_Session::setStatus($error_msg['error_msg'], ts("Error"), "error");
95 }
96 }
97 else {
0d48f1cc
TO
98 CRM_Core_Session::setStatus(
99 ts('Not permitted to file activity %1 %2.', [
353ffa53 100 1 => empty($defaults['subject']) ? '' : $defaults['subject'],
389bcebf 101 2 => $defaults['activity_date_time'],
be2fb01f 102 ]),
6a488035
TO
103 ts("Error"), "error");
104 }
105 }
106
107 CRM_Core_Session::setStatus($filedActivities, ts("Filed Activities"), "success");
be2fb01f 108 CRM_Core_Session::setStatus("", ts('Total Selected Activities: %1', [1 => count($this->_activityHolderIds)]), "info");
6a488035 109 }
96025800 110
6a488035 111}