Merge pull request #15321 from yashodha/dev_1065
[civicrm-core.git] / CRM / Pledge / Task.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
fee14197 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
6b83d5bd 6 | Copyright CiviCRM LLC (c) 2004-2019 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
6a488035 29 * @package CRM
6b83d5bd 30 * @copyright CiviCRM LLC (c) 2004-2019
6a488035
TO
31 */
32
33/**
34 * class to represent the actions that can be performed on a group of contacts
cc28438b 35 * used by the search forms.
6a488035 36 */
56c77e1c 37class CRM_Pledge_Task extends CRM_Core_Task {
6a488035 38
c86d4e7c 39 public static $objectType = 'pledge';
6a488035
TO
40
41 /**
42 * These tasks are the core set of tasks that the user can perform
43 * on a contact / group of contacts
44 *
a6c01b45
CW
45 * @return array
46 * the set of tasks for a group of contacts
6a488035 47 */
56c77e1c 48 public static function tasks() {
6a488035 49 if (!self::$_tasks) {
be2fb01f
CW
50 self::$_tasks = [
51 self::TASK_DELETE => [
7f82e636 52 'title' => ts('Delete pledges'),
6a488035
TO
53 'class' => 'CRM_Pledge_Form_Task_Delete',
54 'result' => FALSE,
be2fb01f
CW
55 ],
56 self::TASK_PRINT => [
7f82e636 57 'title' => ts('Print selected rows'),
6a488035
TO
58 'class' => 'CRM_Pledge_Form_Task_Print',
59 'result' => FALSE,
be2fb01f
CW
60 ],
61 self::TASK_EXPORT => [
7f82e636 62 'title' => ts('Export pledges'),
be2fb01f 63 'class' => [
6a488035
TO
64 'CRM_Export_Form_Select',
65 'CRM_Export_Form_Map',
be2fb01f 66 ],
6a488035 67 'result' => FALSE,
be2fb01f
CW
68 ],
69 ];
6a488035 70
cc28438b 71 // CRM-4418, check for delete
6a488035 72 if (!CRM_Core_Permission::check('delete in CiviPledge')) {
56c77e1c 73 unset(self::$_tasks[self::TASK_DELETE]);
6a488035 74 }
4d73a5a7 75
56c77e1c 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
56c77e1c 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 pledges')
95 ) {
96 $tasks = self::taskTitles();
97 }
98 else {
be2fb01f 99 $tasks = [
56c77e1c 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 CiviPledge')) {
56c77e1c 104 $tasks[self::TASK_DELETE] = self::$_tasks[self::TASK_DELETE]['title'];
6a488035
TO
105 }
106 }
56c77e1c
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
cc28438b 114 * on pledges.
6a488035
TO
115 *
116 * @param int $value
117 *
a6c01b45
CW
118 * @return array
119 * the set of tasks for a group of pledge holders
6a488035 120 */
00be9182 121 public static function getTask($value) {
6a488035 122 self::tasks();
56c77e1c
MW
123
124 if (!CRM_Utils_Array::value($value, self::$_tasks)) {
125 // make it the print task by default
126 $value = self::TASK_PRINT;
6a488035 127 }
56c77e1c 128 return parent::getTask($value);
6a488035 129 }
96025800 130
6a488035 131}