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