Merge pull request #11163 from mickadoo/CRM-21334-fire-hooks-on-contact-image-deletion
[civicrm-core.git] / CRM / Activity / Task.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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 * @package CRM
30 * @copyright CiviCRM LLC (c) 2004-2017
31 */
32
33 /**
34 * Class to represent the actions that can be performed on a group of contacts used by the search forms.
35 */
36 class CRM_Activity_Task {
37 const
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 /**
46 * The task array.
47 *
48 * @var array
49 */
50 static $_tasks = NULL;
51
52 /**
53 * The optional task array.
54 *
55 * @var array
56 */
57 static $_optionalTasks = NULL;
58
59 /**
60 * These tasks are the core set of tasks that the user can perform
61 * on a contact / group of contacts.
62 *
63 * @return array
64 * the set of tasks for a group of contacts
65 */
66 public static function &tasks() {
67 if (!(self::$_tasks)) {
68 self::$_tasks = array(
69 1 => array(
70 'title' => ts('Delete activities'),
71 'class' => 'CRM_Activity_Form_Task_Delete',
72 'result' => FALSE,
73 ),
74 2 => array(
75 'title' => ts('Print selected rows'),
76 'class' => 'CRM_Activity_Form_Task_Print',
77 'result' => FALSE,
78 ),
79 3 => array(
80 'title' => ts('Export activities'),
81 'class' => array(
82 'CRM_Export_Form_Select',
83 'CRM_Export_Form_Map',
84 ),
85 'result' => FALSE,
86 ),
87 4 => array(
88 'title' => ts('Update multiple activities'),
89 'class' => array(
90 'CRM_Activity_Form_Task_PickProfile',
91 'CRM_Activity_Form_Task_Batch',
92 ),
93 'result' => FALSE,
94 ),
95 5 => array(
96 'title' => ts('Email - send now (to %1 or less)', array(
97 1 => Civi::settings()
98 ->get('simple_mail_limit'),
99 )),
100 'class' => array(
101 'CRM_Activity_Form_Task_PickOption',
102 'CRM_Activity_Form_Task_Email',
103 ),
104 'result' => FALSE,
105 ),
106 6 => array(
107 'title' => ts('SMS - send reply'),
108 'class' => 'CRM_Activity_Form_Task_SMS',
109 'result' => FALSE,
110 ),
111 7 => array(
112 'title' => ts('Tag - add to activities'),
113 'class' => 'CRM_Activity_Form_Task_AddToTag',
114 'result' => FALSE,
115 ),
116 8 => array(
117 'title' => ts('Tag - remove from activities'),
118 'class' => 'CRM_Activity_Form_Task_RemoveFromTag',
119 'result' => FALSE,
120 ),
121 );
122
123 $config = CRM_Core_Config::singleton();
124 if (in_array('CiviCase', $config->enableComponents)) {
125 if (CRM_Core_Permission::check('access all cases and activities') ||
126 CRM_Core_Permission::check('access my cases and activities')
127 ) {
128 self::$_tasks[6] = array(
129 'title' => ts('File on case'),
130 'class' => 'CRM_Activity_Form_Task_FileOnCase',
131 'result' => FALSE,
132 );
133 }
134 }
135
136 // CRM-4418, check for delete
137 if (!CRM_Core_Permission::check('delete activities')) {
138 unset(self::$_tasks[1]);
139 }
140
141 CRM_Utils_Hook::searchTasks('activity', self::$_tasks);
142 asort(self::$_tasks);
143 }
144
145 return self::$_tasks;
146 }
147
148 /**
149 * These tasks are the core set of task titles on activity.
150 *
151 * @return array
152 * the set of task titles
153 */
154 public static function &taskTitles() {
155 self::tasks();
156 $titles = array();
157 foreach (self::$_tasks as $id => $value) {
158 $titles[$id] = $value['title'];
159 }
160 return $titles;
161 }
162
163 /**
164 * Show tasks selectively based on the permission level of the user.
165 *
166 * @param int $permission
167 *
168 * @return array
169 * set of tasks that are valid for the user
170 */
171 public static function &permissionedTaskTitles($permission) {
172 $tasks = array();
173 if ($permission == CRM_Core_Permission::EDIT) {
174 $tasks = self::taskTitles();
175 }
176 else {
177 $tasks = array(
178 3 => self::$_tasks[3]['title'],
179 );
180
181 //CRM-4418,
182 if (CRM_Core_Permission::check('delete activities')) {
183 $tasks[1] = self::$_tasks[1]['title'];
184 }
185 }
186 return $tasks;
187 }
188
189 /**
190 * These tasks are the core set of tasks that the user can perform on activity.
191 *
192 * @param int $value
193 *
194 * @return array
195 * the set of tasks for a group of activity
196 */
197 public static function getTask($value) {
198 self::tasks();
199 if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) {
200 // make the print task by default
201 $value = 2;
202 }
203 return array(
204 self::$_tasks[$value]['class'],
205 self::$_tasks[$value]['result'],
206 );
207 }
208
209 }