-
-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use onToggle feature for setting user_dashboard_options when toggling…
… invoicing, remove from form
- Loading branch information
1 parent
9886779
commit 8d33433
Showing
3 changed files
with
83 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
/* | ||
+--------------------------------------------------------------------+ | ||
| CiviCRM version 5 | | ||
+--------------------------------------------------------------------+ | ||
| Copyright CiviCRM LLC (c) 2004-2018 | | ||
+--------------------------------------------------------------------+ | ||
| This file is a part of CiviCRM. | | ||
| | | ||
| CiviCRM is free software; you can copy, modify, and distribute it | | ||
| under the terms of the GNU Affero General Public License | | ||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | ||
| | | ||
| CiviCRM is distributed in the hope that it will be useful, but | | ||
| WITHOUT ANY WARRANTY; without even the implied warranty of | | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | ||
| See the GNU Affero General Public License for more details. | | ||
| | | ||
| You should have received a copy of the GNU Affero General Public | | ||
| License and the CiviCRM Licensing Exception along | | ||
| with this program; if not, contact CiviCRM LLC | | ||
| at info[AT]civicrm[DOT]org. If you have questions about the | | ||
| GNU Affero General Public License or the licensing of CiviCRM, | | ||
| see the CiviCRM license FAQ at http://civicrm.org/licensing | | ||
+--------------------------------------------------------------------+ | ||
*/ | ||
|
||
/** | ||
* | ||
* @package CRM | ||
* @copyright CiviCRM LLC (c) 2004-2018 | ||
*/ | ||
|
||
class CRM_Invoicing_Utils { | ||
|
||
/** | ||
* Function to call when invoicing is toggled on or off. | ||
* | ||
* We add or remove invoicing from the user dashboard here. | ||
* | ||
* @param bool $oldValue | ||
* @param bool $newValue | ||
* @param array $metadata | ||
*/ | ||
public static function onToggle($oldValue, $newValue, $metadata) { | ||
if ($oldValue == $newValue) { | ||
return; | ||
} | ||
$existingUserViewOptions = civicrm_api3('Setting', 'get', ['return' => 'user_dashboard_options'])['values'][CRM_Core_Config::domainID()]['user_dashboard_options']; | ||
$optionValues= civicrm_api3('Setting', 'getoptions', ['field' => 'user_dashboard_options'])['values']; | ||
$invoiceKey = array_search('Invoices / Credit Notes', $optionValues); | ||
$existingIndex = in_array($invoiceKey, $existingUserViewOptions); | ||
|
||
if ($newValue && $existingIndex === FALSE) { | ||
$existingUserViewOptions[] = $invoiceKey; | ||
} | ||
elseif (!$newValue && $existingIndex !== FALSE) { | ||
unset($existingUserViewOptions[$existingIndex]); | ||
} | ||
civicrm_api3('Setting', 'create', ['user_dashboard_options' => $existingUserViewOptions]); | ||
} | ||
|
||
/** | ||
* Function to call to determine if invoicing is enabled. | ||
* | ||
* Historically the invoicing was declared as a setting but actually | ||
* set within contribution_invoice_settings (which stores multiple settings | ||
* as an array in a non-standard way). | ||
* | ||
* We check both here. | ||
*/ | ||
public static function isInvoicingEnabled() { | ||
if (Civi::settings()->get('invoicing')) { | ||
return TRUE; | ||
} | ||
$invoiceSettings = Civi::settings()->get('contribution_invoice_settings'); | ||
return CRM_Utils_Array::value('invoicing', $invoiceSettings); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters