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