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