Commit 0321a2ef authored by mattwire's avatar mattwire
Browse files

Use generic settings form

parent e6de6900
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
use CRM_Civigiftaid_ExtensionUtil as E;
/**
* Form controller class
*
* @see http://wiki.civicrm.org/confluence/display/CRMDOC43/QuickForm+Reference
*/
class CRM_Civigiftaid_Form_Settings extends CRM_Core_Form {
function buildQuickForm() {
parent::buildQuickForm();
$className = E::CLASS_PREFIX . '_Settings';
CRM_Utils_System::setTitle($className::TITLE . ' - ' . E::ts('Settings'));
$className = E::CLASS_PREFIX . '_Form_SettingsCustom';
if (method_exists($className, 'buildQuickFormPre')) {
$className::buildQuickFormPre($this);
}
$settings = $this->getFormSettings();
foreach ($settings as $name => $setting) {
if (isset($setting['html_type'])) {
Switch (strtolower($setting['html_type'])) {
case 'text':
$this->addElement('text', $name, ts($setting['description']), $setting['html_attributes'], []);
break;
case 'checkbox':
$this->addElement('checkbox', $name, ts($setting['description']), '', '');
break;
case 'datepicker':
foreach ($setting['html_extra'] as $key => $value) {
if ($key == 'minDate') {
$minDate = new DateTime('now');
$minDate->modify($value);
$setting['html_extra'][$key] = $minDate->format('Y-m-d');
}
}
$this->add('datepicker', $name, ts($setting['description']), $setting['html_attributes'], FALSE, $setting['html_extra']);
break;
case 'select2':
$className = E::CLASS_PREFIX . '_Form_SettingsCustom';
if (method_exists($className, 'addSelect2Element')) {
$className::addSelect2Element($this, $name, $setting);
}
break;
case 'select':
$className = E::CLASS_PREFIX . '_Form_SettingsCustom';
if (method_exists($className, 'addSelectElement')) {
$className::addSelectElement($this, $name, $setting);
}
break;
case 'hidden':
$hidden = TRUE;
}
if (isset($hidden)) {
continue;
}
$adminGroup = isset($setting['admin_group']) ? $setting['admin_group'] : 'default';
$elementGroups[$adminGroup]['elementNames'][] = $name;
// Title and description may not be defined on all elements (they only need to be on one)
if (!empty($setting['admin_grouptitle'])) {
$elementGroups[$setting['admin_group']]['title'] = $setting['admin_grouptitle'];
}
if (!empty($setting['admin_groupdescription'])) {
$elementGroups[$setting['admin_group']]['description'] = $setting['admin_groupdescription'];
}
}
}
$this->addButtons([
[
'type' => 'submit',
'name' => ts('Submit'),
'isDefault' => TRUE,
],
[
'type' => 'cancel',
'name' => ts('Cancel'),
]
]);
// export form elements
$this->assign('elementGroups', $elementGroups);
}
function postProcess() {
$className = E::CLASS_PREFIX . '_Settings';
$changed = $this->_submitValues;
$settings = $this->getFormSettings(TRUE);
foreach ($settings as &$setting) {
if ($setting['html_type'] == 'Checkbox') {
$setting = false;
}
else {
$setting = NULL;
}
}
// Make sure we have all settings elements set (boolean settings will be unset by default and wouldn't be saved)
$settingsToSave = array_merge($settings, array_intersect_key($changed, $settings));
$className::save($settingsToSave);
parent::postProcess();
CRM_Core_Session::singleton()->setStatus('Configuration Updated', $className::TITLE, 'success');
}
/**
* Get the settings we are going to allow to be set on this form.
*
* @return array
*/
function getFormSettings($metadata=TRUE) {
$className = E::CLASS_PREFIX . '_Settings';
$unprefixedSettings = [];
$settings = civicrm_api3('setting', 'getfields', ['filters' => $className::getFilter()]);
if (!empty($settings['values'])) {
foreach ($settings['values'] as $name => $values) {
if ($metadata) {
$unprefixedSettings[$className::getName($name, FALSE)] = $values;
}
else {
$unprefixedSettings[$className::getName($name, FALSE)] = NULL;
}
}
}
return $unprefixedSettings;
}
/**
* Set defaults for form.
*
* @see CRM_Core_Form::setDefaultValues()
*/
function setDefaultValues() {
$className = E::CLASS_PREFIX . '_Settings';
$settings = $this->getFormSettings(FALSE);
$defaults = [];
$existing = $className::get(array_keys($settings));
if ($existing) {
foreach ($existing as $name => $value) {
$defaults[$name] = $value;
}
}
return $defaults;
}
}
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
use CRM_Civigiftaid_ExtensionUtil as E;
/**
* Form controller class
*
* @see http://wiki.civicrm.org/confluence/display/CRMDOC43/QuickForm+Reference
*/
class CRM_Civigiftaid_Form_SettingsCustom extends CRM_Civigiftaid_Form_Settings {
/**
* @param \CRM_Core_Form $form
* @param string $name
* @param array $setting
*
* @throws \CiviCRM_API3_Exception
*/
public static function addSelect2Element(&$form, $name, $setting) {
switch ($name) {
case 'financial_types_enabled':
$financialTypes = civicrm_api3('FinancialType', 'get', [
'is_active' => 1,
'options' => ['limit' => 0, 'sort' => "name ASC"],
]);
$types = [];
foreach ($financialTypes['values'] as $type) {
$types[] = [
'id' => $type['id'],
'text' => $type['name'],
];
}
$form->add('select2', $name, $setting['description'], $types, FALSE, $setting['html_attributes']);
break;
}
}
}
......@@ -139,7 +139,7 @@ function civigiftaid_symfony_civicrm_navigationMenu($event, $hookName) {
$item[] = [
'label' => E::ts('Settings'),
'name' => 'settings',
'url' => "civicrm/admin/giftaid/settings",
'url' => "civicrm/admin/setting/ukgiftaid",
'permission' => 'access CiviContribute',
'operator' => NULL,
'separator' => NULL,
......@@ -184,6 +184,28 @@ function civigiftaid_civicrm_buildForm($formName, &$form) {
->addScriptFile(E::LONG_NAME, 'resources/js/batch.js', 1, 'html-header')
->addStyleFile(E::LONG_NAME, 'resources/css/batch.css', 1, 'html-header');
break;
case 'CRM_Admin_Form_Generic':
if ($form->getSettingPageFilter() !== 'ukgiftaid') {
return;
}
$helpText = E::ts(
'Configure settings for GiftAid. You can specify which financial types are eligible. Also please read the <a href="%1" target="_blank">documentation</a>.',
[
1 => 'https://docs.civicrm.org/ukgiftaid'
]
);
// addMarkup was added in CiviCRM 5.32 via https://github.com/civicrm/civicrm-core/commit/e564eac67d3fcfee8fad1760e928f6af81e13d22
if (method_exists(\Civi::resources(), 'addMarkup')) {
\Civi::resources()
->addMarkup('<div class="help">' . $helpText . '</div>', [
'weight' => -1,
'region' => 'page-body'
]);
}
\Civi::resources()->addScriptFile(E::LONG_NAME, 'js/ukgiftaid.settings.js');
}
}
......
......@@ -18,7 +18,7 @@
<author>MJW Consulting, Rich Lott (Artful Robot) Erawat Chamanont, Jamie Novick, Guanhuan Chen, Robin Mitra</author>
<email>mjw@mjwconsult.co.uk, https://artfulrobot.uk, jamie@compucorp.co.uk, guanhuan@compucorp.co.uk</email>
</maintainer>
<releaseDate>2020-11-08</releaseDate>
<releaseDate>2020-11-15</releaseDate>
<version>3.4.6-dev</version>
<develStage>beta</develStage>
<compatibility>
......
(function($, ts) {
function updateVisibleElements() {
if ($('input#civigiftaid_globally_enabled_civigiftaid_globally_enabled').prop('checked')) {
$('tr.crm--form-block-civigiftaid_financial_types_enabled').hide();
}
else {
$('tr.crm--form-block-civigiftaid_financial_types_enabled').show();
}
}
document.addEventListener('DOMContentLoaded', function() {
updateVisibleElements();
});
$('input#civigiftaid_globally_enabled_civigiftaid_globally_enabled').on('change', function() {
updateVisibleElements();
});
}(CRM.$, CRM.ts('uk.co.compucorp.civicrm.giftaid')));
......@@ -27,39 +27,43 @@ use CRM_Civigiftaid_ExtensionUtil as E;
return [
'civigiftaid_globally_enabled' => [
'admin_group' => 'civigiftaid_general',
'admin_grouptitle' => 'Gift Aid Financial Types',
'admin_groupdescription' => 'Customise which financial types gift aid should apply to.',
'group_name' => 'CiviGiftAid Settings',
'group' => 'civigiftaid',
'name' => 'civigiftaid_globally_enabled',
'type' => 'Boolean',
'html_type' => 'Checkbox',
'default' => 1,
'html_type' => 'checkbox',
'default' => TRUE,
'add' => '5.0',
'is_domain' => 1,
'is_contact' => 0,
'description' => 'Enable gift aid for line items of any financial type',
'title' => E::ts('Enable gift aid for line items of any financial type'),
'html_attributes' => [],
'settings_pages' => [
'ukgiftaid' => [
'weight' => 5,
]
],
],
// financial_type
'civigiftaid_financial_types_enabled' => [
'admin_group' => 'civigiftaid_general',
'group_name' => 'CiviGiftAid Settings',
'group' => 'civigiftaid',
'name' => 'civigiftaid_financial_types_enabled',
'type' => 'Array',
'html_type' => 'select2',
'html_type' => 'select',
'default' => [],
'add' => '4.7',
'is_domain' => 1,
'is_contact' => 0,
'description' => 'Enabled Financial Types',
'title' => E::ts('Enabled Financial Types'),
'description' => E::ts('Select which financial types are eligible for gift aid.'),
'html_attributes' => [
'placeholder' => E::ts('- select -'),
'class' => 'huge',
'class' => 'crm-select2',
'multiple' => TRUE
],
'pseudoconstant' => ['callback' => 'CRM_Contribute_PseudoConstant::financialType'],
'settings_pages' => [
'ukgiftaid' => [
'weight' => 10,
]
],
],
];
{*--------------------------------------------------------------------+
| CiviCRM version 5.0 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2019 |
+--------------------------------------------------------------------+
| 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 |
+-------------------------------------------------------------------*}
{htxt id='payment_instrument_id'}
{ts}Select the payment method to record for direct debit payments (usually "Direct Debit"){/ts}
{/htxt}
{htxt id='financial_type'}
{ts}Select the financial type to record for direct debit payment. Normally this will already be set by the contribution page - it will only be used when syncing from SmartDebit.
(For example if you use Direct Debit for your membership fees select "Member Dues"){/ts}
{/htxt}
{htxt id='activity_type'}
{ts}Select the activity type to record each time a contact signs up for a new Direct Debit{/ts}
{/htxt}
{htxt id='collection_interval'}
{ts}This is the interval between setup of a Direct Debit and when payment will actually be taken. It will use the days specified in 'Collection Days' to pre-select
the next available collection date. It is also used to calculate when the first payment will be taken which may be this month or next month. The default value is 10, and a minimum would be 7 working days
(to allow for bank processing cycles) so do not set this value below 10.{/ts}
{/htxt}
{htxt id='collection_days'}
{ts}This will be displayed to the customer on sign up. It allows them to select their preferred collection day. For example: 1,20 would allow the customer
to have their Direct Debit payment taken on either the 1st or 20th of the month.{/ts}
{/htxt}
{htxt id='notice_period'}
{ts}This is the "Advance Notice Period" as agreed with Smartdebit and displayed on the Direct Debit Guarantee.
"If there are any changes to the amount, date or frequency of your Direct Debit ORGANISATION_NAME will notify you XX working days in advance of your account being debited
or as otherwise agreed. If you request ORGANISATION_NAME to collect a payment, confirmation of the amount and date will be given to you at the time of the request."{/ts}
{/htxt}
{htxt id='service_user_number'}
{ts}This is assigned to you by the Bank / Direct Debit provider and should be entered here.{/ts}
{/htxt}
{htxt id='service_user_name'}
{ts}In some cases the organisation name required on the direct debit instruction/guarantee is different to the main organisation name. For example, if the SUN is owned by Smartdebit
it will normally need to be "PSL re [organisation name]"{/ts}
{/htxt}
{htxt id='transaction_prefix'}
{ts}This is the transaction prefix (BACS reference) for each Direct Debit instruction that will be generated by CiviCRM.
For example, if this is set to "WEB" references will be in the form WEB0001023{/ts}
{/htxt}
{htxt id='initial_completed'}
{ts}When a new direct debit instruction is created it will take around 10 days for the payment to be collected by the bank. During this time the payment
in CiviCRM will be "Pending", as it could fail. However, this means that new memberships/event registrations are also in pending state.{/ts}
<br/>
{ts}Enabling this parameter will set the payment to completed immediately (it will still change to failed if it cannot be taken) and allow the
memberships etc to become active.{/ts}
{/htxt}
{htxt id='cr_cache'}
{ts}How long should CiviCRM cache collection reports from SmartDebit? The default is 1 year but you can change this to anything reasonable here -
consider that a longer time will increase time it takes to sync as well as database size.{/ts}
<br/>{ts}Must be a valid format per: <a href="http://www.php.net/manual/en/datetime.formats.php">Date and Time Formats</a>{/ts}
<br/>{ts}Default value is '-1 year'{/ts}
{/htxt}
\ No newline at end of file
{*
* https://civicrm.org/license
*}
<div class="crm-block crm-form-block crm-admin-options-form-block">
<div class="crm-submit-buttons">
{include file="CRM/common/formButtons.tpl" location="top"}
</div>
<h2>Configuration</h2>
{foreach from=$elementGroups item=elementGroup}
<div class="clear">
<br />
<h3>{$elementGroup.title}</h3>
<div class="help">{$elementGroup.description}</div>
<table class="form-layout-compressed">
{foreach from=$elementGroup.elementNames item=elementName}
<tr><td>
{$form.$elementName.html}
<label for="{$elementName}">{$form.$elementName.label} {help id=$elementName title=$form.$elementName.label}</label>
</td></tr>
{/foreach}
</table>
</div>
{/foreach}
{* FOOTER *}
<div class="crm-submit-buttons">
{include file="CRM/common/formButtons.tpl" location="bottom"}
</div>
</div>
<?xml version="1.0"?>
<menu>
<item>
<path>civicrm/admin/giftaid/settings</path>
<title>CiviGiftaid Configuration</title>
<path_arguments>reset=1</path_arguments>
<page_callback>CRM_Civigiftaid_Form_Settings</page_callback>
<path>civicrm/admin/setting/ukgiftaid</path>
<title>Gift Aid settings</title>
<page_callback>CRM_Admin_Form_Generic</page_callback>
<access_arguments>administer CiviCRM</access_arguments>
</item>
</menu>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment