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