Merge pull request #4820 from kurund/CRM-15705
[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 the set of tasks for a group of contacts
69 * @static
70 */
71 public static function &tasks() {
72 if (!(self::$_tasks)) {
73 self::$_tasks = array(1 => array(
74 'title' => ts('Delete Participants'),
75 'class' => 'CRM_Event_Form_Task_Delete',
76 'result' => FALSE,
77 ),
78 2 => array(
79 'title' => ts('Print Selected Rows'),
80 'class' => 'CRM_Event_Form_Task_Print',
81 'result' => FALSE,
82 ),
83 3 => array(
84 'title' => ts('Export Participants'),
85 'class' => array(
86 'CRM_Export_Form_Select',
87 'CRM_Export_Form_Map',
88 ),
89 'result' => FALSE,
90 ),
91 4 => array(
92 'title' => ts('Batch Update Participants Via Profile'),
93 'class' => array(
94 'CRM_Event_Form_Task_PickProfile',
95 'CRM_Event_Form_Task_Batch',
96 ),
97 'result' => TRUE,
98 ),
99 5 => array(
100 'title' => ts('Cancel Registration'),
101 'class' => 'CRM_Event_Form_Task_Cancel',
102 'result' => FALSE,
103 ),
104 6 => array(
105 'title' => ts('Send Email to Contacts'),
106 'class' => 'CRM_Event_Form_Task_Email',
107 'result' => TRUE,
108 ),
109 13 => array(
110 'title' => ts('New Smart Group'),
111 'class' => 'CRM_Event_Form_Task_SaveSearch',
112 'result' => TRUE,
113 ),
114 14 => array(
115 'title' => ts('Update Smart Group'),
116 'class' => 'CRM_Event_Form_Task_SaveSearch_Update',
117 'result' => TRUE,
118 ),
119 15 => array(
120 'title' => ts('Change Participant Status'),
121 'class' => 'CRM_Event_Form_Task_ParticipantStatus',
122 'result' => TRUE,
123 ),
124 16 => array(
125 'title' => ts('Print Event Name Badges'),
126 'class' => 'CRM_Event_Form_Task_Badge',
127 'result' => FALSE,
128 ),
129 20 => array(
130 'title' => ts('Add Contacts to Group'),
131 'class' => 'CRM_Event_Form_Task_AddToGroup',
132 'result' => FALSE,
133 ),
134 );
135
136 //CRM-4418, check for delete
137 if (!CRM_Core_Permission::check('delete in CiviEvent')) {
138 unset(self::$_tasks[1]);
139 }
140 //CRM-12920 - check for edit permission
141 if( !CRM_Core_Permission::check('edit event participants') ){
142 unset(self::$_tasks[4],self::$_tasks[5],self::$_tasks[15]);
143 }
144 }
145
146 CRM_Utils_Hook::searchTasks('event', self::$_tasks);
147 asort(self::$_tasks);
148 return self::$_tasks;
149 }
150
151 /**
152 * These tasks are the core set of task titles
153 * for participants
154 *
155 * @return array the set of task titles
156 * @static
157 */
158 public static function &taskTitles() {
159 self::tasks();
160 $titles = array();
161 foreach (self::$_tasks as $id => $value) {
162 // skip Update Smart Group task
163 if ($id != self::SAVE_SEARCH_UPDATE) {
164 $titles[$id] = $value['title'];
165 }
166 }
167 return $titles;
168 }
169
170 /**
171 * These tasks get added based on the context the user is in
172 *
173 * @return array the set of optional tasks for a group of contacts
174 * @static
175 */
176 public static function &optionalTaskTitle() {
177 $tasks = array(
178 14 => self::$_tasks[14]['title'],
179 );
180 return $tasks;
181 }
182
183 /**
184 * Show tasks selectively based on the permission level
185 * of the user
186 *
187 * @param int $permission
188 *
189 * @return array set of tasks that are valid for the user
190 */
191 public static function &permissionedTaskTitles($permission) {
192 $tasks = array();
193 if (($permission == CRM_Core_Permission::EDIT)
194 || CRM_Core_Permission::check('edit event participants')
195 ) {
196 $tasks = self::taskTitles();
197 }
198 else {
199 $tasks = array(
200 3 => self::$_tasks[3]['title'],
201 6 => self::$_tasks[6]['title'],
202 );
203
204 //CRM-4418,
205 if (CRM_Core_Permission::check('delete in CiviEvent')) {
206 $tasks[1] = self::$_tasks[1]['title'];
207 }
208 }
209 return $tasks;
210 }
211
212 /**
213 * These tasks are the core set of tasks that the user can perform
214 * on participants
215 *
216 * @param int $value
217 *
218 * @return array the set of tasks for a group of participants
219 * @static
220 */
221 public static function getTask($value) {
222 self::tasks();
223 if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) {
224 // make the print task by default
225 $value = 2;
226 }
227 return array(
228 self::$_tasks[$value]['class'],
229 self::$_tasks[$value]['result'],
230 );
231 }
232 }