add filter based on entity types for profile builder
[civicrm-core.git] / CRM / Activity / Task.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
232624b1 4 | CiviCRM version 4.4 |
6a488035
TO
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
31 * $Id$
32 *
33 */
34
35/**
36 * class to represent the actions that can be performed on a group of contacts
37 * used by the search forms
38 *
39 */
40class CRM_Activity_Task {
41 CONST
42 DELETE_ACTIVITIES = 1,
43 PRINT_ACTIVITIES = 2,
44 EXPORT_ACTIVITIES = 3,
45 BATCH_ACTIVITIES = 4,
46 EMAIL_CONTACTS = 5,
47 EMAIL_SMS = 6;
48
49 /**
50 * the task array
51 *
52 * @var array
53 * @static
54 */
55 static $_tasks = NULL;
56
57 /**
58 * the optional task array
59 *
60 * @var array
61 * @static
62 */
63 static $_optionalTasks = NULL;
64
65 /**
66 * These tasks are the core set of tasks that the user can perform
67 * on a contact / group of contacts
68 *
69 * @return array the set of tasks for a group of contacts
70 * @static
71 * @access public
72 */
73 static function &tasks() {
74 if (!(self::$_tasks)) {
75 self::$_tasks = array(
76 1 => array('title' => ts('Delete Activities'),
77 'class' => 'CRM_Activity_Form_Task_Delete',
78 'result' => FALSE,
79 ),
80 2 => array('title' => ts('Print Activities'),
81 'class' => 'CRM_Activity_Form_Task_Print',
82 'result' => FALSE,
83 ),
84 3 => array('title' => ts('Export Activities'),
85 'class' => array(
86 'CRM_Export_Form_Select',
87 'CRM_Export_Form_Map',
88 ),
89 'result' => FALSE,
90 ),
91 4 => array('title' => ts('Batch Update Activities Via Profile'),
92 'class' => array(
93 'CRM_Activity_Form_Task_PickProfile',
94 'CRM_Activity_Form_Task_Batch',
95 ),
96 'result' => FALSE,
97 ),
98 5 => array('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('title' => ts('Send Reply SMS To Contacts'),
106 'class' => 'CRM_Activity_Form_Task_SMS',
107 'result' => FALSE,
108 ),
f70ca446
PN
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 ),
6a488035
TO
119 );
120
121 $config = CRM_Core_Config::singleton();
122 if (in_array('CiviCase', $config->enableComponents)) {
bbfeec41
BS
123 if ( CRM_Core_Permission::check('access all cases and activities') ||
124 CRM_Core_Permission::check('access my cases and activities') ) {
125 self::$_tasks[6] = array('title' => ts('File on Case'),
126 'class' => 'CRM_Activity_Form_Task_FileOnCase',
127 'result' => FALSE,
128 );
129 }
6a488035
TO
130 }
131
132 //CRM-4418, check for delete
133 if (!CRM_Core_Permission::check('delete activities')) {
134 unset(self::$_tasks[1]);
135 }
136 }
137 CRM_Utils_Hook::searchTasks('activity', self::$_tasks);
138 asort(self::$_tasks);
139 return self::$_tasks;
140 }
141
142 /**
143 * These tasks are the core set of task titles
144 * on activity
145 *
146 * @return array the set of task titles
147 * @static
148 * @access public
149 */
150 static function &taskTitles() {
151 self::tasks();
152 $titles = array();
153 foreach (self::$_tasks as $id => $value) {
154 // skip Print Activity task
155 if ($id != 2) {
156 $titles[$id] = $value['title'];
157 }
158 }
159 return $titles;
160 }
161
162 /**
163 * show tasks selectively based on the permission level
164 * of the user
165 *
166 * @param int $permission
167 *
168 * @return array set of tasks that are valid for the user
169 * @access public
170 */
171 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
191 * on activity
192 *
193 * @param int $value
194 *
195 * @return array the set of tasks for a group of activity
196 * @static
197 * @access public
198 */
199 static function getTask($value) {
200 self::tasks();
201 if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) {
202 // make the print task by default
203 $value = 2;
204 }
205 return array(
206 self::$_tasks[$value]['class'],
207 self::$_tasks[$value]['result'],
208 );
209 }
210}
211