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