Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
fa938177 | 6 | | Copyright CiviCRM LLC (c) 2004-2016 | |
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 | | |
c73475ea | 12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | |
6a488035 TO |
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 | | |
c73475ea WA |
20 | | License and the CiviCRM Licensing Exception along | |
21 | | with this program; if not, contact CiviCRM LLC | | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
6a488035 | 29 | * @package CRM |
fa938177 | 30 | * @copyright CiviCRM LLC (c) 2004-2016 |
6a488035 TO |
31 | */ |
32 | ||
33 | /** | |
3819f101 | 34 | * Class to represent the actions that can be performed on a group of contacts used by the search forms. |
6a488035 TO |
35 | */ |
36 | class CRM_Activity_Task { | |
7da04cde | 37 | const |
6a488035 TO |
38 | DELETE_ACTIVITIES = 1, |
39 | PRINT_ACTIVITIES = 2, | |
40 | EXPORT_ACTIVITIES = 3, | |
41 | BATCH_ACTIVITIES = 4, | |
42 | EMAIL_CONTACTS = 5, | |
43 | EMAIL_SMS = 6; | |
44 | ||
45 | /** | |
fe482240 | 46 | * The task array. |
6a488035 TO |
47 | * |
48 | * @var array | |
6a488035 TO |
49 | */ |
50 | static $_tasks = NULL; | |
51 | ||
52 | /** | |
fe482240 | 53 | * The optional task array. |
6a488035 TO |
54 | * |
55 | * @var array | |
6a488035 TO |
56 | */ |
57 | static $_optionalTasks = NULL; | |
58 | ||
59 | /** | |
7808aae6 SB |
60 | * These tasks are the core set of tasks that the user can perform |
61 | * on a contact / group of contacts. | |
6a488035 | 62 | * |
a6c01b45 CW |
63 | * @return array |
64 | * the set of tasks for a group of contacts | |
6a488035 | 65 | */ |
00be9182 | 66 | public static function &tasks() { |
6a488035 TO |
67 | if (!(self::$_tasks)) { |
68 | self::$_tasks = array( | |
23546577 | 69 | 1 => array( |
7f82e636 | 70 | 'title' => ts('Delete activities'), |
6a488035 TO |
71 | 'class' => 'CRM_Activity_Form_Task_Delete', |
72 | 'result' => FALSE, | |
73 | ), | |
23546577 | 74 | 2 => array( |
7f82e636 | 75 | 'title' => ts('Print selected rows'), |
6a488035 TO |
76 | 'class' => 'CRM_Activity_Form_Task_Print', |
77 | 'result' => FALSE, | |
78 | ), | |
23546577 | 79 | 3 => array( |
7f82e636 | 80 | 'title' => ts('Export activities'), |
6a488035 TO |
81 | 'class' => array( |
82 | 'CRM_Export_Form_Select', | |
83 | 'CRM_Export_Form_Map', | |
84 | ), | |
85 | 'result' => FALSE, | |
86 | ), | |
23546577 | 87 | 4 => array( |
b581842f | 88 | 'title' => ts('Update multiple activities'), |
6a488035 TO |
89 | 'class' => array( |
90 | 'CRM_Activity_Form_Task_PickProfile', | |
91 | 'CRM_Activity_Form_Task_Batch', | |
92 | ), | |
93 | 'result' => FALSE, | |
94 | ), | |
23546577 | 95 | 5 => array( |
7f82e636 | 96 | 'title' => ts('Email - send now'), |
6a488035 TO |
97 | 'class' => array( |
98 | 'CRM_Activity_Form_Task_PickOption', | |
99 | 'CRM_Activity_Form_Task_Email', | |
100 | ), | |
101 | 'result' => FALSE, | |
102 | ), | |
23546577 | 103 | 6 => array( |
7f82e636 | 104 | 'title' => ts('SMS - send reply'), |
6a488035 TO |
105 | 'class' => 'CRM_Activity_Form_Task_SMS', |
106 | 'result' => FALSE, | |
107 | ), | |
f70ca446 | 108 | 7 => array( |
7f82e636 | 109 | 'title' => ts('Tag - add to activities'), |
f70ca446 PN |
110 | 'class' => 'CRM_Activity_Form_Task_AddToTag', |
111 | 'result' => FALSE, | |
112 | ), | |
113 | 8 => array( | |
7f82e636 | 114 | 'title' => ts('Tag - remove from activities'), |
f70ca446 PN |
115 | 'class' => 'CRM_Activity_Form_Task_RemoveFromTag', |
116 | 'result' => FALSE, | |
117 | ), | |
6a488035 TO |
118 | ); |
119 | ||
120 | $config = CRM_Core_Config::singleton(); | |
121 | if (in_array('CiviCase', $config->enableComponents)) { | |
481a74f4 | 122 | if (CRM_Core_Permission::check('access all cases and activities') || |
353ffa53 TO |
123 | CRM_Core_Permission::check('access my cases and activities') |
124 | ) { | |
23546577 | 125 | self::$_tasks[6] = array( |
7f82e636 | 126 | 'title' => ts('File on case'), |
bbfeec41 BS |
127 | 'class' => 'CRM_Activity_Form_Task_FileOnCase', |
128 | 'result' => FALSE, | |
129 | ); | |
130 | } | |
6a488035 TO |
131 | } |
132 | ||
7808aae6 | 133 | // CRM-4418, check for delete |
6a488035 TO |
134 | if (!CRM_Core_Permission::check('delete activities')) { |
135 | unset(self::$_tasks[1]); | |
136 | } | |
137 | } | |
138 | CRM_Utils_Hook::searchTasks('activity', self::$_tasks); | |
139 | asort(self::$_tasks); | |
140 | return self::$_tasks; | |
141 | } | |
142 | ||
143 | /** | |
7808aae6 | 144 | * These tasks are the core set of task titles on activity. |
6a488035 | 145 | * |
a6c01b45 CW |
146 | * @return array |
147 | * the set of task titles | |
6a488035 | 148 | */ |
00be9182 | 149 | public static function &taskTitles() { |
6a488035 TO |
150 | self::tasks(); |
151 | $titles = array(); | |
152 | foreach (self::$_tasks as $id => $value) { | |
e341bbee | 153 | $titles[$id] = $value['title']; |
6a488035 TO |
154 | } |
155 | return $titles; | |
156 | } | |
157 | ||
158 | /** | |
7808aae6 | 159 | * Show tasks selectively based on the permission level of the user. |
6a488035 TO |
160 | * |
161 | * @param int $permission | |
162 | * | |
a6c01b45 CW |
163 | * @return array |
164 | * set of tasks that are valid for the user | |
6a488035 | 165 | */ |
00be9182 | 166 | public static function &permissionedTaskTitles($permission) { |
6a488035 TO |
167 | $tasks = array(); |
168 | if ($permission == CRM_Core_Permission::EDIT) { | |
169 | $tasks = self::taskTitles(); | |
170 | } | |
171 | else { | |
172 | $tasks = array( | |
173 | 3 => self::$_tasks[3]['title'], | |
174 | ); | |
175 | ||
176 | //CRM-4418, | |
177 | if (CRM_Core_Permission::check('delete activities')) { | |
178 | $tasks[1] = self::$_tasks[1]['title']; | |
179 | } | |
180 | } | |
181 | return $tasks; | |
182 | } | |
183 | ||
184 | /** | |
7808aae6 | 185 | * These tasks are the core set of tasks that the user can perform on activity. |
6a488035 TO |
186 | * |
187 | * @param int $value | |
188 | * | |
a6c01b45 CW |
189 | * @return array |
190 | * the set of tasks for a group of activity | |
6a488035 | 191 | */ |
00be9182 | 192 | public static function getTask($value) { |
6a488035 TO |
193 | self::tasks(); |
194 | if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) { | |
195 | // make the print task by default | |
196 | $value = 2; | |
197 | } | |
198 | return array( | |
199 | self::$_tasks[$value]['class'], | |
200 | self::$_tasks[$value]['result'], | |
201 | ); | |
202 | } | |
96025800 | 203 | |
6a488035 | 204 | } |