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. | | |
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 along with this program; if not, contact CiviCRM LLC | | |
21 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
22 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
23 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
24 | +--------------------------------------------------------------------+ | |
25 | */ | |
26 | ||
27 | /** | |
28 | * | |
29 | * @package CRM | |
06b69b18 | 30 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
31 | * $Id$ |
32 | * | |
33 | */ | |
34 | ||
35 | /** | |
36 | * class to represent the actions that can be performed on a group of contacts | |
37 | * used by the search forms | |
38 | * | |
39 | */ | |
40 | class CRM_Activity_Task { | |
7da04cde | 41 | const |
6a488035 TO |
42 | DELETE_ACTIVITIES = 1, |
43 | PRINT_ACTIVITIES = 2, | |
44 | EXPORT_ACTIVITIES = 3, | |
45 | BATCH_ACTIVITIES = 4, | |
46 | EMAIL_CONTACTS = 5, | |
47 | EMAIL_SMS = 6; | |
48 | ||
49 | /** | |
100fef9d | 50 | * The task array |
6a488035 TO |
51 | * |
52 | * @var array | |
53 | * @static | |
54 | */ | |
55 | static $_tasks = NULL; | |
56 | ||
57 | /** | |
100fef9d | 58 | * The optional task array |
6a488035 TO |
59 | * |
60 | * @var array | |
61 | * @static | |
62 | */ | |
63 | static $_optionalTasks = NULL; | |
64 | ||
65 | /** | |
66 | * These tasks are the core set of tasks that the user can perform | |
67 | * on a contact / group of contacts | |
68 | * | |
a6c01b45 CW |
69 | * @return array |
70 | * the set of tasks for a group of contacts | |
6a488035 | 71 | * @static |
6a488035 | 72 | */ |
00be9182 | 73 | public static function &tasks() { |
6a488035 TO |
74 | if (!(self::$_tasks)) { |
75 | self::$_tasks = array( | |
23546577 CW |
76 | 1 => array( |
77 | 'title' => ts('Delete Activities'), | |
6a488035 TO |
78 | 'class' => 'CRM_Activity_Form_Task_Delete', |
79 | 'result' => FALSE, | |
80 | ), | |
23546577 CW |
81 | 2 => array( |
82 | 'title' => ts('Print Selected Rows'), | |
6a488035 TO |
83 | 'class' => 'CRM_Activity_Form_Task_Print', |
84 | 'result' => FALSE, | |
85 | ), | |
23546577 CW |
86 | 3 => array( |
87 | 'title' => ts('Export Activities'), | |
6a488035 TO |
88 | 'class' => array( |
89 | 'CRM_Export_Form_Select', | |
90 | 'CRM_Export_Form_Map', | |
91 | ), | |
92 | 'result' => FALSE, | |
93 | ), | |
23546577 CW |
94 | 4 => array( |
95 | 'title' => ts('Batch Update Activities Via Profile'), | |
6a488035 TO |
96 | 'class' => array( |
97 | 'CRM_Activity_Form_Task_PickProfile', | |
98 | 'CRM_Activity_Form_Task_Batch', | |
99 | ), | |
100 | 'result' => FALSE, | |
101 | ), | |
23546577 CW |
102 | 5 => array( |
103 | 'title' => ts('Send Email to Contacts'), | |
6a488035 TO |
104 | 'class' => array( |
105 | 'CRM_Activity_Form_Task_PickOption', | |
106 | 'CRM_Activity_Form_Task_Email', | |
107 | ), | |
108 | 'result' => FALSE, | |
109 | ), | |
23546577 CW |
110 | 6 => array( |
111 | 'title' => ts('Send Reply SMS To Contacts'), | |
6a488035 TO |
112 | 'class' => 'CRM_Activity_Form_Task_SMS', |
113 | 'result' => FALSE, | |
114 | ), | |
f70ca446 PN |
115 | 7 => array( |
116 | 'title' => ts('Tag Activities (assign tags)'), | |
117 | 'class' => 'CRM_Activity_Form_Task_AddToTag', | |
118 | 'result' => FALSE, | |
119 | ), | |
120 | 8 => array( | |
121 | 'title' => ts('Untag Activities (remove tags)'), | |
122 | 'class' => 'CRM_Activity_Form_Task_RemoveFromTag', | |
123 | 'result' => FALSE, | |
124 | ), | |
6a488035 TO |
125 | ); |
126 | ||
127 | $config = CRM_Core_Config::singleton(); | |
128 | if (in_array('CiviCase', $config->enableComponents)) { | |
481a74f4 | 129 | if (CRM_Core_Permission::check('access all cases and activities') || |
353ffa53 TO |
130 | CRM_Core_Permission::check('access my cases and activities') |
131 | ) { | |
23546577 CW |
132 | self::$_tasks[6] = array( |
133 | 'title' => ts('File on Case'), | |
bbfeec41 BS |
134 | 'class' => 'CRM_Activity_Form_Task_FileOnCase', |
135 | 'result' => FALSE, | |
136 | ); | |
137 | } | |
6a488035 TO |
138 | } |
139 | ||
140 | //CRM-4418, check for delete | |
141 | if (!CRM_Core_Permission::check('delete activities')) { | |
142 | unset(self::$_tasks[1]); | |
143 | } | |
144 | } | |
145 | CRM_Utils_Hook::searchTasks('activity', self::$_tasks); | |
146 | asort(self::$_tasks); | |
147 | return self::$_tasks; | |
148 | } | |
149 | ||
150 | /** | |
151 | * These tasks are the core set of task titles | |
152 | * on activity | |
153 | * | |
a6c01b45 CW |
154 | * @return array |
155 | * the set of task titles | |
6a488035 | 156 | * @static |
6a488035 | 157 | */ |
00be9182 | 158 | public static function &taskTitles() { |
6a488035 TO |
159 | self::tasks(); |
160 | $titles = array(); | |
161 | foreach (self::$_tasks as $id => $value) { | |
e341bbee | 162 | $titles[$id] = $value['title']; |
6a488035 TO |
163 | } |
164 | return $titles; | |
165 | } | |
166 | ||
167 | /** | |
100fef9d | 168 | * Show tasks selectively based on the permission level |
6a488035 TO |
169 | * of the user |
170 | * | |
171 | * @param int $permission | |
172 | * | |
a6c01b45 CW |
173 | * @return array |
174 | * set of tasks that are valid for the user | |
6a488035 | 175 | */ |
00be9182 | 176 | public static function &permissionedTaskTitles($permission) { |
6a488035 TO |
177 | $tasks = array(); |
178 | if ($permission == CRM_Core_Permission::EDIT) { | |
179 | $tasks = self::taskTitles(); | |
180 | } | |
181 | else { | |
182 | $tasks = array( | |
183 | 3 => self::$_tasks[3]['title'], | |
184 | ); | |
185 | ||
186 | //CRM-4418, | |
187 | if (CRM_Core_Permission::check('delete activities')) { | |
188 | $tasks[1] = self::$_tasks[1]['title']; | |
189 | } | |
190 | } | |
191 | return $tasks; | |
192 | } | |
193 | ||
194 | /** | |
195 | * These tasks are the core set of tasks that the user can perform | |
196 | * on activity | |
197 | * | |
198 | * @param int $value | |
199 | * | |
a6c01b45 CW |
200 | * @return array |
201 | * the set of tasks for a group of activity | |
6a488035 | 202 | * @static |
6a488035 | 203 | */ |
00be9182 | 204 | public static function getTask($value) { |
6a488035 TO |
205 | self::tasks(); |
206 | if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) { | |
207 | // make the print task by default | |
208 | $value = 2; | |
209 | } | |
210 | return array( | |
211 | self::$_tasks[$value]['class'], | |
212 | self::$_tasks[$value]['result'], | |
213 | ); | |
214 | } | |
215 | } |