more comment fixes
[civicrm-core.git] / CRM / Activity / Task.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2015
32 */
33
34 /**
35 * Class to represent the actions that can be performed on a group of contacts used by the search forms.
36 */
37 class CRM_Activity_Task {
38 const
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 /**
47 * The task array.
48 *
49 * @var array
50 */
51 static $_tasks = NULL;
52
53 /**
54 * The optional task array.
55 *
56 * @var array
57 */
58 static $_optionalTasks = NULL;
59
60 /**
61 * These tasks are the core set of tasks that the user can perform.
62 * on a contact / group of contacts
63 *
64 * @return array
65 * the set of tasks for a group of contacts
66 */
67 public static function &tasks() {
68 if (!(self::$_tasks)) {
69 self::$_tasks = array(
70 1 => array(
71 'title' => ts('Delete Activities'),
72 'class' => 'CRM_Activity_Form_Task_Delete',
73 'result' => FALSE,
74 ),
75 2 => array(
76 'title' => ts('Print Selected Rows'),
77 'class' => 'CRM_Activity_Form_Task_Print',
78 'result' => FALSE,
79 ),
80 3 => array(
81 'title' => ts('Export Activities'),
82 'class' => array(
83 'CRM_Export_Form_Select',
84 'CRM_Export_Form_Map',
85 ),
86 'result' => FALSE,
87 ),
88 4 => array(
89 'title' => ts('Batch Update Activities Via Profile'),
90 'class' => array(
91 'CRM_Activity_Form_Task_PickProfile',
92 'CRM_Activity_Form_Task_Batch',
93 ),
94 'result' => FALSE,
95 ),
96 5 => array(
97 'title' => ts('Send Email to Contacts'),
98 'class' => array(
99 'CRM_Activity_Form_Task_PickOption',
100 'CRM_Activity_Form_Task_Email',
101 ),
102 'result' => FALSE,
103 ),
104 6 => array(
105 'title' => ts('Send Reply SMS To Contacts'),
106 'class' => 'CRM_Activity_Form_Task_SMS',
107 'result' => FALSE,
108 ),
109 7 => array(
110 'title' => ts('Tag Activities (assign tags)'),
111 'class' => 'CRM_Activity_Form_Task_AddToTag',
112 'result' => FALSE,
113 ),
114 8 => array(
115 'title' => ts('Untag Activities (remove tags)'),
116 'class' => 'CRM_Activity_Form_Task_RemoveFromTag',
117 'result' => FALSE,
118 ),
119 );
120
121 $config = CRM_Core_Config::singleton();
122 if (in_array('CiviCase', $config->enableComponents)) {
123 if (CRM_Core_Permission::check('access all cases and activities') ||
124 CRM_Core_Permission::check('access my cases and activities')
125 ) {
126 self::$_tasks[6] = array(
127 'title' => ts('File on Case'),
128 'class' => 'CRM_Activity_Form_Task_FileOnCase',
129 'result' => FALSE,
130 );
131 }
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 /**
145 * These tasks are the core set of task titles.
146 * on activity
147 *
148 * @return array
149 * the set of task titles
150 */
151 public static function &taskTitles() {
152 self::tasks();
153 $titles = array();
154 foreach (self::$_tasks as $id => $value) {
155 $titles[$id] = $value['title'];
156 }
157 return $titles;
158 }
159
160 /**
161 * Show tasks selectively based on the permission level.
162 * of the user
163 *
164 * @param int $permission
165 *
166 * @return array
167 * set of tasks that are valid for the user
168 */
169 public static function &permissionedTaskTitles($permission) {
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 /**
188 * These tasks are the core set of tasks that the user can perform.
189 * on activity
190 *
191 * @param int $value
192 *
193 * @return array
194 * the set of tasks for a group of activity
195 */
196 public static function getTask($value) {
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 }
207
208 }