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