Merge pull request #15248 from MegaphoneJon/reporting-19
[civicrm-core.git] / CRM / Event / Task.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2020 |
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
30 * @copyright CiviCRM LLC (c) 2004-2020
31 *
32 */
33
34 /**
35 * class to represent the actions that can be performed on a group of contacts
36 * used by the search forms
37 *
38 */
39 class CRM_Event_Task extends CRM_Core_Task {
40
41 /**
42 * Event tasks
43 */
44 const
45 CANCEL_REGISTRATION = 301,
46 PARTICIPANT_STATUS = 302;
47
48 /**
49 * @var string
50 */
51 public static $objectType = 'event';
52
53 /**
54 * These tasks are the core set of tasks that the user can perform
55 * on a contact / group of contacts
56 *
57 * @return array
58 * The set of tasks for a group of contacts
59 * [ 'title' => The Task title,
60 * 'class' => The Task Form class name,
61 * 'result => Boolean. FIXME: Not sure what this is for
62 * ]
63 */
64 public static function tasks() {
65 if (!self::$_tasks) {
66 self::$_tasks = [
67 self::TASK_DELETE => [
68 'title' => ts('Delete participants from event'),
69 'class' => 'CRM_Event_Form_Task_Delete',
70 'result' => FALSE,
71 ],
72 self::TASK_PRINT => [
73 'title' => ts('Print selected rows'),
74 'class' => 'CRM_Event_Form_Task_Print',
75 'result' => FALSE,
76 ],
77 self::TASK_EXPORT => [
78 'title' => ts('Export participants'),
79 'class' => [
80 'CRM_Export_Form_Select',
81 'CRM_Export_Form_Map',
82 ],
83 'result' => FALSE,
84 ],
85 self::BATCH_UPDATE => [
86 'title' => ts('Update multiple participants'),
87 'class' => [
88 'CRM_Event_Form_Task_PickProfile',
89 'CRM_Event_Form_Task_Batch',
90 ],
91 'result' => TRUE,
92 ],
93 self::CANCEL_REGISTRATION => [
94 'title' => ts('Cancel registration'),
95 'class' => 'CRM_Event_Form_Task_Cancel',
96 'result' => FALSE,
97 ],
98 self::TASK_EMAIL => [
99 'title' => ts('Email - send now (to %1 or less)', [
100 1 => Civi::settings()
101 ->get('simple_mail_limit'),
102 ]),
103 'class' => 'CRM_Event_Form_Task_Email',
104 'result' => TRUE,
105 ],
106 self::SAVE_SEARCH => [
107 'title' => ts('Group - create smart group'),
108 'class' => 'CRM_Event_Form_Task_SaveSearch',
109 'result' => TRUE,
110 ],
111 self::SAVE_SEARCH_UPDATE => [
112 'title' => ts('Group - update smart group'),
113 'class' => 'CRM_Event_Form_Task_SaveSearch_Update',
114 'result' => TRUE,
115 ],
116 self::PARTICIPANT_STATUS => [
117 'title' => ts('Participant status - change'),
118 'class' => 'CRM_Event_Form_Task_ParticipantStatus',
119 'result' => TRUE,
120 ],
121 self::LABEL_CONTACTS => [
122 'title' => ts('Name badges - print'),
123 'class' => 'CRM_Event_Form_Task_Badge',
124 'result' => FALSE,
125 ],
126 self::PDF_LETTER => [
127 'title' => ts('PDF letter - print for participants'),
128 'class' => 'CRM_Event_Form_Task_PDF',
129 'result' => TRUE,
130 ],
131 self::GROUP_ADD => [
132 'title' => ts('Group - add contacts'),
133 'class' => 'CRM_Event_Form_Task_AddToGroup',
134 'result' => FALSE,
135 ],
136 ];
137
138 //CRM-4418, check for delete
139 if (!CRM_Core_Permission::check('delete in CiviEvent')) {
140 unset(self::$_tasks[self::TASK_DELETE]);
141 }
142 //CRM-12920 - check for edit permission
143 if (!CRM_Core_Permission::check('edit event participants')) {
144 unset(self::$_tasks[self::BATCH_UPDATE], self::$_tasks[self::CANCEL_REGISTRATION], self::$_tasks[self::PARTICIPANT_STATUS]);
145 }
146
147 parent::tasks();
148 }
149
150 return self::$_tasks;
151 }
152
153 /**
154 * Show tasks selectively based on the permission level
155 * of the user
156 *
157 * @param int $permission
158 * @param array $params
159 *
160 * @return array
161 * set of tasks that are valid for the user
162 */
163 public static function permissionedTaskTitles($permission, $params = []) {
164 if (($permission == CRM_Core_Permission::EDIT)
165 || CRM_Core_Permission::check('edit event participants')
166 ) {
167 $tasks = self::taskTitles();
168 }
169 else {
170 $tasks = [
171 self::TASK_EXPORT => self::$_tasks[self::TASK_EXPORT]['title'],
172 self::TASK_EMAIL => self::$_tasks[self::TASK_EMAIL]['title'],
173 ];
174
175 //CRM-4418,
176 if (CRM_Core_Permission::check('delete in CiviEvent')) {
177 $tasks[self::TASK_DELETE] = self::$_tasks[self::TASK_DELETE]['title'];
178 }
179 }
180
181 $tasks = parent::corePermissionedTaskTitles($tasks, $permission, $params);
182 return $tasks;
183 }
184
185 /**
186 * These tasks are the core set of tasks that the user can perform
187 * on participants
188 *
189 * @param int $value
190 *
191 * @return array
192 * the set of tasks for a group of participants
193 */
194 public static function getTask($value) {
195 self::tasks();
196 if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) {
197 // make the print task by default
198 $value = self::TASK_PRINT;
199 }
200 return parent::getTask($value);
201 }
202
203 }