The Task title, * 'class' => The Task Form class name, * 'result => Boolean. FIXME: Not sure what this is for * ] */ public static function tasks() { CRM_Utils_Hook::searchTasks(static::$objectType, self::$_tasks); asort(self::$_tasks); return self::$_tasks; } /** * These tasks are the core set of tasks that the user can perform * on a contact / group of contacts * * @return array * the set of tasks for a group of contacts */ public static function taskTitles() { static::tasks(); $titles = []; foreach (self::$_tasks as $id => $value) { $titles[$id] = $value['title']; } if (!CRM_Utils_Mail::validOutBoundMail()) { unset($titles[self::TASK_EMAIL]); unset($titles[self::CREATE_MAILING]); } // Users who do not have 'access deleted contacts' should NOT have the 'Delete Permanently' option in search result tasks if (!CRM_Core_Permission::check('access deleted contacts') || !CRM_Core_Permission::check('delete contacts') ) { unset($titles[self::DELETE_PERMANENTLY]); } return $titles; } /** * Show tasks selectively based on the permission level * of the user * This function should be overridden by the child class which would normally call parent::corePermissionedTaskTitles * * @param int $permission * @param array $params * "ssID: Saved Search ID": If !empty we are in saved search context * * @return array * set of tasks that are valid for the user */ public static function permissionedTaskTitles($permission, $params) { return self::corePermissionedTaskTitles(self::tasks(), $permission, $params); } /** * Show tasks selectively based on the permission level * of the user * This function should be called by permissionedTaskTitles in children * * @param array $tasks The array of tasks generated by permissionedTaskTitles * @param int $permission * @param array $params * "ssID: Saved Search ID": If !empty we are in saved search context * * @return array * set of tasks that are valid for the user */ public static function corePermissionedTaskTitles($tasks, $permission, $params) { // Only offer the "Update Smart Group" task if a smart group/saved search is already in play and we have edit permissions if (!empty($params['ssID']) && ($permission == CRM_Core_Permission::EDIT) && CRM_Core_Permission::check('edit groups')) { $tasks[self::SAVE_SEARCH_UPDATE] = self::$_tasks[self::SAVE_SEARCH_UPDATE]['title']; } else { unset($tasks[self::SAVE_SEARCH_UPDATE]); } asort($tasks); return $tasks; } /** * These tasks are the core set of tasks that the user can perform * on participants * * @param int $value * * @return array * the set of tasks for a group of participants */ public static function getTask($value) { static::tasks(); if (empty(self::$_tasks[$value])) { // Children can specify a default task (eg. print), pick another if it is not valid. $value = key(self::$_tasks); } return [ CRM_Utils_Array::value('class', self::$_tasks[$value]), CRM_Utils_Array::value('result', self::$_tasks[$value]), ]; } /** * Filter tasks based on the permission key, if available. * * @param array $tasks * @param bool $hasEditContactPermission * Does the user have permission to edit the given contact. Required where * permission to edit the user is required in conjunction with permission * to do the task. * * @return array */ protected static function getTasksFilteredByPermission(array $tasks, bool $hasEditContactPermission): array { foreach ($tasks as $index => $task) { // requires_edit_contact_permission is a (hopefully transient way) of denoting which // tasks need 'edit this contact' on top of the membership permission. if (!empty($task['requires_edit_contact_permission']) && !$hasEditContactPermission) { unset($tasks[$index]); } elseif (!empty($task['permissions']) && !CRM_Core_Permission::check($task['permissions'])) { unset($tasks[$index]); } } return $tasks; } /** * Get task tiles filtered by any declared permissions. * * @param array $tasks * @param bool $hasEditContactPermission * Does the user have permission to edit the given contact. Required where * permission to edit the user is required in conjunction with permission * to do the task. * * @return array */ protected static function getTitlesFilteredByPermission(array $tasks, bool $hasEditContactPermission): array { $availableTasks = self::getTasksFilteredByPermission($tasks, $hasEditContactPermission); $return = []; foreach ($availableTasks as $key => $details) { $return[$key] = $details['title']; } return $return; } /** * Function to return the task information on basis of provided task's form name * * @param string $className * * @return array [ 0 => Task ID, 1 => Task Title ] */ public static function getTaskAndTitleByClass($className) { static::tasks(); foreach (self::$_tasks as $task => $value) { if ((!empty($value['url']) || $task == self::TASK_EXPORT) && ((is_array($value['class']) && in_array($className, $value['class'])) || ($value['class'] == $className))) { return [$task, CRM_Utils_Array::value('title', $value)]; } } return []; } }