Merge pull request #18200 from seamuslee001/5.29
[civicrm-core.git] / CRM / Pledge / 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 * @package CRM
14 * @copyright CiviCRM LLC https://civicrm.org/licensing
15 */
16
17 /**
18 * class to represent the actions that can be performed on a group of contacts
19 * used by the search forms.
20 */
21 class CRM_Pledge_Task extends CRM_Core_Task {
22
23 public static $objectType = 'pledge';
24
25 /**
26 * These tasks are the core set of tasks that the user can perform
27 * on a contact / group of contacts
28 *
29 * @return array
30 * the set of tasks for a group of contacts
31 */
32 public static function tasks() {
33 if (!self::$_tasks) {
34 self::$_tasks = [
35 self::TASK_DELETE => [
36 'title' => ts('Delete pledges'),
37 'class' => 'CRM_Pledge_Form_Task_Delete',
38 'result' => FALSE,
39 ],
40 self::TASK_PRINT => [
41 'title' => ts('Print selected rows'),
42 'class' => 'CRM_Pledge_Form_Task_Print',
43 'result' => FALSE,
44 ],
45 self::TASK_EXPORT => [
46 'title' => ts('Export pledges'),
47 'class' => [
48 'CRM_Export_Form_Select',
49 'CRM_Export_Form_Map',
50 ],
51 'result' => FALSE,
52 ],
53 ];
54
55 // CRM-4418, check for delete
56 if (!CRM_Core_Permission::check('delete in CiviPledge')) {
57 unset(self::$_tasks[self::TASK_DELETE]);
58 }
59
60 parent::tasks();
61 }
62
63 return self::$_tasks;
64 }
65
66 /**
67 * Show tasks selectively based on the permission level
68 * of the user
69 *
70 * @param int $permission
71 * @param array $params
72 *
73 * @return array
74 * set of tasks that are valid for the user
75 */
76 public static function permissionedTaskTitles($permission, $params = []) {
77 if (($permission == CRM_Core_Permission::EDIT)
78 || CRM_Core_Permission::check('edit pledges')
79 ) {
80 $tasks = self::taskTitles();
81 }
82 else {
83 $tasks = [
84 self::TASK_EXPORT => self::$_tasks[self::TASK_EXPORT]['title'],
85 ];
86 //CRM-4418,
87 if (CRM_Core_Permission::check('delete in CiviPledge')) {
88 $tasks[self::TASK_DELETE] = self::$_tasks[self::TASK_DELETE]['title'];
89 }
90 }
91
92 $tasks = parent::corePermissionedTaskTitles($tasks, $permission, $params);
93 return $tasks;
94 }
95
96 /**
97 * These tasks are the core set of tasks that the user can perform
98 * on pledges.
99 *
100 * @param int $value
101 *
102 * @return array
103 * the set of tasks for a group of pledge holders
104 */
105 public static function getTask($value) {
106 self::tasks();
107
108 if (empty(self::$_tasks[$value])) {
109 // make it the print task by default
110 $value = self::TASK_PRINT;
111 }
112 return parent::getTask($value);
113 }
114
115 }