Merge pull request #4887 from pratikshad/broken-webtest
[civicrm-core.git] / CRM / Event / Task.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
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 * @static
53 */
54 static $_tasks = NULL;
55
56 /**
57 * The optional task array
58 *
59 * @var array
60 * @static
61 */
62 static $_optionalTasks = NULL;
63
64 /**
65 * These tasks are the core set of tasks that the user can perform
66 * on a contact / group of contacts
67 *
68 * @return array
69 * the set of tasks for a group of contacts
70 * @static
71 */
72 public static function &tasks() {
73 if (!(self::$_tasks)) {
74 self::$_tasks = array(
75 1 => array(
76 'title' => ts('Delete Participants'),
77 'class' => 'CRM_Event_Form_Task_Delete',
78 'result' => FALSE,
79 ),
80 2 => array(
81 'title' => ts('Print Selected Rows'),
82 'class' => 'CRM_Event_Form_Task_Print',
83 'result' => FALSE,
84 ),
85 3 => array(
86 'title' => ts('Export Participants'),
87 'class' => array(
88 'CRM_Export_Form_Select',
89 'CRM_Export_Form_Map',
90 ),
91 'result' => FALSE,
92 ),
93 4 => array(
94 'title' => ts('Batch Update Participants Via Profile'),
95 'class' => array(
96 'CRM_Event_Form_Task_PickProfile',
97 'CRM_Event_Form_Task_Batch',
98 ),
99 'result' => TRUE,
100 ),
101 5 => array(
102 'title' => ts('Cancel Registration'),
103 'class' => 'CRM_Event_Form_Task_Cancel',
104 'result' => FALSE,
105 ),
106 6 => array(
107 'title' => ts('Send Email to Contacts'),
108 'class' => 'CRM_Event_Form_Task_Email',
109 'result' => TRUE,
110 ),
111 13 => array(
112 'title' => ts('New Smart Group'),
113 'class' => 'CRM_Event_Form_Task_SaveSearch',
114 'result' => TRUE,
115 ),
116 14 => array(
117 'title' => ts('Update Smart Group'),
118 'class' => 'CRM_Event_Form_Task_SaveSearch_Update',
119 'result' => TRUE,
120 ),
121 15 => array(
122 'title' => ts('Change Participant Status'),
123 'class' => 'CRM_Event_Form_Task_ParticipantStatus',
124 'result' => TRUE,
125 ),
126 16 => array(
127 'title' => ts('Print Event Name Badges'),
128 'class' => 'CRM_Event_Form_Task_Badge',
129 'result' => FALSE,
130 ),
131 20 => array(
132 'title' => ts('Add Contacts to Group'),
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[1]);
141 }
142 //CRM-12920 - check for edit permission
143 if (!CRM_Core_Permission::check('edit event participants')) {
144 unset(self::$_tasks[4], self::$_tasks[5], self::$_tasks[15]);
145 }
146 }
147
148 CRM_Utils_Hook::searchTasks('event', self::$_tasks);
149 asort(self::$_tasks);
150 return self::$_tasks;
151 }
152
153 /**
154 * These tasks are the core set of task titles
155 * for participants
156 *
157 * @return array
158 * the set of task titles
159 * @static
160 */
161 public static function &taskTitles() {
162 self::tasks();
163 $titles = array();
164 foreach (self::$_tasks as $id => $value) {
165 // skip Update Smart Group task
166 if ($id != self::SAVE_SEARCH_UPDATE) {
167 $titles[$id] = $value['title'];
168 }
169 }
170 return $titles;
171 }
172
173 /**
174 * These tasks get added based on the context the user is in
175 *
176 * @return array
177 * the set of optional tasks for a group of contacts
178 * @static
179 */
180 public static function &optionalTaskTitle() {
181 $tasks = array(
182 14 => self::$_tasks[14]['title'],
183 );
184 return $tasks;
185 }
186
187 /**
188 * Show tasks selectively based on the permission level
189 * of the user
190 *
191 * @param int $permission
192 *
193 * @return array
194 * set of tasks that are valid for the user
195 */
196 public static function &permissionedTaskTitles($permission) {
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 *
223 * @return array
224 * the set of tasks for a group of participants
225 * @static
226 */
227 public static function getTask($value) {
228 self::tasks();
229 if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) {
230 // make the print task by default
231 $value = 2;
232 }
233 return array(
234 self::$_tasks[$value]['class'],
235 self::$_tasks[$value]['result'],
236 );
237 }
238 }