more-CRM-12274
[civicrm-core.git] / CRM / Activity / Task.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
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 */
40 class 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 ),
109 );
110
111 $config = CRM_Core_Config::singleton();
112 if (in_array('CiviCase', $config->enableComponents)) {
113 self::$_tasks[6] = array('title' => ts('File on Case'),
114 'class' => 'CRM_Activity_Form_Task_FileOnCase',
115 'result' => FALSE,
116 );
117 }
118
119 //CRM-4418, check for delete
120 if (!CRM_Core_Permission::check('delete activities')) {
121 unset(self::$_tasks[1]);
122 }
123 }
124 CRM_Utils_Hook::searchTasks('activity', self::$_tasks);
125 asort(self::$_tasks);
126 return self::$_tasks;
127 }
128
129 /**
130 * These tasks are the core set of task titles
131 * on activity
132 *
133 * @return array the set of task titles
134 * @static
135 * @access public
136 */
137 static function &taskTitles() {
138 self::tasks();
139 $titles = array();
140 foreach (self::$_tasks as $id => $value) {
141 // skip Print Activity task
142 if ($id != 2) {
143 $titles[$id] = $value['title'];
144 }
145 }
146 return $titles;
147 }
148
149 /**
150 * show tasks selectively based on the permission level
151 * of the user
152 *
153 * @param int $permission
154 *
155 * @return array set of tasks that are valid for the user
156 * @access public
157 */
158 static function &permissionedTaskTitles($permission) {
159 $tasks = array();
160 if ($permission == CRM_Core_Permission::EDIT) {
161 $tasks = self::taskTitles();
162 }
163 else {
164 $tasks = array(
165 3 => self::$_tasks[3]['title'],
166 );
167
168 //CRM-4418,
169 if (CRM_Core_Permission::check('delete activities')) {
170 $tasks[1] = self::$_tasks[1]['title'];
171 }
172 }
173 return $tasks;
174 }
175
176 /**
177 * These tasks are the core set of tasks that the user can perform
178 * on activity
179 *
180 * @param int $value
181 *
182 * @return array the set of tasks for a group of activity
183 * @static
184 * @access public
185 */
186 static function getTask($value) {
187 self::tasks();
188 if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) {
189 // make the print task by default
190 $value = 2;
191 }
192 return array(
193 self::$_tasks[$value]['class'],
194 self::$_tasks[$value]['result'],
195 );
196 }
197 }
198