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 | * | |
69 | * @return array the set of tasks for a group of contacts | |
70 | * @static | |
6a488035 | 71 | */ |
00be9182 | 72 | public static function &tasks() { |
6a488035 TO |
73 | if (!(self::$_tasks)) { |
74 | self::$_tasks = array( | |
23546577 CW |
75 | 1 => array( |
76 | 'title' => ts('Delete Activities'), | |
6a488035 TO |
77 | 'class' => 'CRM_Activity_Form_Task_Delete', |
78 | 'result' => FALSE, | |
79 | ), | |
23546577 CW |
80 | 2 => array( |
81 | 'title' => ts('Print Selected Rows'), | |
6a488035 TO |
82 | 'class' => 'CRM_Activity_Form_Task_Print', |
83 | 'result' => FALSE, | |
84 | ), | |
23546577 CW |
85 | 3 => array( |
86 | 'title' => ts('Export Activities'), | |
6a488035 TO |
87 | 'class' => array( |
88 | 'CRM_Export_Form_Select', | |
89 | 'CRM_Export_Form_Map', | |
90 | ), | |
91 | 'result' => FALSE, | |
92 | ), | |
23546577 CW |
93 | 4 => array( |
94 | 'title' => ts('Batch Update Activities Via Profile'), | |
6a488035 TO |
95 | 'class' => array( |
96 | 'CRM_Activity_Form_Task_PickProfile', | |
97 | 'CRM_Activity_Form_Task_Batch', | |
98 | ), | |
99 | 'result' => FALSE, | |
100 | ), | |
23546577 CW |
101 | 5 => array( |
102 | 'title' => ts('Send Email to Contacts'), | |
6a488035 TO |
103 | 'class' => array( |
104 | 'CRM_Activity_Form_Task_PickOption', | |
105 | 'CRM_Activity_Form_Task_Email', | |
106 | ), | |
107 | 'result' => FALSE, | |
108 | ), | |
23546577 CW |
109 | 6 => array( |
110 | 'title' => ts('Send Reply SMS To Contacts'), | |
6a488035 TO |
111 | 'class' => 'CRM_Activity_Form_Task_SMS', |
112 | 'result' => FALSE, | |
113 | ), | |
f70ca446 PN |
114 | 7 => array( |
115 | 'title' => ts('Tag Activities (assign tags)'), | |
116 | 'class' => 'CRM_Activity_Form_Task_AddToTag', | |
117 | 'result' => FALSE, | |
118 | ), | |
119 | 8 => array( | |
120 | 'title' => ts('Untag Activities (remove tags)'), | |
121 | 'class' => 'CRM_Activity_Form_Task_RemoveFromTag', | |
122 | 'result' => FALSE, | |
123 | ), | |
6a488035 TO |
124 | ); |
125 | ||
126 | $config = CRM_Core_Config::singleton(); | |
127 | if (in_array('CiviCase', $config->enableComponents)) { | |
bbfeec41 BS |
128 | if ( CRM_Core_Permission::check('access all cases and activities') || |
129 | CRM_Core_Permission::check('access my cases and activities') ) { | |
23546577 CW |
130 | self::$_tasks[6] = array( |
131 | 'title' => ts('File on Case'), | |
bbfeec41 BS |
132 | 'class' => 'CRM_Activity_Form_Task_FileOnCase', |
133 | 'result' => FALSE, | |
134 | ); | |
135 | } | |
6a488035 TO |
136 | } |
137 | ||
138 | //CRM-4418, check for delete | |
139 | if (!CRM_Core_Permission::check('delete activities')) { | |
140 | unset(self::$_tasks[1]); | |
141 | } | |
142 | } | |
143 | CRM_Utils_Hook::searchTasks('activity', self::$_tasks); | |
144 | asort(self::$_tasks); | |
145 | return self::$_tasks; | |
146 | } | |
147 | ||
148 | /** | |
149 | * These tasks are the core set of task titles | |
150 | * on activity | |
151 | * | |
152 | * @return array the set of task titles | |
153 | * @static | |
6a488035 | 154 | */ |
00be9182 | 155 | public static function &taskTitles() { |
6a488035 TO |
156 | self::tasks(); |
157 | $titles = array(); | |
158 | foreach (self::$_tasks as $id => $value) { | |
e341bbee | 159 | $titles[$id] = $value['title']; |
6a488035 TO |
160 | } |
161 | return $titles; | |
162 | } | |
163 | ||
164 | /** | |
100fef9d | 165 | * Show tasks selectively based on the permission level |
6a488035 TO |
166 | * of the user |
167 | * | |
168 | * @param int $permission | |
169 | * | |
170 | * @return array set of tasks that are valid for the user | |
6a488035 | 171 | */ |
00be9182 | 172 | public static function &permissionedTaskTitles($permission) { |
6a488035 TO |
173 | $tasks = array(); |
174 | if ($permission == CRM_Core_Permission::EDIT) { | |
175 | $tasks = self::taskTitles(); | |
176 | } | |
177 | else { | |
178 | $tasks = array( | |
179 | 3 => self::$_tasks[3]['title'], | |
180 | ); | |
181 | ||
182 | //CRM-4418, | |
183 | if (CRM_Core_Permission::check('delete activities')) { | |
184 | $tasks[1] = self::$_tasks[1]['title']; | |
185 | } | |
186 | } | |
187 | return $tasks; | |
188 | } | |
189 | ||
190 | /** | |
191 | * These tasks are the core set of tasks that the user can perform | |
192 | * on activity | |
193 | * | |
194 | * @param int $value | |
195 | * | |
196 | * @return array the set of tasks for a group of activity | |
197 | * @static | |
6a488035 | 198 | */ |
00be9182 | 199 | public static function getTask($value) { |
6a488035 TO |
200 | self::tasks(); |
201 | if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) { | |
202 | // make the print task by default | |
203 | $value = 2; | |
204 | } | |
205 | return array( | |
206 | self::$_tasks[$value]['class'], | |
207 | self::$_tasks[$value]['result'], | |
208 | ); | |
209 | } | |
210 | } |