Merge pull request #15843 from totten/master-simplehead
[civicrm-core.git] / CRM / Grant / Task.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 * $Id$
17 *
18 */
19
20 /**
21 * class to represent the actions that can be performed on a group of contacts
22 * used by the search forms
23 *
24 */
25 class CRM_Grant_Task extends CRM_Core_Task {
26
27 /**
28 * Grant Tasks
29 */
30 const UPDATE_GRANTS = 701;
31
32 /**
33 * @var string
34 */
35 public static $objectType = 'grant';
36
37 /**
38 * These tasks are the core set of tasks that the user can perform
39 * on a contact / group of contacts
40 *
41 * @return array
42 * the set of tasks for a group of contacts
43 */
44 public static function tasks() {
45 if (!(self::$_tasks)) {
46 self::$_tasks = [
47 self::TASK_DELETE => [
48 'title' => ts('Delete grants'),
49 'class' => 'CRM_Grant_Form_Task_Delete',
50 'result' => FALSE,
51 ],
52 self::TASK_PRINT => [
53 'title' => ts('Print selected rows'),
54 'class' => 'CRM_Grant_Form_Task_Print',
55 'result' => FALSE,
56 ],
57 self::TASK_EXPORT => [
58 'title' => ts('Export grants'),
59 'class' => [
60 'CRM_Export_Form_Select',
61 'CRM_Export_Form_Map',
62 ],
63 'result' => FALSE,
64 ],
65 self::UPDATE_GRANTS => [
66 'title' => ts('Update grants'),
67 'class' => 'CRM_Grant_Form_Task_Update',
68 'result' => FALSE,
69 ],
70 ];
71
72 if (!CRM_Core_Permission::check('delete in CiviGrant')) {
73 unset(self::$_tasks[self::TASK_DELETE]);
74 }
75
76 parent::tasks();
77 }
78
79 return self::$_tasks;
80 }
81
82 /**
83 * Show tasks selectively based on the permission level
84 * of the user
85 *
86 * @param int $permission
87 * @param array $params
88 *
89 * @return array
90 * set of tasks that are valid for the user
91 */
92 public static function permissionedTaskTitles($permission, $params = []) {
93 if (($permission == CRM_Core_Permission::EDIT)
94 || CRM_Core_Permission::check('edit grants')
95 ) {
96 $tasks = self::taskTitles();
97 }
98 else {
99 $tasks = [
100 self::TASK_EXPORT => self::$_tasks[self::TASK_EXPORT]['title'],
101 ];
102 //CRM-4418,
103 if (CRM_Core_Permission::check('delete in CiviGrant')) {
104 $tasks[self::TASK_DELETE] = self::$_tasks[self::TASK_DELETE]['title'];
105 }
106 }
107
108 $tasks = parent::corePermissionedTaskTitles($tasks, $permission, $params);
109 return $tasks;
110 }
111
112 /**
113 * These tasks are the core set of tasks that the user can perform
114 *
115 * @param int $value
116 *
117 * @return array
118 * the set of tasks for a group of contacts
119 */
120 public static function getTask($value) {
121 self::tasks();
122
123 if (!CRM_Utils_Array::value($value, self::$_tasks)) {
124 // make it the print task by default
125 $value = self::TASK_PRINT;
126 }
127 return parent::getTask($value);
128 }
129
130 }