Merge pull request #15966 from seamuslee001/permission_access_metadata
[civicrm-core.git] / CRM / Contribute / Task.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2019
32 */
33
34 /**
35 * Class to represent the actions that can be performed on a group of contacts.
36 *
37 * Used by the search forms.
38 */
39 class CRM_Contribute_Task extends CRM_Core_Task {
40
41 /**
42 * Contribution tasks
43 */
44 const
45 UPDATE_STATUS = 401,
46 PDF_RECEIPT = 402,
47 PDF_THANKYOU = 403,
48 PDF_INVOICE = 404;
49
50 /**
51 * @var string
52 */
53 public static $objectType = 'contribution';
54
55 /**
56 * These tasks are the core set of tasks that the user can perform
57 * on a contact / group of contacts
58 *
59 * @return array
60 * the set of tasks for a group of contacts
61 */
62 public static function tasks() {
63 if (!(self::$_tasks)) {
64 self::$_tasks = [
65 self::TASK_DELETE => [
66 'title' => ts('Delete contributions'),
67 'class' => 'CRM_Contribute_Form_Task_Delete',
68 'result' => FALSE,
69 ],
70 self::TASK_PRINT => [
71 'title' => ts('Print selected rows'),
72 'class' => 'CRM_Contribute_Form_Task_Print',
73 'result' => FALSE,
74 ],
75 self::TASK_EXPORT => [
76 'title' => ts('Export contributions'),
77 'class' => [
78 'CRM_Export_Form_Select',
79 'CRM_Export_Form_Map',
80 ],
81 'result' => FALSE,
82 ],
83 self::BATCH_UPDATE => [
84 'title' => ts('Update multiple contributions'),
85 'class' => [
86 'CRM_Contribute_Form_Task_PickProfile',
87 'CRM_Contribute_Form_Task_Batch',
88 ],
89 'result' => TRUE,
90 ],
91 self::TASK_EMAIL => [
92 'title' => ts('Email - send now (to %1 or less)', [
93 1 => Civi::settings()
94 ->get('simple_mail_limit'),
95 ]),
96 'class' => 'CRM_Contribute_Form_Task_Email',
97 'result' => TRUE,
98 ],
99 self::UPDATE_STATUS => [
100 'title' => ts('Update pending contribution status'),
101 'class' => 'CRM_Contribute_Form_Task_Status',
102 'result' => TRUE,
103 ],
104 self::PDF_RECEIPT => [
105 'title' => ts('Receipts - print or email'),
106 'class' => 'CRM_Contribute_Form_Task_PDF',
107 'result' => FALSE,
108 ],
109 self::PDF_THANKYOU => [
110 'title' => ts('Thank-you letters - print or email'),
111 'class' => 'CRM_Contribute_Form_Task_PDFLetter',
112 'result' => FALSE,
113 ],
114 self::PDF_INVOICE => [
115 'title' => ts('Invoices - print or email'),
116 'class' => 'CRM_Contribute_Form_Task_Invoice',
117 'result' => FALSE,
118 ],
119 ];
120
121 //CRM-4418, check for delete
122 if (!CRM_Core_Permission::check('delete in CiviContribute')) {
123 unset(self::$_tasks[self::TASK_DELETE]);
124 }
125 //CRM-12920 - check for edit permission
126 if (!CRM_Core_Permission::check('edit contributions')) {
127 unset(self::$_tasks[self::BATCH_UPDATE], self::$_tasks[self::UPDATE_STATUS]);
128 }
129
130 // remove action "Invoices - print or email"
131 $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
132 $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
133 if (!$invoicing) {
134 unset(self::$_tasks[self::PDF_INVOICE]);
135 }
136
137 parent::tasks();
138 }
139
140 return self::$_tasks;
141 }
142
143 /**
144 * Show tasks selectively based on the permission level
145 * of the user
146 *
147 * @param int $permission
148 *
149 * @param array $params
150 * bool softCreditFiltering: derived from CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled
151 *
152 * @return array
153 * set of tasks that are valid for the user
154 */
155 public static function permissionedTaskTitles($permission, $params = []) {
156 if (!isset($params['softCreditFiltering'])) {
157 $params['softCreditFiltering'] = FALSE;
158 }
159 if (($permission == CRM_Core_Permission::EDIT)
160 || CRM_Core_Permission::check('edit contributions')
161 ) {
162 $tasks = self::taskTitles();
163 }
164 else {
165 $tasks = [
166 self::TASK_EXPORT => self::$_tasks[self::TASK_EXPORT]['title'],
167 self::TASK_EMAIL => self::$_tasks[self::TASK_EMAIL]['title'],
168 self::PDF_RECEIPT => self::$_tasks[self::PDF_RECEIPT]['title'],
169 ];
170
171 //CRM-4418,
172 if (CRM_Core_Permission::check('delete in CiviContribute')) {
173 $tasks[self::TASK_DELETE] = self::$_tasks[self::TASK_DELETE]['title'];
174 }
175 }
176 if ($params['softCreditFiltering']) {
177 unset($tasks[self::BATCH_UPDATE], $tasks[self::PDF_RECEIPT]);
178 }
179
180 $tasks = parent::corePermissionedTaskTitles($tasks, $permission, $params);
181 return $tasks;
182 }
183
184 /**
185 * These tasks are the core set of tasks that the user can perform
186 * on contributors
187 *
188 * @param int $value
189 *
190 * @return array
191 * the set of tasks for a group of contributors
192 */
193 public static function getTask($value) {
194 self::tasks();
195 if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) {
196 // make the print task by default
197 $value = self::TASK_PRINT;
198 }
199 return parent::getTask($value);
200 }
201
202 }