Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06b69b18 | 4 | | CiviCRM version 4.5 | |
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 { | |
41 | CONST | |
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 | /** | |
50 | * the task array | |
51 | * | |
52 | * @var array | |
53 | * @static | |
54 | */ | |
55 | static $_tasks = NULL; | |
56 | ||
57 | /** | |
58 | * the optional task array | |
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 | |
71 | * @access public | |
72 | */ | |
73 | static function &tasks() { | |
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)) { | |
bbfeec41 BS |
129 | if ( CRM_Core_Permission::check('access all cases and activities') || |
130 | CRM_Core_Permission::check('access my cases and activities') ) { | |
23546577 CW |
131 | self::$_tasks[6] = array( |
132 | 'title' => ts('File on Case'), | |
bbfeec41 BS |
133 | 'class' => 'CRM_Activity_Form_Task_FileOnCase', |
134 | 'result' => FALSE, | |
135 | ); | |
136 | } | |
6a488035 TO |
137 | } |
138 | ||
139 | //CRM-4418, check for delete | |
140 | if (!CRM_Core_Permission::check('delete activities')) { | |
141 | unset(self::$_tasks[1]); | |
142 | } | |
143 | } | |
144 | CRM_Utils_Hook::searchTasks('activity', self::$_tasks); | |
145 | asort(self::$_tasks); | |
146 | return self::$_tasks; | |
147 | } | |
148 | ||
149 | /** | |
150 | * These tasks are the core set of task titles | |
151 | * on activity | |
152 | * | |
153 | * @return array the set of task titles | |
154 | * @static | |
155 | * @access public | |
156 | */ | |
157 | static function &taskTitles() { | |
158 | self::tasks(); | |
159 | $titles = array(); | |
160 | foreach (self::$_tasks as $id => $value) { | |
e341bbee | 161 | $titles[$id] = $value['title']; |
6a488035 TO |
162 | } |
163 | return $titles; | |
164 | } | |
165 | ||
166 | /** | |
167 | * show tasks selectively based on the permission level | |
168 | * of the user | |
169 | * | |
170 | * @param int $permission | |
171 | * | |
172 | * @return array set of tasks that are valid for the user | |
173 | * @access public | |
174 | */ | |
175 | static function &permissionedTaskTitles($permission) { | |
176 | $tasks = array(); | |
177 | if ($permission == CRM_Core_Permission::EDIT) { | |
178 | $tasks = self::taskTitles(); | |
179 | } | |
180 | else { | |
181 | $tasks = array( | |
182 | 3 => self::$_tasks[3]['title'], | |
183 | ); | |
184 | ||
185 | //CRM-4418, | |
186 | if (CRM_Core_Permission::check('delete activities')) { | |
187 | $tasks[1] = self::$_tasks[1]['title']; | |
188 | } | |
189 | } | |
190 | return $tasks; | |
191 | } | |
192 | ||
193 | /** | |
194 | * These tasks are the core set of tasks that the user can perform | |
195 | * on activity | |
196 | * | |
197 | * @param int $value | |
198 | * | |
199 | * @return array the set of tasks for a group of activity | |
200 | * @static | |
201 | * @access public | |
202 | */ | |
203 | static function getTask($value) { | |
204 | self::tasks(); | |
205 | if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) { | |
206 | // make the print task by default | |
207 | $value = 2; | |
208 | } | |
209 | return array( | |
210 | self::$_tasks[$value]['class'], | |
211 | self::$_tasks[$value]['result'], | |
212 | ); | |
213 | } | |
214 | } | |
215 |