diff --git a/CRM/Core/Task.php b/CRM/Core/Task.php new file mode 100644 index 000000000000..1aed1bf970a0 --- /dev/null +++ b/CRM/Core/Task.php @@ -0,0 +1,184 @@ + $value) { + $titles[$id] = $value['title']; + } + + if (!CRM_Utils_Mail::validOutBoundMail()) { + unset($titles[self::EMAIL]); + unset($titles[self::CREATE_MAILING]); + } + + // CRM-6806 + 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 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 + */ + abstract public static function permissionedTaskTitles($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)) { + $tasks[self::SAVE_SEARCH_UPDATE] = self::$_tasks[self::SAVE_SEARCH_UPDATE]['title']; + } + else { + unset($tasks[self::SAVE_SEARCH_UPDATE]); + } + + asort($tasks); + return $tasks; + } + + /** + * @param $value + * + * @return array + */ + public static function getTask($value) { + static::tasks(); + + if (!CRM_Utils_Array::value($value, self::$_tasks)) { + // Children can specify a default task (eg. print), we don't here + return array(); + } + return array( + CRM_Utils_Array::value('class', self::$_tasks[$value]), + CRM_Utils_Array::value('result', self::$_tasks[$value]), + ); + } + + /** + * Function to return the task information on basis of provided task's form name + * + * @param string $className + * + * @return array + */ + public static function getTaskAndTitleByClass($className) { + static::tasks(); + + foreach (self::$_tasks as $task => $value) { + if ((!empty($value['url']) || $task == self::EXPORT) && ( + (is_array($value['class']) && in_array($className, $value['class'])) || + ($value['class'] == $className) + ) + ) { + return array( + $task, + CRM_Utils_Array::value('title', $value), + ); + } + } + } + +}