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