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