Merge remote-tracking branch 'upstream/4.5' into 4.5-master-2015-02-09-11-44-07
[civicrm-core.git] / CRM / Activity / Task.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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
30 * @copyright CiviCRM LLC (c) 2004-2014
31 * $Id$
32 */
33
34 /**
35 * Class to represent the actions that can be performed on a group of contacts
36 * used by the search forms.
37 */
38 class CRM_Activity_Task {
39 const
40 DELETE_ACTIVITIES = 1,
41 PRINT_ACTIVITIES = 2,
42 EXPORT_ACTIVITIES = 3,
43 BATCH_ACTIVITIES = 4,
44 EMAIL_CONTACTS = 5,
45 EMAIL_SMS = 6;
46
47 /**
48 * The task array.
49 *
50 * @var array
51 */
52 static $_tasks = NULL;
53
54 /**
55 * The optional task array.
56 *
57 * @var array
58 */
59 static $_optionalTasks = NULL;
60
61 /**
62 * These tasks are the core set of tasks that the user can perform.
63 * on a contact / group of contacts
64 *
65 * @return array
66 * the set of tasks for a group of contacts
67 */
68 public static function &tasks() {
69 if (!(self::$_tasks)) {
70 self::$_tasks = array(
71 1 => array(
72 'title' => ts('Delete Activities'),
73 'class' => 'CRM_Activity_Form_Task_Delete',
74 'result' => FALSE,
75 ),
76 2 => array(
77 'title' => ts('Print Selected Rows'),
78 'class' => 'CRM_Activity_Form_Task_Print',
79 'result' => FALSE,
80 ),
81 3 => array(
82 'title' => ts('Export Activities'),
83 'class' => array(
84 'CRM_Export_Form_Select',
85 'CRM_Export_Form_Map',
86 ),
87 'result' => FALSE,
88 ),
89 4 => array(
90 'title' => ts('Batch Update Activities Via Profile'),
91 'class' => array(
92 'CRM_Activity_Form_Task_PickProfile',
93 'CRM_Activity_Form_Task_Batch',
94 ),
95 'result' => FALSE,
96 ),
97 5 => array(
98 'title' => ts('Send Email to Contacts'),
99 'class' => array(
100 'CRM_Activity_Form_Task_PickOption',
101 'CRM_Activity_Form_Task_Email',
102 ),
103 'result' => FALSE,
104 ),
105 6 => array(
106 'title' => ts('Send Reply SMS To Contacts'),
107 'class' => 'CRM_Activity_Form_Task_SMS',
108 'result' => FALSE,
109 ),
110 7 => array(
111 'title' => ts('Tag Activities (assign tags)'),
112 'class' => 'CRM_Activity_Form_Task_AddToTag',
113 'result' => FALSE,
114 ),
115 8 => array(
116 'title' => ts('Untag Activities (remove tags)'),
117 'class' => 'CRM_Activity_Form_Task_RemoveFromTag',
118 'result' => FALSE,
119 ),
120 );
121
122 $config = CRM_Core_Config::singleton();
123 if (in_array('CiviCase', $config->enableComponents)) {
124 if (CRM_Core_Permission::check('access all cases and activities') ||
125 CRM_Core_Permission::check('access my cases and activities')
126 ) {
127 self::$_tasks[6] = array(
128 'title' => ts('File on Case'),
129 'class' => 'CRM_Activity_Form_Task_FileOnCase',
130 'result' => FALSE,
131 );
132 }
133 }
134
135 //CRM-4418, check for delete
136 if (!CRM_Core_Permission::check('delete activities')) {
137 unset(self::$_tasks[1]);
138 }
139 }
140 CRM_Utils_Hook::searchTasks('activity', self::$_tasks);
141 asort(self::$_tasks);
142 return self::$_tasks;
143 }
144
145 /**
146 * These tasks are the core set of task titles.
147 * on activity
148 *
149 * @return array
150 * the set of task titles
151 */
152 public static function &taskTitles() {
153 self::tasks();
154 $titles = array();
155 foreach (self::$_tasks as $id => $value) {
156 $titles[$id] = $value['title'];
157 }
158 return $titles;
159 }
160
161 /**
162 * Show tasks selectively based on the permission level.
163 * of the user
164 *
165 * @param int $permission
166 *
167 * @return array
168 * set of tasks that are valid for the user
169 */
170 public static function &permissionedTaskTitles($permission) {
171 $tasks = array();
172 if ($permission == CRM_Core_Permission::EDIT) {
173 $tasks = self::taskTitles();
174 }
175 else {
176 $tasks = array(
177 3 => self::$_tasks[3]['title'],
178 );
179
180 //CRM-4418,
181 if (CRM_Core_Permission::check('delete activities')) {
182 $tasks[1] = self::$_tasks[1]['title'];
183 }
184 }
185 return $tasks;
186 }
187
188 /**
189 * These tasks are the core set of tasks that the user can perform.
190 * 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 }