3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
14 * @copyright CiviCRM LLC https://civicrm.org/licensing
18 * Class to represent the actions that can be performed on a group of contacts used by the search forms.
20 abstract class CRM_Core_Task
{
23 * These constants are only used as enumerators for each of the batch tasks.
26 // General (Implemented by more than one entity)
40 SAVE_SEARCH_UPDATE
= 13,
42 DELETE_PERMANENTLY
= 15,
50 public static $_tasks = NULL;
54 * This must be defined in each child class. It is passed to the searchTasks hook.
55 * Example: $objectType = 'event';
57 public static $objectType = NULL;
60 * Generates a list of batch tasks available for the current entities.
61 * Each child class should populate $_tasks array and then call this parent function for shared functionality.
62 * * @return array The set of tasks for a group of contacts
63 * [ 'title' => The Task title,
64 * 'class' => The Task Form class name,
65 * 'result => Boolean. FIXME: Not sure what this is for
68 public static function tasks() {
69 CRM_Utils_Hook
::searchTasks(static::$objectType, self
::$_tasks);
76 * These tasks are the core set of tasks that the user can perform
77 * on a contact / group of contacts
80 * the set of tasks for a group of contacts
82 public static function taskTitles() {
86 foreach (self
::$_tasks as $id => $value) {
87 $titles[$id] = $value['title'];
90 if (!CRM_Utils_Mail
::validOutBoundMail()) {
91 unset($titles[self
::TASK_EMAIL
]);
92 unset($titles[self
::CREATE_MAILING
]);
95 // Users who do not have 'access deleted contacts' should NOT have the 'Delete Permanently' option in search result tasks
96 if (!CRM_Core_Permission
::check('access deleted contacts') ||
97 !CRM_Core_Permission
::check('delete contacts')
99 unset($titles[self
::DELETE_PERMANENTLY
]);
105 * Show tasks selectively based on the permission level
107 * This function should be overridden by the child class which would normally call parent::corePermissionedTaskTitles
109 * @param int $permission
110 * @param array $params
111 * "ssID: Saved Search ID": If !empty we are in saved search context
114 * set of tasks that are valid for the user
116 public static function permissionedTaskTitles($permission, $params) {
117 return self
::corePermissionedTaskTitles(self
::tasks(), $permission, $params);
121 * Show tasks selectively based on the permission level
123 * This function should be called by permissionedTaskTitles in children
125 * @param array $tasks The array of tasks generated by permissionedTaskTitles
126 * @param int $permission
127 * @param array $params
128 * "ssID: Saved Search ID": If !empty we are in saved search context
131 * set of tasks that are valid for the user
133 public static function corePermissionedTaskTitles($tasks, $permission, $params) {
134 // Only offer the "Update Smart Group" task if a smart group/saved search is already in play and we have edit permissions
135 if (!empty($params['ssID']) && ($permission == CRM_Core_Permission
::EDIT
) && CRM_Core_Permission
::check('edit groups')) {
136 $tasks[self
::SAVE_SEARCH_UPDATE
] = self
::$_tasks[self
::SAVE_SEARCH_UPDATE
]['title'];
139 unset($tasks[self
::SAVE_SEARCH_UPDATE
]);
147 * These tasks are the core set of tasks that the user can perform
153 * the set of tasks for a group of participants
155 public static function getTask($value) {
158 if (empty(self
::$_tasks[$value])) {
159 // Children can specify a default task (eg. print), pick another if it is not valid.
160 $value = key(self
::$_tasks);
163 CRM_Utils_Array
::value('class', self
::$_tasks[$value]),
164 CRM_Utils_Array
::value('result', self
::$_tasks[$value]),
169 * Function to return the task information on basis of provided task's form name
171 * @param string $className
173 * @return array [ 0 => Task ID, 1 => Task Title ]
175 public static function getTaskAndTitleByClass($className) {
178 foreach (self
::$_tasks as $task => $value) {
179 if ((!empty($value['url']) ||
$task == self
::TASK_EXPORT
)
180 && ((is_array($value['class']) && in_array($className, $value['class']))
181 ||
($value['class'] == $className))) {
182 return [$task, CRM_Utils_Array
::value('title', $value)];