ensure recur options are present on backend cc contribution form.
[civicrm-core.git] / CRM / Invoicing / Utils.php
CommitLineData
8d334338 1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
8d334338 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 |
8d334338 9 +--------------------------------------------------------------------+
10 */
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
8d334338 16 */
8d334338 17class CRM_Invoicing_Utils {
18
19 /**
20 * Function to call when invoicing is toggled on or off.
21 *
22 * We add or remove invoicing from the user dashboard here.
23 *
24 * @param bool $oldValue
25 * @param bool $newValue
26 * @param array $metadata
ff6f993e 27 *
28 * @throws \CiviCRM_API3_Exception
8d334338 29 */
30 public static function onToggle($oldValue, $newValue, $metadata) {
31 if ($oldValue == $newValue) {
32 return;
33 }
34 $existingUserViewOptions = civicrm_api3('Setting', 'get', ['return' => 'user_dashboard_options'])['values'][CRM_Core_Config::domainID()]['user_dashboard_options'];
d0df87f2 35 $optionValues = civicrm_api3('Setting', 'getoptions', ['field' => 'user_dashboard_options'])['values'];
8d334338 36 $invoiceKey = array_search('Invoices / Credit Notes', $optionValues);
ff6f993e 37 $existingIndex = array_search($invoiceKey, $existingUserViewOptions);
8d334338 38
39 if ($newValue && $existingIndex === FALSE) {
40 $existingUserViewOptions[] = $invoiceKey;
41 }
42 elseif (!$newValue && $existingIndex !== FALSE) {
43 unset($existingUserViewOptions[$existingIndex]);
44 }
45 civicrm_api3('Setting', 'create', ['user_dashboard_options' => $existingUserViewOptions]);
46 }
47
48 /**
49 * Function to call to determine if invoicing is enabled.
50 *
51 * Historically the invoicing was declared as a setting but actually
52 * set within contribution_invoice_settings (which stores multiple settings
53 * as an array in a non-standard way).
54 *
f8857611 55 * We check both here. But will deprecate the latter in time.
8d334338 56 */
57 public static function isInvoicingEnabled() {
fe4d1285 58 return Civi::settings()->get('invoicing');
8d334338 59 }
60
ec5e7bcf 61 /**
62 * Function to get the tax term.
63 *
64 * The value is nested in the contribution_invoice_settings setting - which
65 * is unsupported. Here we have a wrapper function to make later cleanup easier.
66 */
67 public static function getTaxTerm() {
530f1e12 68 return Civi::settings()->get('tax_term');
ec5e7bcf 69 }
70
8d334338 71}