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