Merge pull request #5123 from eileenmcnaughton/CRM-15369
[civicrm-core.git] / CRM / Activity / Task.php
CommitLineData
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 +--------------------------------------------------------------------+
d25dd0ee 25 */
6a488035
TO
26
27/**
28 *
29 * @package CRM
06b69b18 30 * @copyright CiviCRM LLC (c) 2004-2014
6a488035 31 * $Id$
6a488035
TO
32 */
33
34/**
2e2605fe
EM
35 * Class to represent the actions that can be performed on a group of contacts
36 * used by the search forms.
6a488035
TO
37 */
38class CRM_Activity_Task {
7da04cde 39 const
6a488035
TO
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 /**
fe482240 48 * The task array.
6a488035
TO
49 *
50 * @var array
6a488035
TO
51 */
52 static $_tasks = NULL;
53
54 /**
fe482240 55 * The optional task array.
6a488035
TO
56 *
57 * @var array
6a488035
TO
58 */
59 static $_optionalTasks = NULL;
60
61 /**
fe482240 62 * These tasks are the core set of tasks that the user can perform.
6a488035
TO
63 * on a contact / group of contacts
64 *
a6c01b45
CW
65 * @return array
66 * the set of tasks for a group of contacts
6a488035 67 */
00be9182 68 public static function &tasks() {
6a488035
TO
69 if (!(self::$_tasks)) {
70 self::$_tasks = array(
23546577
CW
71 1 => array(
72 'title' => ts('Delete Activities'),
6a488035
TO
73 'class' => 'CRM_Activity_Form_Task_Delete',
74 'result' => FALSE,
75 ),
23546577
CW
76 2 => array(
77 'title' => ts('Print Selected Rows'),
6a488035
TO
78 'class' => 'CRM_Activity_Form_Task_Print',
79 'result' => FALSE,
80 ),
23546577
CW
81 3 => array(
82 'title' => ts('Export Activities'),
6a488035
TO
83 'class' => array(
84 'CRM_Export_Form_Select',
85 'CRM_Export_Form_Map',
86 ),
87 'result' => FALSE,
88 ),
23546577
CW
89 4 => array(
90 'title' => ts('Batch Update Activities Via Profile'),
6a488035
TO
91 'class' => array(
92 'CRM_Activity_Form_Task_PickProfile',
93 'CRM_Activity_Form_Task_Batch',
94 ),
95 'result' => FALSE,
96 ),
23546577
CW
97 5 => array(
98 'title' => ts('Send Email to Contacts'),
6a488035
TO
99 'class' => array(
100 'CRM_Activity_Form_Task_PickOption',
101 'CRM_Activity_Form_Task_Email',
102 ),
103 'result' => FALSE,
104 ),
23546577
CW
105 6 => array(
106 'title' => ts('Send Reply SMS To Contacts'),
6a488035
TO
107 'class' => 'CRM_Activity_Form_Task_SMS',
108 'result' => FALSE,
109 ),
f70ca446
PN
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 ),
6a488035
TO
120 );
121
122 $config = CRM_Core_Config::singleton();
123 if (in_array('CiviCase', $config->enableComponents)) {
481a74f4 124 if (CRM_Core_Permission::check('access all cases and activities') ||
353ffa53
TO
125 CRM_Core_Permission::check('access my cases and activities')
126 ) {
23546577
CW
127 self::$_tasks[6] = array(
128 'title' => ts('File on Case'),
bbfeec41
BS
129 'class' => 'CRM_Activity_Form_Task_FileOnCase',
130 'result' => FALSE,
131 );
132 }
6a488035
TO
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 /**
fe482240 146 * These tasks are the core set of task titles.
6a488035
TO
147 * on activity
148 *
a6c01b45
CW
149 * @return array
150 * the set of task titles
6a488035 151 */
00be9182 152 public static function &taskTitles() {
6a488035
TO
153 self::tasks();
154 $titles = array();
155 foreach (self::$_tasks as $id => $value) {
e341bbee 156 $titles[$id] = $value['title'];
6a488035
TO
157 }
158 return $titles;
159 }
160
161 /**
fe482240 162 * Show tasks selectively based on the permission level.
6a488035
TO
163 * of the user
164 *
165 * @param int $permission
166 *
a6c01b45
CW
167 * @return array
168 * set of tasks that are valid for the user
6a488035 169 */
00be9182 170 public static function &permissionedTaskTitles($permission) {
6a488035
TO
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 /**
fe482240 189 * These tasks are the core set of tasks that the user can perform.
6a488035
TO
190 * on activity
191 *
192 * @param int $value
193 *
a6c01b45
CW
194 * @return array
195 * the set of tasks for a group of activity
6a488035 196 */
00be9182 197 public static function getTask($value) {
6a488035
TO
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 }
96025800 208
6a488035 209}