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