3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
30 * @copyright CiviCRM LLC (c) 2004-2017
34 * Class to represent the actions that can be performed on a group of contacts used by the search forms.
36 abstract class CRM_Core_Task
{
39 * These constants are only used as enumerators for each of the batch tasks.
42 // General (Implemented by more than one entity)
56 SAVE_SEARCH_UPDATE
= 13,
58 DELETE_PERMANENTLY
= 15,
66 public static $_tasks = NULL;
70 * This must be defined in each child class. It is passed to the searchTasks hook.
71 * Example: $objectType = 'event';
73 static $objectType = NULL;
76 * Generates a list of batch tasks available for the current entities.
77 * Each child class should populate $_tasks array and then call this parent function for shared functionality.
78 * * @return array The set of tasks for a group of contacts
79 * [ 'title' => The Task title,
80 * 'class' => The Task Form class name,
81 * 'result => Boolean. FIXME: Not sure what this is for
84 public static function tasks() {
85 CRM_Utils_Hook
::searchTasks(self
::$objectType, self
::$_tasks);
92 * These tasks are the core set of tasks that the user can perform
93 * on a contact / group of contacts
96 * the set of tasks for a group of contacts
98 public static function taskTitles() {
102 foreach (self
::$_tasks as $id => $value) {
103 $titles[$id] = $value['title'];
106 if (!CRM_Utils_Mail
::validOutBoundMail()) {
107 unset($titles[self
::TASK_EMAIL
]);
108 unset($titles[self
::CREATE_MAILING
]);
111 // Users who do not have 'access deleted contacts' should NOT have the 'Delete Permanently' option in search result tasks
112 if (!CRM_Core_Permission
::check('access deleted contacts') ||
113 !CRM_Core_Permission
::check('delete contacts')
115 unset($titles[self
::DELETE_PERMANENTLY
]);
121 * Show tasks selectively based on the permission level
123 * This function should be overridden by the child class which would normally call parent::corePermissionedTaskTitles
125 * @param int $permission
126 * @param array $params
127 * "ssID: Saved Search ID": If !empty we are in saved search context
130 * set of tasks that are valid for the user
132 public static function permissionedTaskTitles($permission, $params) {
133 return self
::corePermissionedTaskTitles(self
::tasks(), $permission, $params);
137 * Show tasks selectively based on the permission level
139 * This function should be called by permissionedTaskTitles in children
141 * @param array $tasks The array of tasks generated by permissionedTaskTitles
142 * @param int $permission
143 * @param array $params
144 * "ssID: Saved Search ID": If !empty we are in saved search context
147 * set of tasks that are valid for the user
149 public static function corePermissionedTaskTitles($tasks, $permission, $params) {
150 // Only offer the "Update Smart Group" task if a smart group/saved search is already in play and we have edit permissions
151 if (!empty($params['ssID']) && ($permission == CRM_Core_Permission
::EDIT
)) {
152 $tasks[self
::SAVE_SEARCH_UPDATE
] = self
::$_tasks[self
::SAVE_SEARCH_UPDATE
]['title'];
155 unset($tasks[self
::SAVE_SEARCH_UPDATE
]);
163 * These tasks are the core set of tasks that the user can perform
169 * the set of tasks for a group of participants
171 public static function getTask($value) {
174 if (!CRM_Utils_Array
::value($value, self
::$_tasks)) {
175 // Children can specify a default task (eg. print), we don't here
179 CRM_Utils_Array
::value('class', self
::$_tasks[$value]),
180 CRM_Utils_Array
::value('result', self
::$_tasks[$value]),
185 * Function to return the task information on basis of provided task's form name
187 * @param string $className
189 * @return array [ 0 => Task ID, 1 => Task Title ]
191 public static function getTaskAndTitleByClass($className) {
194 foreach (self
::$_tasks as $task => $value) {
195 if ((!empty($value['url']) ||
$task == self
::TASK_EXPORT
)
196 && ((is_array($value['class']) && in_array($className, $value['class']))
197 ||
($value['class'] == $className))) {
198 return array($task, CRM_Utils_Array
::value('title', $value));