Merge pull request #15982 from civicrm/5.20
[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 * $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 */
7b9bce60 25class CRM_Grant_Task extends CRM_Core_Task {
6a488035 26
7e8c8317
SL
27 /**
28 * Grant Tasks
29 */
30 const UPDATE_GRANTS = 701;
6a488035 31
7e8c8317
SL
32 /**
33 * @var string
34 */
35 public static $objectType = 'grant';
6a488035
TO
36
37 /**
38 * These tasks are the core set of tasks that the user can perform
39 * on a contact / group of contacts
40 *
a6c01b45
CW
41 * @return array
42 * the set of tasks for a group of contacts
6a488035 43 */
7b9bce60 44 public static function tasks() {
6a488035 45 if (!(self::$_tasks)) {
be2fb01f
CW
46 self::$_tasks = [
47 self::TASK_DELETE => [
7f82e636 48 'title' => ts('Delete grants'),
6a488035
TO
49 'class' => 'CRM_Grant_Form_Task_Delete',
50 'result' => FALSE,
be2fb01f
CW
51 ],
52 self::TASK_PRINT => [
7f82e636 53 'title' => ts('Print selected rows'),
6a488035
TO
54 'class' => 'CRM_Grant_Form_Task_Print',
55 'result' => FALSE,
be2fb01f
CW
56 ],
57 self::TASK_EXPORT => [
7f82e636 58 'title' => ts('Export grants'),
be2fb01f 59 'class' => [
6a488035
TO
60 'CRM_Export_Form_Select',
61 'CRM_Export_Form_Map',
be2fb01f 62 ],
6a488035 63 'result' => FALSE,
be2fb01f
CW
64 ],
65 self::UPDATE_GRANTS => [
7f82e636 66 'title' => ts('Update grants'),
6a488035
TO
67 'class' => 'CRM_Grant_Form_Task_Update',
68 'result' => FALSE,
be2fb01f
CW
69 ],
70 ];
4d73a5a7 71
72 if (!CRM_Core_Permission::check('delete in CiviGrant')) {
7b9bce60 73 unset(self::$_tasks[self::TASK_DELETE]);
4d73a5a7 74 }
75
7b9bce60 76 parent::tasks();
6a488035 77 }
4d73a5a7 78
6a488035
TO
79 return self::$_tasks;
80 }
81
6a488035 82 /**
100fef9d 83 * Show tasks selectively based on the permission level
6a488035
TO
84 * of the user
85 *
86 * @param int $permission
7b9bce60 87 * @param array $params
6a488035 88 *
a6c01b45
CW
89 * @return array
90 * set of tasks that are valid for the user
6a488035 91 */
be2fb01f 92 public static function permissionedTaskTitles($permission, $params = []) {
6a488035
TO
93 if (($permission == CRM_Core_Permission::EDIT)
94 || CRM_Core_Permission::check('edit grants')
95 ) {
96 $tasks = self::taskTitles();
97 }
98 else {
be2fb01f 99 $tasks = [
7b9bce60 100 self::TASK_EXPORT => self::$_tasks[self::TASK_EXPORT]['title'],
be2fb01f 101 ];
6a488035
TO
102 //CRM-4418,
103 if (CRM_Core_Permission::check('delete in CiviGrant')) {
7b9bce60 104 $tasks[self::TASK_DELETE] = self::$_tasks[self::TASK_DELETE]['title'];
6a488035
TO
105 }
106 }
7b9bce60
MW
107
108 $tasks = parent::corePermissionedTaskTitles($tasks, $permission, $params);
6a488035
TO
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 *
a6c01b45
CW
117 * @return array
118 * the set of tasks for a group of contacts
6a488035 119 */
00be9182 120 public static function getTask($value) {
6a488035 121 self::tasks();
7b9bce60
MW
122
123 if (!CRM_Utils_Array::value($value, self::$_tasks)) {
124 // make it the print task by default
125 $value = self::TASK_PRINT;
6a488035 126 }
7b9bce60 127 return parent::getTask($value);
6a488035 128 }
96025800 129
6a488035 130}