8d334338 |
1 | <?php |
2 | /* |
3 | +--------------------------------------------------------------------+ |
4 | | CiviCRM version 5 | |
5 | +--------------------------------------------------------------------+ |
6b83d5bd |
6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
8d334338 |
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 | +--------------------------------------------------------------------+ |
26 | */ |
27 | |
28 | /** |
29 | * |
30 | * @package CRM |
6b83d5bd |
31 | * @copyright CiviCRM LLC (c) 2004-2019 |
8d334338 |
32 | */ |
8d334338 |
33 | class CRM_Invoicing_Utils { |
34 | |
35 | /** |
36 | * Function to call when invoicing is toggled on or off. |
37 | * |
38 | * We add or remove invoicing from the user dashboard here. |
39 | * |
40 | * @param bool $oldValue |
41 | * @param bool $newValue |
42 | * @param array $metadata |
43 | */ |
44 | public static function onToggle($oldValue, $newValue, $metadata) { |
45 | if ($oldValue == $newValue) { |
46 | return; |
47 | } |
48 | $existingUserViewOptions = civicrm_api3('Setting', 'get', ['return' => 'user_dashboard_options'])['values'][CRM_Core_Config::domainID()]['user_dashboard_options']; |
d0df87f2 |
49 | $optionValues = civicrm_api3('Setting', 'getoptions', ['field' => 'user_dashboard_options'])['values']; |
8d334338 |
50 | $invoiceKey = array_search('Invoices / Credit Notes', $optionValues); |
51 | $existingIndex = in_array($invoiceKey, $existingUserViewOptions); |
52 | |
53 | if ($newValue && $existingIndex === FALSE) { |
54 | $existingUserViewOptions[] = $invoiceKey; |
55 | } |
56 | elseif (!$newValue && $existingIndex !== FALSE) { |
57 | unset($existingUserViewOptions[$existingIndex]); |
58 | } |
59 | civicrm_api3('Setting', 'create', ['user_dashboard_options' => $existingUserViewOptions]); |
60 | } |
61 | |
62 | /** |
63 | * Function to call to determine if invoicing is enabled. |
64 | * |
65 | * Historically the invoicing was declared as a setting but actually |
66 | * set within contribution_invoice_settings (which stores multiple settings |
67 | * as an array in a non-standard way). |
68 | * |
f8857611 |
69 | * We check both here. But will deprecate the latter in time. |
8d334338 |
70 | */ |
71 | public static function isInvoicingEnabled() { |
72 | if (Civi::settings()->get('invoicing')) { |
73 | return TRUE; |
74 | } |
75 | $invoiceSettings = Civi::settings()->get('contribution_invoice_settings'); |
76 | return CRM_Utils_Array::value('invoicing', $invoiceSettings); |
77 | } |
78 | |
f8857611 |
79 | /** |
80 | * Function to call to determine default invoice page. |
81 | * |
82 | * Historically the invoicing was declared as a setting but actually |
83 | * set within contribution_invoice_settings (which stores multiple settings |
84 | * as an array in a non-standard way). |
85 | * |
86 | * We check both here. But will deprecate the latter in time. |
87 | */ |
88 | public static function getDefaultPaymentPage() { |
89 | $value = Civi::settings()->get('default_invoice_page'); |
90 | if (is_numeric($value)) { |
91 | return $value; |
92 | } |
93 | $invoiceSettings = Civi::settings()->get('contribution_invoice_settings'); |
94 | return CRM_Utils_Array::value('default_invoice_page', $invoiceSettings); |
95 | } |
96 | |
ec5e7bcf |
97 | /** |
98 | * Function to get the tax term. |
99 | * |
100 | * The value is nested in the contribution_invoice_settings setting - which |
101 | * is unsupported. Here we have a wrapper function to make later cleanup easier. |
102 | */ |
103 | public static function getTaxTerm() { |
104 | $invoiceSettings = Civi::settings()->get('contribution_invoice_settings'); |
105 | return CRM_Utils_Array::value('tax_term', $invoiceSettings); |
106 | } |
107 | |
8d334338 |
108 | } |