Merge pull request #16263 from eileenmcnaughton/ids_3
[civicrm-core.git] / CRM / Event / Task.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/**
6a488035 13 * @package CRM
ca5cec67 14 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
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 */
8fd26836 23class CRM_Event_Task extends CRM_Core_Task {
6a488035 24
90b461f1
SL
25 /**
26 * Event tasks
27 */
8fd26836 28 const
8fd26836
MW
29 CANCEL_REGISTRATION = 301,
30 PARTICIPANT_STATUS = 302;
6a488035 31
90b461f1
SL
32 /**
33 * @var string
34 */
35 public static $objectType = 'event';
6a488035
TO
36
37 /**
38 * These tasks are the core set of tasks that the user can perform
39 * on a contact / group of contacts
40 *
90b461f1
SL
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 * ]
6a488035 47 */
8fd26836
MW
48 public static function tasks() {
49 if (!self::$_tasks) {
be2fb01f
CW
50 self::$_tasks = [
51 self::TASK_DELETE => [
7f82e636 52 'title' => ts('Delete participants from event'),
6a488035
TO
53 'class' => 'CRM_Event_Form_Task_Delete',
54 'result' => FALSE,
be2fb01f
CW
55 ],
56 self::TASK_PRINT => [
7f82e636 57 'title' => ts('Print selected rows'),
6a488035
TO
58 'class' => 'CRM_Event_Form_Task_Print',
59 'result' => FALSE,
be2fb01f
CW
60 ],
61 self::TASK_EXPORT => [
7f82e636 62 'title' => ts('Export participants'),
be2fb01f 63 'class' => [
6a488035
TO
64 'CRM_Export_Form_Select',
65 'CRM_Export_Form_Map',
be2fb01f 66 ],
6a488035 67 'result' => FALSE,
be2fb01f
CW
68 ],
69 self::BATCH_UPDATE => [
b581842f 70 'title' => ts('Update multiple participants'),
be2fb01f 71 'class' => [
6a488035
TO
72 'CRM_Event_Form_Task_PickProfile',
73 'CRM_Event_Form_Task_Batch',
be2fb01f 74 ],
6a488035 75 'result' => TRUE,
be2fb01f
CW
76 ],
77 self::CANCEL_REGISTRATION => [
7f82e636 78 'title' => ts('Cancel registration'),
6a488035
TO
79 'class' => 'CRM_Event_Form_Task_Cancel',
80 'result' => FALSE,
be2fb01f
CW
81 ],
82 self::TASK_EMAIL => [
83 'title' => ts('Email - send now (to %1 or less)', [
21d01648
MW
84 1 => Civi::settings()
85 ->get('simple_mail_limit'),
be2fb01f 86 ]),
6a488035
TO
87 'class' => 'CRM_Event_Form_Task_Email',
88 'result' => TRUE,
be2fb01f
CW
89 ],
90 self::SAVE_SEARCH => [
7f12f044 91 'title' => ts('Group - create smart group'),
6a488035
TO
92 'class' => 'CRM_Event_Form_Task_SaveSearch',
93 'result' => TRUE,
be2fb01f
CW
94 ],
95 self::SAVE_SEARCH_UPDATE => [
7f12f044 96 'title' => ts('Group - update smart group'),
6a488035
TO
97 'class' => 'CRM_Event_Form_Task_SaveSearch_Update',
98 'result' => TRUE,
be2fb01f
CW
99 ],
100 self::PARTICIPANT_STATUS => [
1aa1efef 101 'title' => ts('Participant status - change'),
6a488035
TO
102 'class' => 'CRM_Event_Form_Task_ParticipantStatus',
103 'result' => TRUE,
be2fb01f
CW
104 ],
105 self::LABEL_CONTACTS => [
79e4c2ad 106 'title' => ts('Name badges - print'),
6a488035
TO
107 'class' => 'CRM_Event_Form_Task_Badge',
108 'result' => FALSE,
be2fb01f
CW
109 ],
110 self::PDF_LETTER => [
7f82e636 111 'title' => ts('PDF letter - print for participants'),
9cda9396
TM
112 'class' => 'CRM_Event_Form_Task_PDF',
113 'result' => TRUE,
be2fb01f
CW
114 ],
115 self::GROUP_ADD => [
7f82e636 116 'title' => ts('Group - add contacts'),
bb7b01e6
SD
117 'class' => 'CRM_Event_Form_Task_AddToGroup',
118 'result' => FALSE,
be2fb01f
CW
119 ],
120 ];
6a488035
TO
121
122 //CRM-4418, check for delete
123 if (!CRM_Core_Permission::check('delete in CiviEvent')) {
8fd26836 124 unset(self::$_tasks[self::TASK_DELETE]);
6a488035 125 }
447c72b5 126 //CRM-12920 - check for edit permission
481a74f4 127 if (!CRM_Core_Permission::check('edit event participants')) {
8fd26836 128 unset(self::$_tasks[self::BATCH_UPDATE], self::$_tasks[self::CANCEL_REGISTRATION], self::$_tasks[self::PARTICIPANT_STATUS]);
447c72b5 129 }
6a488035 130
8fd26836 131 parent::tasks();
4d73a5a7 132 }
18f6ea53 133
6a488035
TO
134 return self::$_tasks;
135 }
136
6a488035 137 /**
100fef9d 138 * Show tasks selectively based on the permission level
6a488035
TO
139 * of the user
140 *
141 * @param int $permission
8fd26836 142 * @param array $params
6a488035 143 *
a6c01b45
CW
144 * @return array
145 * set of tasks that are valid for the user
6a488035 146 */
be2fb01f 147 public static function permissionedTaskTitles($permission, $params = []) {
6a488035
TO
148 if (($permission == CRM_Core_Permission::EDIT)
149 || CRM_Core_Permission::check('edit event participants')
150 ) {
151 $tasks = self::taskTitles();
152 }
153 else {
be2fb01f 154 $tasks = [
8fd26836
MW
155 self::TASK_EXPORT => self::$_tasks[self::TASK_EXPORT]['title'],
156 self::TASK_EMAIL => self::$_tasks[self::TASK_EMAIL]['title'],
be2fb01f 157 ];
6a488035
TO
158
159 //CRM-4418,
160 if (CRM_Core_Permission::check('delete in CiviEvent')) {
8fd26836 161 $tasks[self::TASK_DELETE] = self::$_tasks[self::TASK_DELETE]['title'];
6a488035
TO
162 }
163 }
8fd26836
MW
164
165 $tasks = parent::corePermissionedTaskTitles($tasks, $permission, $params);
6a488035
TO
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 *
a6c01b45
CW
175 * @return array
176 * the set of tasks for a group of participants
6a488035 177 */
00be9182 178 public static function getTask($value) {
6a488035
TO
179 self::tasks();
180 if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) {
181 // make the print task by default
8fd26836 182 $value = self::TASK_PRINT;
6a488035 183 }
8fd26836 184 return parent::getTask($value);
6a488035 185 }
96025800 186
6a488035 187}