composer.json - Move ezc components from packages to composer.json
[civicrm-core.git] / CRM / Event / Task.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
6a488035
TO
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 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
e7112fa7 31 * @copyright CiviCRM LLC (c) 2004-2015
6a488035
TO
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 */
41class CRM_Event_Task {
42 // Value for SAVE_SEARCH is set to 13 in accordance with CRM_Contact_Task::SAVE_SEARCH
7da04cde 43 const DELETE_EVENTS = 1, PRINT_EVENTS = 2, EXPORT_EVENTS = 3, BATCH_EVENTS = 4, CANCEL_REGISTRATION = 5, EMAIL_CONTACTS = 6,
353ffa53
TO
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;
6a488035
TO
47
48 /**
100fef9d 49 * The task array
6a488035
TO
50 *
51 * @var array
6a488035
TO
52 */
53 static $_tasks = NULL;
54
55 /**
100fef9d 56 * The optional task array
6a488035
TO
57 *
58 * @var array
6a488035
TO
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 *
a6c01b45
CW
66 * @return array
67 * the set of tasks for a group of contacts
6a488035 68 */
00be9182 69 public static function &tasks() {
6a488035 70 if (!(self::$_tasks)) {
0479b4c8 71 self::$_tasks = array(
353ffa53 72 1 => array(
7f82e636 73 'title' => ts('Delete participants from event'),
6a488035
TO
74 'class' => 'CRM_Event_Form_Task_Delete',
75 'result' => FALSE,
76 ),
23546577 77 2 => array(
7f82e636 78 'title' => ts('Print selected rows'),
6a488035
TO
79 'class' => 'CRM_Event_Form_Task_Print',
80 'result' => FALSE,
81 ),
23546577 82 3 => array(
7f82e636 83 'title' => ts('Export participants'),
6a488035
TO
84 'class' => array(
85 'CRM_Export_Form_Select',
86 'CRM_Export_Form_Map',
87 ),
88 'result' => FALSE,
89 ),
23546577 90 4 => array(
b581842f 91 'title' => ts('Update multiple participants'),
6a488035
TO
92 'class' => array(
93 'CRM_Event_Form_Task_PickProfile',
94 'CRM_Event_Form_Task_Batch',
95 ),
96 'result' => TRUE,
97 ),
23546577 98 5 => array(
7f82e636 99 'title' => ts('Cancel registration'),
6a488035
TO
100 'class' => 'CRM_Event_Form_Task_Cancel',
101 'result' => FALSE,
102 ),
23546577 103 6 => array(
79e4c2ad 104 'title' => ts('Email - send now'),
6a488035
TO
105 'class' => 'CRM_Event_Form_Task_Email',
106 'result' => TRUE,
107 ),
23546577 108 13 => array(
7f12f044 109 'title' => ts('Group - create smart group'),
6a488035
TO
110 'class' => 'CRM_Event_Form_Task_SaveSearch',
111 'result' => TRUE,
112 ),
23546577 113 14 => array(
7f12f044 114 'title' => ts('Group - update smart group'),
6a488035
TO
115 'class' => 'CRM_Event_Form_Task_SaveSearch_Update',
116 'result' => TRUE,
117 ),
23546577 118 15 => array(
b581842f 119 'title' => ts('Participant status - change (emails sent)'),
6a488035
TO
120 'class' => 'CRM_Event_Form_Task_ParticipantStatus',
121 'result' => TRUE,
122 ),
23546577 123 16 => array(
79e4c2ad 124 'title' => ts('Name badges - print'),
6a488035
TO
125 'class' => 'CRM_Event_Form_Task_Badge',
126 'result' => FALSE,
127 ),
9cda9396 128 17 => array(
7f82e636 129 'title' => ts('PDF letter - print for participants'),
9cda9396
TM
130 'class' => 'CRM_Event_Form_Task_PDF',
131 'result' => TRUE,
132 ),
bb7b01e6 133 20 => array(
7f82e636 134 'title' => ts('Group - add contacts'),
bb7b01e6
SD
135 'class' => 'CRM_Event_Form_Task_AddToGroup',
136 'result' => FALSE,
137 ),
6a488035
TO
138 );
139
140 //CRM-4418, check for delete
141 if (!CRM_Core_Permission::check('delete in CiviEvent')) {
142 unset(self::$_tasks[1]);
143 }
447c72b5 144 //CRM-12920 - check for edit permission
481a74f4 145 if (!CRM_Core_Permission::check('edit event participants')) {
0479b4c8 146 unset(self::$_tasks[4], self::$_tasks[5], self::$_tasks[15]);
447c72b5 147 }
6a488035
TO
148 }
149
150 CRM_Utils_Hook::searchTasks('event', self::$_tasks);
18f6ea53 151
6a488035
TO
152 return self::$_tasks;
153 }
154
155 /**
156 * These tasks are the core set of task titles
157 * for participants
158 *
a6c01b45
CW
159 * @return array
160 * the set of task titles
6a488035 161 */
00be9182 162 public static function &taskTitles() {
6a488035
TO
163 self::tasks();
164 $titles = array();
165 foreach (self::$_tasks as $id => $value) {
e341bbee
CW
166 // skip Update Smart Group task
167 if ($id != self::SAVE_SEARCH_UPDATE) {
6a488035
TO
168 $titles[$id] = $value['title'];
169 }
6a488035
TO
170 }
171 return $titles;
172 }
173
174 /**
fe482240 175 * These tasks get added based on the context the user is in.
6a488035 176 *
a6c01b45
CW
177 * @return array
178 * the set of optional tasks for a group of contacts
6a488035 179 */
00be9182 180 public static function &optionalTaskTitle() {
6a488035
TO
181 $tasks = array(
182 14 => self::$_tasks[14]['title'],
183 );
184 return $tasks;
185 }
186
187 /**
100fef9d 188 * Show tasks selectively based on the permission level
6a488035
TO
189 * of the user
190 *
191 * @param int $permission
192 *
a6c01b45
CW
193 * @return array
194 * set of tasks that are valid for the user
6a488035 195 */
00be9182 196 public static function &permissionedTaskTitles($permission) {
6a488035
TO
197 $tasks = array();
198 if (($permission == CRM_Core_Permission::EDIT)
199 || CRM_Core_Permission::check('edit event participants')
200 ) {
201 $tasks = self::taskTitles();
202 }
203 else {
204 $tasks = array(
205 3 => self::$_tasks[3]['title'],
206 6 => self::$_tasks[6]['title'],
207 );
208
209 //CRM-4418,
210 if (CRM_Core_Permission::check('delete in CiviEvent')) {
211 $tasks[1] = self::$_tasks[1]['title'];
212 }
213 }
214 return $tasks;
215 }
216
217 /**
218 * These tasks are the core set of tasks that the user can perform
219 * on participants
220 *
221 * @param int $value
222 *
a6c01b45
CW
223 * @return array
224 * the set of tasks for a group of participants
6a488035 225 */
00be9182 226 public static function getTask($value) {
6a488035
TO
227 self::tasks();
228 if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) {
229 // make the print task by default
230 $value = 2;
231 }
2c783bc9 232 asort(self::$_tasks);
6a488035
TO
233 return array(
234 self::$_tasks[$value]['class'],
235 self::$_tasks[$value]['result'],
236 );
237 }
96025800 238
6a488035 239}