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