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 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 abstract public static function permissionedTaskTitles($permission, $params);
135 * Show tasks selectively based on the permission level
137 * This function should be called by permissionedTaskTitles in children
139 * @param array $tasks The array of tasks generated by permissionedTaskTitles
140 * @param int $permission
141 * @param array $params
142 * "ssID: Saved Search ID": If !empty we are in saved search context
145 * set of tasks that are valid for the user
147 public static function corePermissionedTaskTitles($tasks, $permission, $params) {
148 // Only offer the "Update Smart Group" task if a smart group/saved search is already in play and we have edit permissions
149 if (!empty($params['ssID']) && ($permission == CRM_Core_Permission
::EDIT
)) {
150 $tasks[self
::SAVE_SEARCH_UPDATE
] = self
::$_tasks[self
::SAVE_SEARCH_UPDATE
]['title'];
153 unset($tasks[self
::SAVE_SEARCH_UPDATE
]);
161 * These tasks are the core set of tasks that the user can perform
167 * the set of tasks for a group of participants
169 public static function getTask($value) {
172 if (!CRM_Utils_Array
::value($value, self
::$_tasks)) {
173 // Children can specify a default task (eg. print), we don't here
177 CRM_Utils_Array
::value('class', self
::$_tasks[$value]),
178 CRM_Utils_Array
::value('result', self
::$_tasks[$value]),
183 * Function to return the task information on basis of provided task's form name
185 * @param string $className
187 * @return array [ 0 => Task ID, 1 => Task Title ]
189 public static function getTaskAndTitleByClass($className) {
192 foreach (self
::$_tasks as $task => $value) {
193 if ((!empty($value['url']) ||
$task == self
::TASK_EXPORT
)
194 && ((is_array($value['class']) && in_array($className, $value['class']))
195 ||
($value['class'] == $className))) {
196 return array($task, CRM_Utils_Array
::value('title', $value));