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