Merge pull request #11553 from civicrm/4.7.30-rc
[civicrm-core.git] / CRM / Event / Task.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2017
32 * $Id$
33 *
34 */
35
36 /**
37 * class to represent the actions that can be performed on a group of contacts
38 * used by the search forms
39 *
40 */
41 class CRM_Event_Task {
42 // Value for SAVE_SEARCH is set to 13 in accordance with CRM_Contact_Task::SAVE_SEARCH
43 const DELETE_EVENTS = 1, PRINT_EVENTS = 2, EXPORT_EVENTS = 3, BATCH_EVENTS = 4, CANCEL_REGISTRATION = 5, EMAIL_CONTACTS = 6,
44 // Value for LABEL_CONTACTS is set to 16 in accordance with CRM_Contact_Task::LABEL_CONTACTS
45 SAVE_SEARCH = 13, SAVE_SEARCH_UPDATE = 14, PARTICIPANT_STATUS = 15,
46 LABEL_CONTACTS = 16, GROUP_CONTACTS = 20;
47
48 /**
49 * The task array
50 *
51 * @var array
52 */
53 static $_tasks = NULL;
54
55 /**
56 * The optional task array
57 *
58 * @var array
59 */
60 static $_optionalTasks = NULL;
61
62 /**
63 * These tasks are the core set of tasks that the user can perform
64 * on a contact / group of contacts
65 *
66 * @return array
67 * the set of tasks for a group of contacts
68 */
69 public static function &tasks() {
70 if (!(self::$_tasks)) {
71 self::$_tasks = array(
72 1 => array(
73 'title' => ts('Delete participants from event'),
74 'class' => 'CRM_Event_Form_Task_Delete',
75 'result' => FALSE,
76 ),
77 2 => array(
78 'title' => ts('Print selected rows'),
79 'class' => 'CRM_Event_Form_Task_Print',
80 'result' => FALSE,
81 ),
82 3 => array(
83 'title' => ts('Export participants'),
84 'class' => array(
85 'CRM_Export_Form_Select',
86 'CRM_Export_Form_Map',
87 ),
88 'result' => FALSE,
89 ),
90 4 => array(
91 'title' => ts('Update multiple participants'),
92 'class' => array(
93 'CRM_Event_Form_Task_PickProfile',
94 'CRM_Event_Form_Task_Batch',
95 ),
96 'result' => TRUE,
97 ),
98 5 => array(
99 'title' => ts('Cancel registration'),
100 'class' => 'CRM_Event_Form_Task_Cancel',
101 'result' => FALSE,
102 ),
103 6 => array(
104 'title' => ts('Email - send now (to %1 or less)', array(
105 1 => Civi::settings()
106 ->get('simple_mail_limit'),
107 )),
108 'class' => 'CRM_Event_Form_Task_Email',
109 'result' => TRUE,
110 ),
111 13 => array(
112 'title' => ts('Group - create smart group'),
113 'class' => 'CRM_Event_Form_Task_SaveSearch',
114 'result' => TRUE,
115 ),
116 14 => array(
117 'title' => ts('Group - update smart group'),
118 'class' => 'CRM_Event_Form_Task_SaveSearch_Update',
119 'result' => TRUE,
120 ),
121 15 => array(
122 'title' => ts('Participant status - change'),
123 'class' => 'CRM_Event_Form_Task_ParticipantStatus',
124 'result' => TRUE,
125 ),
126 16 => array(
127 'title' => ts('Name badges - print'),
128 'class' => 'CRM_Event_Form_Task_Badge',
129 'result' => FALSE,
130 ),
131 17 => array(
132 'title' => ts('PDF letter - print for participants'),
133 'class' => 'CRM_Event_Form_Task_PDF',
134 'result' => TRUE,
135 ),
136 20 => array(
137 'title' => ts('Group - add contacts'),
138 'class' => 'CRM_Event_Form_Task_AddToGroup',
139 'result' => FALSE,
140 ),
141 );
142
143 //CRM-4418, check for delete
144 if (!CRM_Core_Permission::check('delete in CiviEvent')) {
145 unset(self::$_tasks[1]);
146 }
147 //CRM-12920 - check for edit permission
148 if (!CRM_Core_Permission::check('edit event participants')) {
149 unset(self::$_tasks[4], self::$_tasks[5], self::$_tasks[15]);
150 }
151
152 CRM_Utils_Hook::searchTasks('event', self::$_tasks);
153 }
154
155 return self::$_tasks;
156 }
157
158 /**
159 * These tasks are the core set of task titles
160 * for participants
161 *
162 * @return array
163 * the set of task titles
164 */
165 public static function &taskTitles() {
166 self::tasks();
167 $titles = array();
168 foreach (self::$_tasks as $id => $value) {
169 // skip Update Smart Group task
170 if ($id != self::SAVE_SEARCH_UPDATE) {
171 $titles[$id] = $value['title'];
172 }
173 }
174 return $titles;
175 }
176
177 /**
178 * These tasks get added based on the context the user is in.
179 *
180 * @return array
181 * the set of optional tasks for a group of contacts
182 */
183 public static function &optionalTaskTitle() {
184 $tasks = array(
185 14 => self::$_tasks[14]['title'],
186 );
187 return $tasks;
188 }
189
190 /**
191 * Show tasks selectively based on the permission level
192 * of the user
193 *
194 * @param int $permission
195 *
196 * @return array
197 * set of tasks that are valid for the user
198 */
199 public static function &permissionedTaskTitles($permission) {
200 $tasks = array();
201 if (($permission == CRM_Core_Permission::EDIT)
202 || CRM_Core_Permission::check('edit event participants')
203 ) {
204 $tasks = self::taskTitles();
205 }
206 else {
207 $tasks = array(
208 3 => self::$_tasks[3]['title'],
209 6 => self::$_tasks[6]['title'],
210 );
211
212 //CRM-4418,
213 if (CRM_Core_Permission::check('delete in CiviEvent')) {
214 $tasks[1] = self::$_tasks[1]['title'];
215 }
216 }
217 return $tasks;
218 }
219
220 /**
221 * These tasks are the core set of tasks that the user can perform
222 * on participants
223 *
224 * @param int $value
225 *
226 * @return array
227 * the set of tasks for a group of participants
228 */
229 public static function getTask($value) {
230 self::tasks();
231 if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) {
232 // make the print task by default
233 $value = 2;
234 }
235 asort(self::$_tasks);
236 return array(
237 self::$_tasks[$value]['class'],
238 self::$_tasks[$value]['result'],
239 );
240 }
241
242 }