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