From e8f9e112e61f240a88b888fb374ef840446a70d8 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Tue, 18 Jun 2019 10:01:13 +0100 Subject: [PATCH 01/97] RSE-203: Implement a Settings form --- CRM/Eventsextras/Form/Settings.php | 125 +++++++ CRM/Eventsextras/SettingsManager.php | 61 ++++ settings/EventsExtras.setting.php | 328 ++++++++++--------- templates/CRM/Eventsextras/Form/Settings.tpl | 63 ++++ xml/Menu/eventsextras.xml | 10 + 5 files changed, 429 insertions(+), 158 deletions(-) create mode 100644 CRM/Eventsextras/Form/Settings.php create mode 100644 CRM/Eventsextras/SettingsManager.php create mode 100644 templates/CRM/Eventsextras/Form/Settings.tpl create mode 100644 xml/Menu/eventsextras.xml diff --git a/CRM/Eventsextras/Form/Settings.php b/CRM/Eventsextras/Form/Settings.php new file mode 100644 index 0000000..9fbf58e --- /dev/null +++ b/CRM/Eventsextras/Form/Settings.php @@ -0,0 +1,125 @@ + $config) { + $this->addRadio( + $name, + E::ts($config['title']), + array(1 => E::ts('Show'), 0 => E::ts('Hide')) + ); + /*$this->addYesNo( + $name, + $config['title'] + );*/ + $this->divideConfigSections($name, $config['section']); + } + $this->addButtons([ + [ + 'type' => 'submit', + 'name' => ts('Submit'), + 'isDefault' => TRUE, + ], + [ + 'type' => 'cancel', + 'name' => ts('Cancel'), + ], + ]); + + $this->assign('frontpageConfigSection', $this->frontpageConfig); + $this->assign('feeConfigSection', $this->feeConfig); + $this->assign('onlineRegistrationSection', $this->onlineRegistrationConfig);; + } + + public function postProcess() { + $configFields = SettingsManager::getConfigFields(); + $submittedValues = $this->exportValues(); + $valuesToSave = array_intersect_key($submittedValues, $configFields); + $result = civicrm_api3('setting', 'create', $valuesToSave); + $session = CRM_Core_Session::singleton(); + if($result['is_error']== 0){ + $session->setStatus(E::ts('Settings have been saved'),ts('Events Extra Settings'), 'success'); + }else{ + $session->setStatus(E::ts('Settings could not be saved, please contact Administrator'),ts('Events Extra Settings'), 'error'); + } + } + + /** + * Set defaults for form. + * + * @see CRM_Core_Form::setDefaultValues() + */ + public function setDefaultValues() { + $defaults = []; + $currentValues = civicrm_api3('setting', 'get', + ['return' => array_keys(SettingsManager::getConfigFields())]); + $defaults = []; + $domainID = CRM_Core_Config::domainID(); + foreach ($currentValues['values'][$domainID] as $name => $value) { + $defaults[$name] = $value; + } + return $defaults; + } + + /** + * Divides fields between UI sections + * + * @param $name + * @param $section + */ + private function divideConfigSections($name, $section) { + switch ($section) { + case 'front_page': + $this->frontpageConfig[] = $name; + break; + + case 'fee': + $this->feeConfig[] = $name; + break; + + case 'online_registration': + $this->onlineRegistrationConfig[] = $name; + break; + + } + } +} diff --git a/CRM/Eventsextras/SettingsManager.php b/CRM/Eventsextras/SettingsManager.php new file mode 100644 index 0000000..df4d1a8 --- /dev/null +++ b/CRM/Eventsextras/SettingsManager.php @@ -0,0 +1,61 @@ + [ 'name' => $name], + ])['values'][$name]; + } + return $settingFields; + } + + + + +} + diff --git a/settings/EventsExtras.setting.php b/settings/EventsExtras.setting.php index ba99a1a..009175b 100644 --- a/settings/EventsExtras.setting.php +++ b/settings/EventsExtras.setting.php @@ -1,162 +1,174 @@ [ - 'name' => 'eventsextras_roles', - 'type' => 'Boolean', - 'quick_form_type' => 'YesNo', - 'default' => TRUE, - 'html_type' => 'radio', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'description' => ts('Show/Hide Default Role'), - 'help_text' => '', - 'section' => 'front_page', - ], - 'eventsextras_participant_listing' => [ - 'name' => 'eventsextras_participant_listing', - 'type' => 'Boolean', - 'quick_form_type' => 'YesNo', - 'default' => FALSE, - 'html_type' => 'radio', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'description' => ts('Show/Hide Participant listing'), - 'help_text' => '', - 'section' => 'front_page', - ], - 'eventsextras_event_summary' => [ - 'name' => 'eventsextras_event_summary', - 'type' => 'Boolean', - 'quick_form_type' => 'YesNo', - 'default' => TRUE, - 'html_type' => 'radio', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'description' => ts('Show/Hide Event Summary'), - 'help_text' => '', - 'section' => 'front_page', - ], - 'eventsextras_completed_description' => [ - 'name' => 'eventsExtrasCompleteDescription', - 'type' => 'Boolean', - 'quick_form_type' => 'YesNo', - 'default' => TRUE, - 'html_type' => 'radio', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'description' => ts('Show/Hide Complete Description'), - 'help_text' => '', - 'section' => 'front_page', - ], - 'eventsextras_include_map_event_location' => [ - 'name' => 'eventsextras_include_map_event_location', - 'type' => 'Boolean', - 'quick_form_type' => 'YesNo', - 'default' => TRUE, - 'html_type' => 'radio', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'description' => ts('Show/Hide Include Map to Event Location'), - 'help_text' => '', - 'section' => 'front_page', - ], - 'eventsextras_public_event' => [ - 'name' => 'eventsextras_public_event', - 'type' => 'Boolean', - 'quick_form_type' => 'YesNo', - 'default' => TRUE, - 'html_type' => 'radio', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'description' => ts('Show/Hide Public Event'), - 'help_text' => '', - 'section' => 'front_page', - ], - 'eventsextras_currency' => [ - 'name' => 'eventsextras_currency', - 'type' => 'Boolean', - 'quick_form_type' => 'YesNo', - 'default' => TRUE, - 'html_type' => 'radio', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'description' => ts('Show/Hide Currency'), - 'help_text' => '', - 'section' => 'fee', - ], - 'eventsextras_enable_pay_later_option' => [ - 'name' => 'eventsextras_enable_pay_later_option', - 'type' => 'Boolean', - 'quick_form_type' => 'YesNo', - 'default' => TRUE, - 'html_type' => 'radio', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'description' => ts('Show/Hide Enable pay later option'), - 'help_text' => '', - 'section' => 'fee', - ], - 'eventsextras_payment_processor_selection' => [ - 'name' => 'eventsextras_payment_processor_selection', - 'type' => 'Boolean', - 'quick_form_type' => 'YesNo', - 'default' => TRUE, - 'html_type' => 'radio', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'description' => ts('Show/Hide Payment Processor Selection'), - 'help_text' => '', - 'section' => 'fee', - ], - 'eventsextras_pending_participant_expiration' => [ - 'name' => 'eventsextras_pending_participant_expiration', - 'type' => 'Boolean', - 'quick_form_type' => 'YesNo', - 'default' => TRUE, - 'html_type' => 'radio', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'description' => ts('Show/Hide Pending Participant Expiration'), - 'help_text' => '', - 'section' => 'online_registration', - ], - 'eventsextras_allow_self_service' => [ - 'name' => 'eventsextras_allow_self_service', - 'type' => 'Boolean', - 'quick_form_type' => 'YesNo', - 'default' => TRUE, - 'html_type' => 'radio', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'description' => ts('Show/Hide Allow self-service cancellation or transfer?'), - 'help_text' => '', - 'section' => 'online_registration', - ], - 'eventsextras_register_multiple_participants' => [ - 'name' => 'eventsextras_register_multiple_participants', - 'type' => 'Boolean', - 'quick_form_type' => 'YesNo', - 'default' => TRUE, - 'html_type' => 'radio', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'description' => ts('Show/Hide Register multiple participants?'), - 'help_text' => '', - 'section' => 'online_registration', - ], + 'eventsextras_roles' => [ + 'name' => 'eventsextras_roles', + 'title' => ts('Default Role'), + 'type' => 'Boolean', + 'quick_form_type' => 'YesNo', + 'default' => TRUE, + 'html_type' => 'radio', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('Show/Hide Default Role'), + 'help_text' => 'help ka', + 'section' => 'front_page', + ], + 'eventsextras_participant_listing' => [ + 'name' => 'eventsextras_participant_listing', + 'title' => ts('Participant listing'), + 'type' => 'Boolean', + 'quick_form_type' => 'YesNo', + 'default' => TRUE, + 'html_type' => 'radio', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('Show/Hide Participant listing'), + 'help_text' => 'help 2', + 'section' => 'front_page', + ], + 'eventsextras_event_summary' => [ + 'name' => 'eventsextras_event_summary', + 'title' => ts('Events Summary'), + 'type' => 'Boolean', + 'quick_form_type' => 'YesNo', + 'default' => TRUE, + 'html_type' => 'radio', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('Show/Hide Event Summary'), + 'help_text' => '', + 'section' => 'front_page', + ], + 'eventsextras_completed_description' => [ + 'name' => 'eventsExtrasCompleteDescription', + 'title' => ts('Complete Description'), + 'type' => 'Boolean', + 'quick_form_type' => 'YesNo', + 'default' => TRUE, + 'html_type' => 'radio', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('Show/Hide Complete Description'), + 'help_text' => '', + 'section' => 'front_page', + ], + 'eventsextras_include_map_event_location' => [ + 'name' => 'eventsextras_include_map_event_location', + 'title' => ts('Include Map to Event Location'), + 'type' => 'Boolean', + 'quick_form_type' => 'YesNo', + 'default' => TRUE, + 'html_type' => 'radio', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('Show/Hide Include Map to Event Location'), + 'help_text' => '', + 'section' => 'front_page', + ], + 'eventsextras_public_event' => [ + 'name' => 'eventsextras_public_event', + 'title' => ts('Public Event'), + 'type' => 'Boolean', + 'quick_form_type' => 'YesNo', + 'default' => TRUE, + 'html_type' => 'radio', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('Show/Hide Public Event'), + 'help_text' => '', + 'section' => 'front_page', + ], + 'eventsextras_currency' => [ + 'name' => 'eventsextras_currency', + 'title' => ts('Currency'), + 'type' => 'Boolean', + 'quick_form_type' => 'YesNo', + 'default' => TRUE, + 'html_type' => 'radio', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('Show/Hide Currency'), + 'help_text' => '', + 'section' => 'fee', + ], + 'eventsextras_enable_pay_later_option' => [ + 'name' => 'eventsextras_enable_pay_later_option', + 'title' => ts('Enable pay later option'), + 'type' => 'Boolean', + 'quick_form_type' => 'YesNo', + 'default' => TRUE, + 'html_type' => 'radio', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('Show/Hide Enable pay later option'), + 'help_text' => '', + 'section' => 'fee', + ], + 'eventsextras_payment_processor_selection' => [ + 'name' => 'eventsextras_payment_processor_selection', + 'title' => ts('Payment Processor Selection'), + 'type' => 'Boolean', + 'quick_form_type' => 'YesNo', + 'default' => TRUE, + 'html_type' => 'radio', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('Show/Hide Payment Processor Selection'), + 'help_text' => '', + 'section' => 'fee', + ], + 'eventsextras_pending_participant_expiration' => [ + 'name' => 'eventsextras_pending_participant_expiration', + 'title' => ts('Pending Participant Expiration'), + 'type' => 'Boolean', + 'quick_form_type' => 'YesNo', + 'default' => TRUE, + 'html_type' => 'radio', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('Show/Hide Pending Participant Expiration'), + 'help_text' => '', + 'section' => 'online_registration', + ], + 'eventsextras_allow_self_service' => [ + 'name' => 'eventsextras_allow_self_service', + 'title' => ts('Allow Self Service'), + 'type' => 'Boolean', + 'quick_form_type' => 'YesNo', + 'default' => TRUE, + 'html_type' => 'radio', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('Show/Hide Allow self-service cancellation or transfer?'), + 'help_text' => '', + 'section' => 'online_registration', + ], + 'eventsextras_register_multiple_participants' => [ + 'name' => 'eventsextras_register_multiple_participants', + 'title' => ts('Register Multiple Participants'), + 'type' => 'Boolean', + 'quick_form_type' => 'YesNo', + 'default' => TRUE, + 'html_type' => 'radio', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('Show/Hide Register multiple participants?'), + 'help_text' => '', + 'section' => 'online_registration', + ], ]; \ No newline at end of file diff --git a/templates/CRM/Eventsextras/Form/Settings.tpl b/templates/CRM/Eventsextras/Form/Settings.tpl new file mode 100644 index 0000000..e4ed271 --- /dev/null +++ b/templates/CRM/Eventsextras/Form/Settings.tpl @@ -0,0 +1,63 @@ +{* + +--------------------------------------------------------------------+ + | 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 | + +--------------------------------------------------------------------+ +*} +
+
+ {include file="CRM/common/formButtons.tpl" location="bottom"} +
+

{ts}Front Page Settings{/ts}

+ {foreach from=$frontpageConfigSection item=elementName} +
+
{$form.$elementName.label}
+
+ {$form.$elementName.html} +
+
+
+ {/foreach} +

{ts}Fees Settings{/ts}

+ {foreach from=$feeConfigSection item=elementName} +
+
{$form.$elementName.label}
+
+ {$form.$elementName.html} +
+
+
+ {/foreach} +

{ts}Online Registration Settings{/ts}

+ {foreach from=$onlineRegistrationSection item=elementName} +
+
{$form.$elementName.label}
+
+ {$form.$elementName.html} +
+
+
+ {/foreach} +
+ {include file="CRM/common/formButtons.tpl" location="bottom"} +
+
diff --git a/xml/Menu/eventsextras.xml b/xml/Menu/eventsextras.xml new file mode 100644 index 0000000..065500d --- /dev/null +++ b/xml/Menu/eventsextras.xml @@ -0,0 +1,10 @@ + + + + civicrm/admin/setting/preferences/eventsextras + reset=1 + CRM_Eventsextras_Form_Settings + Events Extra Settings + administer CiviCRM + + From 8066edf37b324dd7bbc2c2e1e1b7f3e9e8c268e4 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Tue, 18 Jun 2019 10:22:41 +0100 Subject: [PATCH 02/97] RSE-203: Removed unwanted comment --- CRM/Eventsextras/Form/Settings.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/CRM/Eventsextras/Form/Settings.php b/CRM/Eventsextras/Form/Settings.php index 9fbf58e..8273a11 100644 --- a/CRM/Eventsextras/Form/Settings.php +++ b/CRM/Eventsextras/Form/Settings.php @@ -47,10 +47,6 @@ public function buildQuickForm() { E::ts($config['title']), array(1 => E::ts('Show'), 0 => E::ts('Hide')) ); - /*$this->addYesNo( - $name, - $config['title'] - );*/ $this->divideConfigSections($name, $config['section']); } $this->addButtons([ From 524bfec2c2e6a8bf33eccaf0c7bd29a0e27e1bed Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Tue, 18 Jun 2019 10:56:48 +0100 Subject: [PATCH 03/97] RSE-203: Added Help Text --- templates/CRM/Eventsextras/Form/Settings.hlp | 81 ++++++++++++++++++++ templates/CRM/Eventsextras/Form/Settings.tpl | 8 +- 2 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 templates/CRM/Eventsextras/Form/Settings.hlp diff --git a/templates/CRM/Eventsextras/Form/Settings.hlp b/templates/CRM/Eventsextras/Form/Settings.hlp new file mode 100644 index 0000000..f6bb0f3 --- /dev/null +++ b/templates/CRM/Eventsextras/Form/Settings.hlp @@ -0,0 +1,81 @@ + +{htxt id="eventsextras_roles"} + {ts} + Show/Hide Default Role. + If hide is selected, admin can set a global default from available options. + {/ts} +{/htxt} + +{htxt id="eventsextras_participant_listing"} + {ts} + Show/Hide: Participant listing + If hide is selected, admin can set a global default (default to disabled) + {/ts} +{/htxt} + +{htxt id="eventsextras_event_summary"} + {ts}Show/Hide: Events summary{/ts} +{/htxt} + +{htxt id="eventsextras_completed_description"} + {ts}Show/Hide: Complete description{/ts} +{/htxt} + +{htxt id="eventsextras_completed_description"} + {ts}Show/Hide: Complete description{/ts} +{/htxt} + +{htxt id="eventsextras_include_map_event_location"} + {ts} + Show/Hide: Include Map to Event Location. + If hide is selected, admin can set a global default from available options + {/ts} +{/htxt} + +{htxt id="eventsextras_public_event"} + {ts} + Show/Hide: Public Event, + If hide is selected, admin can set a global default from available options + {/ts} +{/htxt} + +{htxt id="eventsextras_currency"} + {ts} + Show/Hide: Currency. + if hide is selected, admin can set a global default from available options + {/ts} +{/htxt} + +{htxt id="eventsextras_enable_pay_later_option"} + {ts} + Show/Hide: Enable pay later option + if hide is selected, admin can set a global default from available options + {/ts} +{/htxt} + +{htxt id="eventsextras_payment_processor_selection"} + {ts} + Show/Hide: Payment Processor selection + if hide is selected, admin can set a global default from available options + {/ts} +{/htxt} + +{htxt id="eventsextras_pending_participant_expiration"} + {ts}Show/Hide: Pending participant expiration (hours) + If hide is selected, admin can set a global default from available options + {/ts} +{/htxt} + +{htxt id="eventsextras_allow_self_service"} + {ts} + Show/Hide: Allow self-service cancellation or transfer? + If hide is selected, admin can set a global default from available options + {/ts} +{/htxt} + +{htxt id="eventsextras_register_multiple_participants"} + {ts} + Show/Hide: Register multiple participants + If hide is selected, admin can set a global default from available options + {/ts} +{/htxt} diff --git a/templates/CRM/Eventsextras/Form/Settings.tpl b/templates/CRM/Eventsextras/Form/Settings.tpl index e4ed271..9738d7b 100644 --- a/templates/CRM/Eventsextras/Form/Settings.tpl +++ b/templates/CRM/Eventsextras/Form/Settings.tpl @@ -29,8 +29,8 @@

{ts}Front Page Settings{/ts}

{foreach from=$frontpageConfigSection item=elementName} -
-
{$form.$elementName.label}
+
+
{$form.$elementName.label} {help id=$form.$elementName.name}
{$form.$elementName.html}
@@ -40,7 +40,7 @@

{ts}Fees Settings{/ts}

{foreach from=$feeConfigSection item=elementName}
-
{$form.$elementName.label}
+
{$form.$elementName.label} {help id=$form.$elementName.name}
{$form.$elementName.html}
@@ -50,7 +50,7 @@

{ts}Online Registration Settings{/ts}

{foreach from=$onlineRegistrationSection item=elementName}
-
{$form.$elementName.label}
+
{$form.$elementName.label} {help id=$form.$elementName.name}
{$form.$elementName.html}
From 836c20e26eb21427df8d8ff426d507df47462938 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Tue, 18 Jun 2019 10:57:14 +0100 Subject: [PATCH 04/97] added include map to event location setting --- CRM/Eventsextras/SettingsManager.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/CRM/Eventsextras/SettingsManager.php b/CRM/Eventsextras/SettingsManager.php index df4d1a8..09c5271 100644 --- a/CRM/Eventsextras/SettingsManager.php +++ b/CRM/Eventsextras/SettingsManager.php @@ -13,6 +13,7 @@ class CRM_EventsExtras_SettingsManager { 'eventsextras_participant_listing', 'eventsextras_event_summary', 'eventsextras_completed_description', + 'eventsextras_include_map_event_location', 'eventsextras_public_event', 'eventsextras_currency', 'eventsextras_enable_pay_later_option', @@ -53,9 +54,5 @@ private static function fetchSettingFields() { } return $settingFields; } - - - - } From fb64f3344786a132ce5b2a4b4d1edc9d7f441179 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Tue, 18 Jun 2019 14:58:41 +0100 Subject: [PATCH 05/97] RSE-203: Resolved code to compile with coding standard --- CRM/Eventsextras/Form/Settings.php | 30 +++++++++----------- CRM/Eventsextras/SettingsManager.php | 3 +- eventsextras.civix.php | 10 +++---- eventsextras.php | 2 +- info.xml | 2 +- templates/CRM/Eventsextras/Form/Settings.hlp | 4 --- xml/Menu/eventsextras.xml | 2 +- 7 files changed, 22 insertions(+), 31 deletions(-) diff --git a/CRM/Eventsextras/Form/Settings.php b/CRM/Eventsextras/Form/Settings.php index 8273a11..0d7758c 100644 --- a/CRM/Eventsextras/Form/Settings.php +++ b/CRM/Eventsextras/Form/Settings.php @@ -1,14 +1,14 @@ $config) { + $configFields = SettingsManager::getConfigFields(); + foreach ($configFields as $name => $config) { $this->addRadio( $name, E::ts($config['title']), - array(1 => E::ts('Show'), 0 => E::ts('Hide')) + [1 => E::ts('Show'), 0 => E::ts('Hide')] ); - $this->divideConfigSections($name, $config['section']); + $this->assignConfigSections($name, $config['section']); } $this->addButtons([ [ @@ -72,9 +69,9 @@ public function postProcess() { $valuesToSave = array_intersect_key($submittedValues, $configFields); $result = civicrm_api3('setting', 'create', $valuesToSave); $session = CRM_Core_Session::singleton(); - if($result['is_error']== 0){ + if( $result['is_error']== 0){ $session->setStatus(E::ts('Settings have been saved'),ts('Events Extra Settings'), 'success'); - }else{ + } else{ $session->setStatus(E::ts('Settings could not be saved, please contact Administrator'),ts('Events Extra Settings'), 'error'); } } @@ -97,12 +94,12 @@ public function setDefaultValues() { } /** - * Divides fields between UI sections + * Assign fields between UI sections * - * @param $name - * @param $section + * @param string $name + * @param string $section */ - private function divideConfigSections($name, $section) { + private function assignConfigSections($name, $section) { switch ($section) { case 'front_page': $this->frontpageConfig[] = $name; @@ -115,7 +112,6 @@ private function divideConfigSections($name, $section) { case 'online_registration': $this->onlineRegistrationConfig[] = $name; break; - } } } diff --git a/CRM/Eventsextras/SettingsManager.php b/CRM/Eventsextras/SettingsManager.php index 09c5271..ba358b2 100644 --- a/CRM/Eventsextras/SettingsManager.php +++ b/CRM/Eventsextras/SettingsManager.php @@ -54,5 +54,4 @@ private static function fetchSettingFields() { } return $settingFields; } -} - +} \ No newline at end of file diff --git a/eventsextras.civix.php b/eventsextras.civix.php index 8550e51..07ff10a 100644 --- a/eventsextras.civix.php +++ b/eventsextras.civix.php @@ -6,10 +6,10 @@ * The ExtensionUtil class provides small stubs for accessing resources of this * extension. */ -class CRM_Eventsextras_ExtensionUtil { +class CRM_EventsExtras_ExtensionUtil { const SHORT_NAME = "eventsextras"; const LONG_NAME = "uk.co.compucorp.eventsextras"; - const CLASS_PREFIX = "CRM_Eventsextras"; + const CLASS_PREFIX = "CRM_EventsExtras"; /** * Translate a string using the extension's domain. @@ -77,7 +77,7 @@ public static function findClass($suffix) { } -use CRM_Eventsextras_ExtensionUtil as E; +use CRM_EventsExtras_ExtensionUtil as E; /** * (Delegated) Implements hook_civicrm_config(). @@ -205,14 +205,14 @@ function _eventsextras_civix_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) } /** - * @return CRM_Eventsextras_Upgrader + * @return CRM_EventsExtras_Upgrader */ function _eventsextras_civix_upgrader() { if (!file_exists(__DIR__ . '/CRM/Eventsextras/Upgrader.php')) { return NULL; } else { - return CRM_Eventsextras_Upgrader_Base::instance(); + return CRM_EventsExtras_Upgrader_Base::instance(); } } diff --git a/eventsextras.php b/eventsextras.php index 9fbec0b..dc22256 100644 --- a/eventsextras.php +++ b/eventsextras.php @@ -1,7 +1,7 @@ This is a new, undeveloped module - CRM/Eventsextras + CRM/EventsExtras diff --git a/templates/CRM/Eventsextras/Form/Settings.hlp b/templates/CRM/Eventsextras/Form/Settings.hlp index f6bb0f3..533d487 100644 --- a/templates/CRM/Eventsextras/Form/Settings.hlp +++ b/templates/CRM/Eventsextras/Form/Settings.hlp @@ -21,10 +21,6 @@ {ts}Show/Hide: Complete description{/ts} {/htxt} -{htxt id="eventsextras_completed_description"} - {ts}Show/Hide: Complete description{/ts} -{/htxt} - {htxt id="eventsextras_include_map_event_location"} {ts} Show/Hide: Include Map to Event Location. diff --git a/xml/Menu/eventsextras.xml b/xml/Menu/eventsextras.xml index 065500d..cd992b0 100644 --- a/xml/Menu/eventsextras.xml +++ b/xml/Menu/eventsextras.xml @@ -3,7 +3,7 @@ civicrm/admin/setting/preferences/eventsextras reset=1 - CRM_Eventsextras_Form_Settings + CRM_EventsExtras_Form_Settings Events Extra Settings administer CiviCRM From fa74ad4a500bf422d8232891099930ad1a91ccf5 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Tue, 18 Jun 2019 17:15:02 +0100 Subject: [PATCH 06/97] RSE-203: Rename Eventsextras to EventExtras --- CRM/{Eventsextras => EventsExtras}/Form/Settings.php | 0 CRM/{Eventsextras => EventsExtras}/SettingsManager.php | 0 templates/CRM/{Eventsextras => EventsExtras}/Form/Settings.hlp | 0 templates/CRM/{Eventsextras => EventsExtras}/Form/Settings.tpl | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename CRM/{Eventsextras => EventsExtras}/Form/Settings.php (100%) rename CRM/{Eventsextras => EventsExtras}/SettingsManager.php (100%) rename templates/CRM/{Eventsextras => EventsExtras}/Form/Settings.hlp (100%) rename templates/CRM/{Eventsextras => EventsExtras}/Form/Settings.tpl (100%) diff --git a/CRM/Eventsextras/Form/Settings.php b/CRM/EventsExtras/Form/Settings.php similarity index 100% rename from CRM/Eventsextras/Form/Settings.php rename to CRM/EventsExtras/Form/Settings.php diff --git a/CRM/Eventsextras/SettingsManager.php b/CRM/EventsExtras/SettingsManager.php similarity index 100% rename from CRM/Eventsextras/SettingsManager.php rename to CRM/EventsExtras/SettingsManager.php diff --git a/templates/CRM/Eventsextras/Form/Settings.hlp b/templates/CRM/EventsExtras/Form/Settings.hlp similarity index 100% rename from templates/CRM/Eventsextras/Form/Settings.hlp rename to templates/CRM/EventsExtras/Form/Settings.hlp diff --git a/templates/CRM/Eventsextras/Form/Settings.tpl b/templates/CRM/EventsExtras/Form/Settings.tpl similarity index 100% rename from templates/CRM/Eventsextras/Form/Settings.tpl rename to templates/CRM/EventsExtras/Form/Settings.tpl From d6c37a8bfbdfb9e25173f2a8b8fe019b1bc2a978 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Tue, 18 Jun 2019 17:17:49 +0100 Subject: [PATCH 07/97] RSE-203: fixed the space --- CRM/EventsExtras/Form/Settings.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CRM/EventsExtras/Form/Settings.php b/CRM/EventsExtras/Form/Settings.php index 0d7758c..329456b 100644 --- a/CRM/EventsExtras/Form/Settings.php +++ b/CRM/EventsExtras/Form/Settings.php @@ -34,7 +34,6 @@ class CRM_EventsExtras_Form_Settings extends CRM_Core_Form { */ private $onlineRegistrationConfig = []; - public function buildQuickForm() { CRM_Utils_System::setTitle(E::ts('CiviEvent Extras Settings')); $configFields = SettingsManager::getConfigFields(); @@ -69,7 +68,7 @@ public function postProcess() { $valuesToSave = array_intersect_key($submittedValues, $configFields); $result = civicrm_api3('setting', 'create', $valuesToSave); $session = CRM_Core_Session::singleton(); - if( $result['is_error']== 0){ + if ($result['is_error']== 0){ $session->setStatus(E::ts('Settings have been saved'),ts('Events Extra Settings'), 'success'); } else{ $session->setStatus(E::ts('Settings could not be saved, please contact Administrator'),ts('Events Extra Settings'), 'error'); From 6107b23bb96db80365afec1b5da6c55f19b5f1da Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Tue, 18 Jun 2019 18:09:44 +0100 Subject: [PATCH 08/97] RSE-203: use 1 loop to display from element --- CRM/EventsExtras/Form/Settings.php | 45 +++++++------------- templates/CRM/EventsExtras/Form/Settings.tpl | 44 ++++++------------- 2 files changed, 28 insertions(+), 61 deletions(-) diff --git a/CRM/EventsExtras/Form/Settings.php b/CRM/EventsExtras/Form/Settings.php index 329456b..02581f7 100644 --- a/CRM/EventsExtras/Form/Settings.php +++ b/CRM/EventsExtras/Form/Settings.php @@ -9,30 +9,18 @@ * @see https://wiki.civicrm.org/confluence/display/CRMDOC/QuickForm+Reference */ class CRM_EventsExtras_Form_Settings extends CRM_Core_Form { - - /** - * Contains array of names, which must be displayed - * in Font Page configuration section - * - * @var string[] - */ - private $frontpageConfig = []; /** * Contains array of names, which must be displayed - * in fee configuration section + * in configuration section * - * @var string[] + * @var array[] */ - private $feeConfig = []; - - /** - * Contains array of names, which must be displayed - * in online registration configuration section - * - * @var string[] - */ - private $onlineRegistrationConfig = []; + private $displaySections = [ + 'front_page' => ['name' => 'Front Page Settings'], + 'fee' => ['name' => 'Fee Settings'], + 'online_registration' => ['name' => 'Online Registration Settings'], + ]; public function buildQuickForm() { CRM_Utils_System::setTitle(E::ts('CiviEvent Extras Settings')); @@ -48,18 +36,15 @@ public function buildQuickForm() { $this->addButtons([ [ 'type' => 'submit', - 'name' => ts('Submit'), + 'name' => E::ts('Submit'), 'isDefault' => TRUE, ], [ 'type' => 'cancel', - 'name' => ts('Cancel'), + 'name' => E::ts('Cancel'), ], ]); - - $this->assign('frontpageConfigSection', $this->frontpageConfig); - $this->assign('feeConfigSection', $this->feeConfig); - $this->assign('onlineRegistrationSection', $this->onlineRegistrationConfig);; + $this->assign('displaySections', $this->displaySections); } public function postProcess() { @@ -69,9 +54,9 @@ public function postProcess() { $result = civicrm_api3('setting', 'create', $valuesToSave); $session = CRM_Core_Session::singleton(); if ($result['is_error']== 0){ - $session->setStatus(E::ts('Settings have been saved'),ts('Events Extra Settings'), 'success'); + $session->setStatus(E::ts('Settings have been saved'),E::ts('Events Extra Settings'), 'success'); } else{ - $session->setStatus(E::ts('Settings could not be saved, please contact Administrator'),ts('Events Extra Settings'), 'error'); + $session->setStatus(E::ts('Settings could not be saved, please contact Administrator'),E::ts('Events Extra Settings'), 'error'); } } @@ -101,15 +86,15 @@ public function setDefaultValues() { private function assignConfigSections($name, $section) { switch ($section) { case 'front_page': - $this->frontpageConfig[] = $name; + $this->displaySections['front_page']['fields'][] = $name; break; case 'fee': - $this->feeConfig[] = $name; + $this->displaySections['fee']['fields'][] = $name; break; case 'online_registration': - $this->onlineRegistrationConfig[] = $name; + $this->displaySections['online_registration']['fields'][] = $name; break; } } diff --git a/templates/CRM/EventsExtras/Form/Settings.tpl b/templates/CRM/EventsExtras/Form/Settings.tpl index 9738d7b..bef368f 100644 --- a/templates/CRM/EventsExtras/Form/Settings.tpl +++ b/templates/CRM/EventsExtras/Form/Settings.tpl @@ -27,37 +27,19 @@
{include file="CRM/common/formButtons.tpl" location="bottom"}
-

{ts}Front Page Settings{/ts}

- {foreach from=$frontpageConfigSection item=elementName} -
-
{$form.$elementName.label} {help id=$form.$elementName.name}
-
- {$form.$elementName.html} + {foreach from=$displaySections item=section} +

{ts}{$section.name}{/ts}

+ {foreach from=$section.fields item=elementName} +
+
{$form.$elementName.label} {help id=$form.$elementName.name}
+
+ {$form.$elementName.html} +
+
-
-
- {/foreach} -

{ts}Fees Settings{/ts}

- {foreach from=$feeConfigSection item=elementName} -
-
{$form.$elementName.label} {help id=$form.$elementName.name}
-
- {$form.$elementName.html} -
-
-
- {/foreach} -

{ts}Online Registration Settings{/ts}

- {foreach from=$onlineRegistrationSection item=elementName} -
-
{$form.$elementName.label} {help id=$form.$elementName.name}
-
- {$form.$elementName.html} -
-
-
{/foreach} -
- {include file="CRM/common/formButtons.tpl" location="bottom"} -
+ {/foreach} +
+ {include file="CRM/common/formButtons.tpl" location="bottom"} +
From c8406fbe81a27248259c65963627be073acb4eae Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Wed, 19 Jun 2019 17:36:41 +0100 Subject: [PATCH 09/97] RSE-204: Added extra attributes and put section under extra attributes so we can have dynamic hiding --- settings/EventsExtras.setting.php | 66 ++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 15 deletions(-) diff --git a/settings/EventsExtras.setting.php b/settings/EventsExtras.setting.php index 009175b..98c0179 100644 --- a/settings/EventsExtras.setting.php +++ b/settings/EventsExtras.setting.php @@ -14,8 +14,11 @@ 'is_domain' => 1, 'is_contact' => 0, 'description' => ts('Show/Hide Default Role'), - 'help_text' => 'help ka', - 'section' => 'front_page', + 'help_text' => '', + 'extra_attributes' => [ + 'section' => 'event_info', + 'css_class' => 'crm-event-manage-eventinfo-form-block-default_role_id', + ], ], 'eventsextras_participant_listing' => [ 'name' => 'eventsextras_participant_listing', @@ -28,8 +31,11 @@ 'is_domain' => 1, 'is_contact' => 0, 'description' => ts('Show/Hide Participant listing'), - 'help_text' => 'help 2', - 'section' => 'front_page', + 'help_text' => '', + 'extra_attributes' => [ + 'section' => 'event_info', + 'css_class' => 'crm-event-manage-eventinfo-form-block-participant_listing_id', + ], ], 'eventsextras_event_summary' => [ 'name' => 'eventsextras_event_summary', @@ -43,10 +49,13 @@ 'is_contact' => 0, 'description' => ts('Show/Hide Event Summary'), 'help_text' => '', - 'section' => 'front_page', + 'extra_attributes' => [ + 'section' => 'event_info', + 'css_class' => 'crm-event-manage-eventinfo-form-block-summary', + ], ], 'eventsextras_completed_description' => [ - 'name' => 'eventsExtrasCompleteDescription', + 'name' => 'eventsextras_event_summary', 'title' => ts('Complete Description'), 'type' => 'Boolean', 'quick_form_type' => 'YesNo', @@ -57,7 +66,10 @@ 'is_contact' => 0, 'description' => ts('Show/Hide Complete Description'), 'help_text' => '', - 'section' => 'front_page', + 'extra_attributes' => [ + 'section' => 'event_info', + 'css_class' => 'crm-event-manage-eventinfo-form-block-description', + ], ], 'eventsextras_include_map_event_location' => [ 'name' => 'eventsextras_include_map_event_location', @@ -71,7 +83,10 @@ 'is_contact' => 0, 'description' => ts('Show/Hide Include Map to Event Location'), 'help_text' => '', - 'section' => 'front_page', + 'extra_attributes' => [ + 'section' => 'event_info', + 'css_class' => 'crm-event-manage-eventinfo-form-block-is_map', + ], ], 'eventsextras_public_event' => [ 'name' => 'eventsextras_public_event', @@ -85,7 +100,10 @@ 'is_contact' => 0, 'description' => ts('Show/Hide Public Event'), 'help_text' => '', - 'section' => 'front_page', + 'extra_attributes' => [ + 'section' => 'event_info', + 'css_class' => 'crm-event-manage-eventinfo-form-block-is_public', + ], ], 'eventsextras_currency' => [ 'name' => 'eventsextras_currency', @@ -99,7 +117,10 @@ 'is_contact' => 0, 'description' => ts('Show/Hide Currency'), 'help_text' => '', - 'section' => 'fee', + 'extra_attributes' => [ + 'section' => 'event_fee', + 'css_class' => 'crm-event-manage-fee-form-block-currency', + ], ], 'eventsextras_enable_pay_later_option' => [ 'name' => 'eventsextras_enable_pay_later_option', @@ -113,7 +134,10 @@ 'is_contact' => 0, 'description' => ts('Show/Hide Enable pay later option'), 'help_text' => '', - 'section' => 'fee', + 'extra_attributes' => [ + 'section' => 'event_fee', + 'css_class' => 'crm-event-manage-fee-form-block-is_pay_later', + ], ], 'eventsextras_payment_processor_selection' => [ 'name' => 'eventsextras_payment_processor_selection', @@ -127,7 +151,10 @@ 'is_contact' => 0, 'description' => ts('Show/Hide Payment Processor Selection'), 'help_text' => '', - 'section' => 'fee', + 'extra_attributes' => [ + 'section' => 'event_fee', + 'css_class' => 'crm-event-manage-fee-form-block-payment_processor', + ], ], 'eventsextras_pending_participant_expiration' => [ 'name' => 'eventsextras_pending_participant_expiration', @@ -141,7 +168,10 @@ 'is_contact' => 0, 'description' => ts('Show/Hide Pending Participant Expiration'), 'help_text' => '', - 'section' => 'online_registration', + 'extra_attributes' => [ + 'section' => 'event_online_registration', + 'css_class' => 'crm-event-manage-registration-form-block-expiration_time', + ], ], 'eventsextras_allow_self_service' => [ 'name' => 'eventsextras_allow_self_service', @@ -155,7 +185,10 @@ 'is_contact' => 0, 'description' => ts('Show/Hide Allow self-service cancellation or transfer?'), 'help_text' => '', - 'section' => 'online_registration', + 'extra_attributes' => [ + 'section' => 'event_online_registration', + 'css_class' => 'crm-event-manage-registration-form-block-selfcancelxfer', + ], ], 'eventsextras_register_multiple_participants' => [ 'name' => 'eventsextras_register_multiple_participants', @@ -169,6 +202,9 @@ 'is_contact' => 0, 'description' => ts('Show/Hide Register multiple participants?'), 'help_text' => '', - 'section' => 'online_registration', + 'extra_attributes' => [ + 'section' => 'event_online_registration', + 'css_class' => 'crm-event-manage-registration-form-block-is_multiple_registrations', + ], ], ]; \ No newline at end of file From 2aaa6f970413d020d508f4e3912f12e5298bfc0f Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Wed, 19 Jun 2019 17:38:06 +0100 Subject: [PATCH 10/97] RSE-204: Create constrants as per seetings and create getSettingsValue function --- CRM/EventsExtras/SettingsManager.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/CRM/EventsExtras/SettingsManager.php b/CRM/EventsExtras/SettingsManager.php index ba358b2..d71a160 100644 --- a/CRM/EventsExtras/SettingsManager.php +++ b/CRM/EventsExtras/SettingsManager.php @@ -5,6 +5,13 @@ */ class CRM_EventsExtras_SettingsManager { + /** + * Constants for setting sections + */ + const EVENT_INFO = 'event_info'; + const EVENT_FEE = 'event_fee'; + const EVENT_REGISTRATION = 'event_online_registration'; + /** * Constants value for settings name */ @@ -23,6 +30,18 @@ class CRM_EventsExtras_SettingsManager { 'eventsextras_register_multiple_participants', ]; + /** + * Gets the settings Value + * + * @return array + */ + public static function getSettingsValue(){ + return civicrm_api3('setting', 'get', [ + 'return' => self::SETTING_FIELDS, + 'sequential' => 1, + ])['values'][0]; + } + /** * Gets the extension configuration fields * From 684aba537e65533ca4e8635806eb3001fe636903 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Wed, 19 Jun 2019 17:39:33 +0100 Subject: [PATCH 11/97] RSE-204: Update setting form to use constants for displaying --- CRM/EventsExtras/Form/Settings.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/CRM/EventsExtras/Form/Settings.php b/CRM/EventsExtras/Form/Settings.php index 02581f7..4141a12 100644 --- a/CRM/EventsExtras/Form/Settings.php +++ b/CRM/EventsExtras/Form/Settings.php @@ -17,9 +17,9 @@ class CRM_EventsExtras_Form_Settings extends CRM_Core_Form { * @var array[] */ private $displaySections = [ - 'front_page' => ['name' => 'Front Page Settings'], - 'fee' => ['name' => 'Fee Settings'], - 'online_registration' => ['name' => 'Online Registration Settings'], + SettingsManager::EVENT_INFO => ['name' => 'Event Info Settings'], + SettingsManager::EVENT_FEE => ['name' => 'Fee Settings'], + SettingsManager::EVENT_REGISTRATION => ['name' => 'Online Registration Settings'], ]; public function buildQuickForm() { @@ -31,7 +31,7 @@ public function buildQuickForm() { E::ts($config['title']), [1 => E::ts('Show'), 0 => E::ts('Hide')] ); - $this->assignConfigSections($name, $config['section']); + $this->assignConfigSections($name, $config['extra_attributes']['section']); } $this->addButtons([ [ @@ -85,16 +85,16 @@ public function setDefaultValues() { */ private function assignConfigSections($name, $section) { switch ($section) { - case 'front_page': - $this->displaySections['front_page']['fields'][] = $name; + case SettingsManager::EVENT_INFO: + $this->displaySections[SettingsManager::EVENT_INFO]['fields'][] = $name; break; - case 'fee': - $this->displaySections['fee']['fields'][] = $name; + case SettingsManager::EVENT_FEE: + $this->displaySections[SettingsManager::EVENT_FEE]['fields'][] = $name; break; - case 'online_registration': - $this->displaySections['online_registration']['fields'][] = $name; + case SettingsManager::EVENT_REGISTRATION: + $this->displaySections[SettingsManager::EVENT_REGISTRATION]['fields'][] = $name; break; } } From 4b950cd4f49698089dd6f2facd5584afdd4b2eb4 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Wed, 19 Jun 2019 17:48:24 +0100 Subject: [PATCH 12/97] RSE-204: Implement BuildForm Hook to hide the element as per settings --- CRM/EventsExtras/Hook/BuildForm.php | 49 +++++++++++++++++++ CRM/EventsExtras/Hook/BuildForm/EventFee.php | 23 +++++++++ CRM/EventsExtras/Hook/BuildForm/EventInfo.php | 23 +++++++++ .../Hook/BuildForm/EventRegistration.php | 23 +++++++++ eventsextras.php | 21 ++++++++ templates/CRM/EventsExtras/Form/EventTabs.tpl | 39 +++++++++++++++ 6 files changed, 178 insertions(+) create mode 100644 CRM/EventsExtras/Hook/BuildForm.php create mode 100644 CRM/EventsExtras/Hook/BuildForm/EventFee.php create mode 100644 CRM/EventsExtras/Hook/BuildForm/EventInfo.php create mode 100644 CRM/EventsExtras/Hook/BuildForm/EventRegistration.php create mode 100644 templates/CRM/EventsExtras/Form/EventTabs.tpl diff --git a/CRM/EventsExtras/Hook/BuildForm.php b/CRM/EventsExtras/Hook/BuildForm.php new file mode 100644 index 0000000..e45f275 --- /dev/null +++ b/CRM/EventsExtras/Hook/BuildForm.php @@ -0,0 +1,49 @@ +eventTab = $eventTab; + $templatePath = E::path() . '/templates/CRM/EventsExtras/Form/EventTabs.tpl'; + CRM_Core_Region::instance('page-body')->add([ + 'template' => "{$templatePath}" + ]); + } + + /** + * fuction to hide fields based on settings + * + * @param array $$form + * + */ + protected function hideField(CRM_Event_Form_ManageEvent &$form){ + $configFields = SettingsManager::getConfigFields(); + $settingsValue = SettingsManager::getSettingsValue(); + $hiddenFields = []; + foreach ($configFields as $config) { + if ($settingsValue[$config['name']] == 0){ + if ($config['extra_attributes']['section'] == $this->eventTab){ + $hiddenFields[] = $config['extra_attributes']['css_class']; + } + } + } + $form->assign('hiddenCssClasses', $hiddenFields); + } +} \ No newline at end of file diff --git a/CRM/EventsExtras/Hook/BuildForm/EventFee.php b/CRM/EventsExtras/Hook/BuildForm/EventFee.php new file mode 100644 index 0000000..f3a49fa --- /dev/null +++ b/CRM/EventsExtras/Hook/BuildForm/EventFee.php @@ -0,0 +1,23 @@ +hideField($form); + } + +} \ No newline at end of file diff --git a/CRM/EventsExtras/Hook/BuildForm/EventInfo.php b/CRM/EventsExtras/Hook/BuildForm/EventInfo.php new file mode 100644 index 0000000..b7d028b --- /dev/null +++ b/CRM/EventsExtras/Hook/BuildForm/EventInfo.php @@ -0,0 +1,23 @@ +hideField($form); + } + +} \ No newline at end of file diff --git a/CRM/EventsExtras/Hook/BuildForm/EventRegistration.php b/CRM/EventsExtras/Hook/BuildForm/EventRegistration.php new file mode 100644 index 0000000..506d36e --- /dev/null +++ b/CRM/EventsExtras/Hook/BuildForm/EventRegistration.php @@ -0,0 +1,23 @@ +hideField($form); + } + +} \ No newline at end of file diff --git a/eventsextras.php b/eventsextras.php index dc22256..0d6a2c8 100644 --- a/eventsextras.php +++ b/eventsextras.php @@ -2,6 +2,27 @@ require_once 'eventsextras.civix.php'; use CRM_EventsExtras_ExtensionUtil as E; +use CRM_EventsExtras_SettingsManager as SettingsManager; + +/** + * Implements hook_civicrm_buildForm(). + * + * @link hhttps://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_buildForm/ + */ +function eventsextras_civicrm_buildForm($formName, &$form){ + if ($formName === 'CRM_Event_Form_ManageEvent_EventInfo'){ + $eventInfoHook = new CRM_EventsExtras_Hook_BuildForm_EventInfo(SettingsManager::EVENT_INFO); + $eventInfoHook->buildForm($form); + } + if ($formName === 'CRM_Event_Form_ManageEvent_Fee'){ + $eventFeeHook = new CRM_EventsExtras_Hook_BuildForm_EventFee(SettingsManager::EVENT_FEE); + $eventFeeHook->buildForm($form); + } + if ($formName === 'CRM_Event_Form_ManageEvent_Registration'){ + $eventFeeRegistration = new CRM_EventsExtras_Hook_BuildForm_EventRegistration(SettingsManager::EVENT_REGISTRATION); + $eventFeeRegistration->buildForm($form); + } +} /** * Implements hook_civicrm_config(). diff --git a/templates/CRM/EventsExtras/Form/EventTabs.tpl b/templates/CRM/EventsExtras/Form/EventTabs.tpl new file mode 100644 index 0000000..2967fe9 --- /dev/null +++ b/templates/CRM/EventsExtras/Form/EventTabs.tpl @@ -0,0 +1,39 @@ +{* + +--------------------------------------------------------------------+ + | 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 | + +--------------------------------------------------------------------+ +*} +{* Hide Info in Event Tabs based on Events Extras Settings. *} + {literal} + + {/literal} \ No newline at end of file From 6c20878d52d73345906d519fded2f3bccb41b4e4 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Thu, 20 Jun 2019 10:36:33 +0100 Subject: [PATCH 13/97] RSE-204: fixed duplicated name --- settings/EventsExtras.setting.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings/EventsExtras.setting.php b/settings/EventsExtras.setting.php index 98c0179..c35a2ba 100644 --- a/settings/EventsExtras.setting.php +++ b/settings/EventsExtras.setting.php @@ -55,7 +55,7 @@ ], ], 'eventsextras_completed_description' => [ - 'name' => 'eventsextras_event_summary', + 'name' => 'eventsextras_event_description', 'title' => ts('Complete Description'), 'type' => 'Boolean', 'quick_form_type' => 'YesNo', From f7898c5457e4be9e5758e3133b72afab9e684f5f Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Thu, 20 Jun 2019 10:36:33 +0100 Subject: [PATCH 14/97] RSE-204: fixed duplicated name --- CRM/EventsExtras/SettingsManager.php | 2 +- settings/EventsExtras.setting.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CRM/EventsExtras/SettingsManager.php b/CRM/EventsExtras/SettingsManager.php index d71a160..117aca1 100644 --- a/CRM/EventsExtras/SettingsManager.php +++ b/CRM/EventsExtras/SettingsManager.php @@ -19,7 +19,7 @@ class CRM_EventsExtras_SettingsManager { 'eventsextras_roles', 'eventsextras_participant_listing', 'eventsextras_event_summary', - 'eventsextras_completed_description', + 'eventsextras_event_description', 'eventsextras_include_map_event_location', 'eventsextras_public_event', 'eventsextras_currency', diff --git a/settings/EventsExtras.setting.php b/settings/EventsExtras.setting.php index 98c0179..cb5ac2e 100644 --- a/settings/EventsExtras.setting.php +++ b/settings/EventsExtras.setting.php @@ -54,8 +54,8 @@ 'css_class' => 'crm-event-manage-eventinfo-form-block-summary', ], ], - 'eventsextras_completed_description' => [ - 'name' => 'eventsextras_event_summary', + 'eventsextras_event_description' => [ + 'name' => 'eventsextras_event_description', 'title' => ts('Complete Description'), 'type' => 'Boolean', 'quick_form_type' => 'YesNo', From 7e70eda1d21aa26343e17902fab59703d5048bb9 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Fri, 21 Jun 2019 11:34:20 +0100 Subject: [PATCH 15/97] RSE-210: Added Settings for storing default --- settings/EventsExtrasDefault.setting.php | 300 +++++++++++++++++++++++ 1 file changed, 300 insertions(+) create mode 100644 settings/EventsExtrasDefault.setting.php diff --git a/settings/EventsExtrasDefault.setting.php b/settings/EventsExtrasDefault.setting.php new file mode 100644 index 0000000..18102a8 --- /dev/null +++ b/settings/EventsExtrasDefault.setting.php @@ -0,0 +1,300 @@ + [ + 'name' => 'eventsextras_roles_default', + 'title' => ts('Set Default Setting of Default Role'), + 'type' => 'Integer', + 'quick_form_type' => 'Select', + 'default' => '', + 'html_type' => 'select', + 'pseudoconstant' => [ + 'optionGroupName' => 'participant_role', + ], + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => '', + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_INFO, + 'parent_setting' => 'eventsextras_roles', + 'class' => 'crm-select2', + 'placeholder' => ts('- Select -'), + ], + ], +'eventsextras_participant_listing_default' => [ + 'name' => 'eventsextras_participant_listing_default', + 'title' => ts('Set Default Setting of Participant Listing'), + 'type' => 'Integer', + 'quick_form_type' => 'Select', + 'default' => '', + 'html_type' => 'select', + 'pseudoconstant' => [ + 'optionGroupName' => 'participant_listing', + ], + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => '', + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_INFO, + 'parent_setting' => 'eventsextras_participant_listing', + 'class' => 'crm-select2', + 'placeholder' => ts('Disabled'), + + ], + ], + 'eventsextras_include_map_event_location_default' => [ + 'name' => 'eventsextras_include_map_event_location_default', + 'title' => ts('Set Default Include Map to Event Location'), + 'type' => 'Integer', + 'quick_form_type' => 'Element', + 'default' => '', + 'html_type' => 'checkbox', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => '', + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_INFO, + 'parent_setting' => 'eventsextras_include_map_event_location', + 'class' => '', + ], +], +'eventsextras_public_event_default' => [ + 'name' => 'eventsextras_public_event_default', + 'title' => ts('Set Default Public Event'), + 'type' => 'Integer', + 'quick_form_type' => 'Element', + 'default' => '', + 'html_type' => 'checkbox', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => '', + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_INFO, + 'parent_setting' => 'eventsextras_public_event', + 'class' => '', + ], + ], + 'eventsextras_currency_default' => [ + 'name' => 'eventsextras_currency_default', + 'title' => ts('Set Default Currency'), + 'type' => 'String', + 'quick_form_type' => 'Select', + 'default' => '', + 'html_type' => 'select', + 'pseudoconstant' => [ + 'optionGroupName' => 'currencies_enabled', + ], + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('Select the currency to be used for event registration.'), + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_FEE, + 'parent_setting' => 'eventsextras_currency', + 'class' => 'crm-select2', + 'placeholder' => ts('--Select--'), + ], + ], + 'eventsextras_payment_processor_selection_default' => [ + 'name' => 'eventsextras_payment_processor_selection_default', + 'title' => ts('Set Default Payment Processor Selection'), + 'type' => 'String', + 'quick_form_type' => 'Checkboxes', + 'default' => TRUE, + 'html_type' => 'checkboxes', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts(' + If this is a paid event and you want users to be able to register and pay online, + select a payment processor to use. NOTE: Alternatively, + you can enable the Pay Later feature below without setting up a payment processor. + All users will then be asked to submit payment offline + (e.g. mail in a check, call in a credit card, etc.). + + (learn more...) + '), + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_FEE, + 'parent_setting' => 'eventsextras_payment_processor', + 'class' => '', + ], + ], + 'eventsextras_enable_pay_later_option_default' => [ + 'name' => 'eventsextras_enable_pay_later_option_default', + 'title' => ts('Enable Default Pay Later option?'), + 'type' => 'String', + 'quick_form_type' => 'Checkbox', + 'default' => '', + 'html_type' => 'checkbox', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('Check this box if you want to give users the option to submit payment offline (e.g. mail in a check, call in a credit card, etc.). '), + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_FEE, + 'parent_setting' => 'eventsextras_enable_pay_later_option', + 'class' => '', + ], + ], + 'eventsextras_enable_pay_later_option_default_label' => [ + 'name' => 'eventsextras_enable_pay_later_option_default_label', + 'title' => ts('Set Default Pay Later Label'), + 'type' => 'String', + 'html_type' => 'textarea', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('Text displayed next to the checkbox for the "pay later" option on the contribution form. You may include HTML formatting tags.'), + 'help_text' => '', + 'is_required' => TRUE, + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_FEE, + 'parent_setting' => 'eventsextras_enable_pay_later_option_default', + 'class' => '', + ], + ], + 'eventsextras_enable_pay_later_option_default_instruction' => [ + 'name' => 'eventsextras_enable_pay_later_option_default_instruction', + 'title' => ts('Set Default Pay Later Instruction'), + 'type' => 'String', + 'html_type' => 'textarea', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('Instructions added to Confirmation and Thank-you pages when the user selects the "pay later" option (e.g. "Mail your check to ... within 3 business days."). '), + 'help_text' => '', + 'is_required' => TRUE, + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_FEE, + 'parent_setting' => 'eventsextras_enable_pay_later_option_default', + 'class' => '', + ], + ], + 'eventsextras_enable_pay_later_option_default_billing_address_required' => [ + 'name' => 'eventsextras_enable_pay_later_option_default_billing_address_required', + 'title' => ts('Set Default Billing Address Required?'), + 'type' => 'Integer', + 'default' => '', + 'html_type' => 'checkbox', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('Check this box to require users who select the pay later option to provide billing name and address.'), + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_FEE, + 'parent_setting' => 'eventsextras_enable_pay_later_option_default', + 'class' => '', + ], + ], + + 'eventsextras_pending_participant_expiration_default' => [ + 'name' => 'eventsextras_pending_participant_expiration_default', + 'title' => ts('Set Default Pending Participant Expiration'), + 'type' => 'Integer', + 'quick_form_type' => 'Text', + 'default' => '', + 'html_type' => 'text', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts(''), + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_REGISTRATION, + 'parent_setting' => 'eventsextras_enable_pay_later_option', + 'class' => '', + ], +], + +'eventsextras_allow_self_service_default' => [ + 'name' => 'eventsextras_allow_self_service_default', + 'title' => ts('Set Default Allow Self-Service Cancellation or Transfer?'), + 'type' => 'Integer', + 'quick_form_type' => 'Checkbox', + 'default' => '', + 'html_type' => 'checkbox', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts(''), + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_REGISTRATION, + 'parent_setting' => 'eventsextras_allow_self_service', + ], +], + +'eventsextras_allow_self_service_default_time_limit' => [ + 'name' => 'eventsextras_allow_self_service_default_time_limit', + 'title' => ts('Set Default Cancellation or transfer time limit (hours) '), + 'type' => 'Integer', + 'quick_form_type' => 'Text', + 'default' => '', + 'html_type' => 'text', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts(''), + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_REGISTRATION, + 'parent_setting' => 'eventsextras_allow_self_service_default', + ], +], + +'eventsextras_register_multiple_participants_default' => [ + 'name' => 'eventsextras_register_multiple_participants_default', + 'title' => ts('Set Default Register multiple participants? '), + 'type' => 'Integer', + 'quick_form_type' => 'Checkbox', + 'default' => '', + 'html_type' => 'checkbox', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts(''), + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_REGISTRATION, + 'parent_setting' => 'eventsextras_register_multiple_participants', + ], +], +'eventsextras_register_multiple_participants_default_maxinum_participant' => [ + 'name' => 'eventsextras_register_multiple_participants_default_maxinum_participant', + 'title' => ts('Set Default Maximum additional participants '), + 'type' => 'Integer', + 'quick_form_type' => 'Select', + 'default' => 9, + 'html_type' => 'select', + 'pseudoconstant' => [ + 'optionGroupName' => '', + ], + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts(''), + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_REGISTRATION, + 'parent_setting' => 'eventsextras_register_multiple_participants_default', + ], + ], +]; \ No newline at end of file From 989f041e727be1833c4b0ca7097248c1e4f7fec9 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Fri, 21 Jun 2019 11:36:02 +0100 Subject: [PATCH 16/97] RSE-210: Display html elemennts for input default settings --- CRM/EventsExtras/Form/Settings.php | 88 ++++++++++++++++++-- CRM/EventsExtras/SettingsManager.php | 16 +++- templates/CRM/EventsExtras/Form/Settings.tpl | 21 ++++- 3 files changed, 115 insertions(+), 10 deletions(-) diff --git a/CRM/EventsExtras/Form/Settings.php b/CRM/EventsExtras/Form/Settings.php index 4141a12..391994b 100644 --- a/CRM/EventsExtras/Form/Settings.php +++ b/CRM/EventsExtras/Form/Settings.php @@ -22,15 +22,29 @@ class CRM_EventsExtras_Form_Settings extends CRM_Core_Form { SettingsManager::EVENT_REGISTRATION => ['name' => 'Online Registration Settings'], ]; + private $parentSettings = []; + private $defaultSettingsDescription = []; + + public function buildQuickForm() { CRM_Utils_System::setTitle(E::ts('CiviEvent Extras Settings')); $configFields = SettingsManager::getConfigFields(); foreach ($configFields as $name => $config) { - $this->addRadio( - $name, - E::ts($config['title']), + if(!array_key_exists('parent_setting', $config['extra_attributes'])){ + $this->addRadio( + $name, + E::ts($config['title']), [1 => E::ts('Show'), 0 => E::ts('Hide')] - ); + ); + $this->parentSettings[$config['name']] = TRUE; + } else { //handle default setting form + if ($config['html_type'] == 'select') { + $this->generateDefaultSelectList($config); + }else { + $this->generateDefaultSettingField($config); + } + $this->defaultSettingsDescription[$config['name']] = $config['description']; + } $this->assignConfigSections($name, $config['extra_attributes']['section']); } $this->addButtons([ @@ -44,6 +58,8 @@ public function buildQuickForm() { 'name' => E::ts('Cancel'), ], ]); + $this->assign('settingsDescription', $this->defaultSettingsDescription); + $this->assign('parentSettings', $this->parentSettings); $this->assign('displaySections', $this->displaySections); } @@ -60,6 +76,68 @@ public function postProcess() { } } + private function generatePaymentProcessorElement($setting){ + $paymentProcessor = CRM_Core_PseudoConstant::paymentProcessor(); + $this->addCheckBox( + $setting['name'], + E::ts($setting['title']), + array_flip($paymentProcessor), + NULL, NULL, NULL, NULL, + array('  ', '  ', '  ', '
') + ); + } + + /** + * Generate a default Setting field to the form. + * + * @param array $field + */ + private function generateDefaultSettingField($setting) { + if ($setting['name'] == 'eventsextras_payment_processor_selection_default') { + $this->generatePaymentProcessorElement($setting); + } else { + $this->add( + $setting['html_type'], + $setting['name'], + E::ts($setting['title']) + ); + } + } + + /** + * Generate select options from settings. + * + * @param array $setting + */ + private function generateDefaultSelectList($setting) { + $options = []; + if (!empty($setting['pseudoconstant']['optionGroupName'])){ + $values = civicrm_api3('OptionGroup', 'get', [ + 'sequential' => 1, + 'name' => $setting['pseudoconstant']['optionGroupName'], + 'api.OptionValue.get' => [' + option_group_id' => "id", + 'return' => ['value', 'label'] + ] + ])['values'][0]['api.OptionValue.get']['values']; + foreach ($values as $value){ + $options[$value['value']] = $value['label']; + } + } else { // for default maxinum participant + foreach (range(1, 9) as $value){ + $options[$value] = $value; + } + } + $this->add( + $setting['html_type'], + $setting['name'], + E::ts($setting['title']), + $options, + FALSE, + $setting['extra_attributes'] + ); + } + /** * Set defaults for form. * @@ -86,7 +164,7 @@ public function setDefaultValues() { private function assignConfigSections($name, $section) { switch ($section) { case SettingsManager::EVENT_INFO: - $this->displaySections[SettingsManager::EVENT_INFO]['fields'][] = $name; + $this->displaySections[SettingsManager::EVENT_INFO]['fields'][$name] = $name; break; case SettingsManager::EVENT_FEE: diff --git a/CRM/EventsExtras/SettingsManager.php b/CRM/EventsExtras/SettingsManager.php index 117aca1..dca8dff 100644 --- a/CRM/EventsExtras/SettingsManager.php +++ b/CRM/EventsExtras/SettingsManager.php @@ -17,17 +17,31 @@ class CRM_EventsExtras_SettingsManager { */ const SETTING_FIELDS = [ 'eventsextras_roles', + 'eventsextras_roles_default', 'eventsextras_participant_listing', + 'eventsextras_participant_listing_default', 'eventsextras_event_summary', 'eventsextras_event_description', 'eventsextras_include_map_event_location', + 'eventsextras_include_map_event_location_default', 'eventsextras_public_event', + 'eventsextras_public_event_default', 'eventsextras_currency', - 'eventsextras_enable_pay_later_option', + 'eventsextras_currency_default', 'eventsextras_payment_processor_selection', + 'eventsextras_payment_processor_selection_default', + 'eventsextras_enable_pay_later_option', + 'eventsextras_enable_pay_later_option_default', + 'eventsextras_enable_pay_later_option_default_label', + 'eventsextras_enable_pay_later_option_default_instruction', + 'eventsextras_enable_pay_later_option_default_billing_address_required', 'eventsextras_pending_participant_expiration', + 'eventsextras_pending_participant_expiration_default', 'eventsextras_allow_self_service', + 'eventsextras_allow_self_service_default', + 'eventsextras_allow_self_service_default_time_limit', 'eventsextras_register_multiple_participants', + 'eventsextras_register_multiple_participants_default_maxinum_participant' ]; /** diff --git a/templates/CRM/EventsExtras/Form/Settings.tpl b/templates/CRM/EventsExtras/Form/Settings.tpl index bef368f..98f4756 100644 --- a/templates/CRM/EventsExtras/Form/Settings.tpl +++ b/templates/CRM/EventsExtras/Form/Settings.tpl @@ -26,15 +26,28 @@
{include file="CRM/common/formButtons.tpl" location="bottom"} -
+
{foreach from=$displaySections item=section}

{ts}{$section.name}{/ts}

{foreach from=$section.fields item=elementName}
-
{$form.$elementName.label} {help id=$form.$elementName.name}
-
+ {if $form.$elementName.type neq 'checkbox'} +
+ {$form.$elementName.label} + {if !$parentSettings.$elementName} {help id=$form.$elementName.name} + {/if} +
+ {/if} +
{$form.$elementName.html} -
+ {if $form.$elementName.type eq 'checkbox'} + {$form.$elementName.label}{if !$parentSettings.$elementName} {help id=$form.$elementName.name} + {/if} + {if !$parentSettings.$elementName} +
{$settingsDescription.$elementName}
+ {/if} + {/if} +
{/foreach} From b451b11cc8b3474054984be8726d17ea7404e39c Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Fri, 21 Jun 2019 11:41:06 +0100 Subject: [PATCH 17/97] RSE-204: Use constants in setting --- settings/EventsExtras.setting.php | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/settings/EventsExtras.setting.php b/settings/EventsExtras.setting.php index cb5ac2e..443a021 100644 --- a/settings/EventsExtras.setting.php +++ b/settings/EventsExtras.setting.php @@ -1,4 +1,6 @@ ts('Show/Hide Default Role'), 'help_text' => '', 'extra_attributes' => [ - 'section' => 'event_info', + 'section' => SettingsManager::EVENT_INFO, 'css_class' => 'crm-event-manage-eventinfo-form-block-default_role_id', ], ], @@ -33,7 +35,7 @@ 'description' => ts('Show/Hide Participant listing'), 'help_text' => '', 'extra_attributes' => [ - 'section' => 'event_info', + 'section' => SettingsManager::EVENT_INFO, 'css_class' => 'crm-event-manage-eventinfo-form-block-participant_listing_id', ], ], @@ -50,7 +52,7 @@ 'description' => ts('Show/Hide Event Summary'), 'help_text' => '', 'extra_attributes' => [ - 'section' => 'event_info', + 'section' => SettingsManager::EVENT_INFO, 'css_class' => 'crm-event-manage-eventinfo-form-block-summary', ], ], @@ -67,7 +69,7 @@ 'description' => ts('Show/Hide Complete Description'), 'help_text' => '', 'extra_attributes' => [ - 'section' => 'event_info', + 'section' => SettingsManager::EVENT_INFO, 'css_class' => 'crm-event-manage-eventinfo-form-block-description', ], ], @@ -84,7 +86,7 @@ 'description' => ts('Show/Hide Include Map to Event Location'), 'help_text' => '', 'extra_attributes' => [ - 'section' => 'event_info', + 'section' => SettingsManager::EVENT_INFO, 'css_class' => 'crm-event-manage-eventinfo-form-block-is_map', ], ], @@ -101,7 +103,7 @@ 'description' => ts('Show/Hide Public Event'), 'help_text' => '', 'extra_attributes' => [ - 'section' => 'event_info', + 'section' => SettingsManager::EVENT_INFO, 'css_class' => 'crm-event-manage-eventinfo-form-block-is_public', ], ], @@ -118,7 +120,7 @@ 'description' => ts('Show/Hide Currency'), 'help_text' => '', 'extra_attributes' => [ - 'section' => 'event_fee', + 'section' => SettingsManager::EVENT_FEE, 'css_class' => 'crm-event-manage-fee-form-block-currency', ], ], @@ -135,7 +137,7 @@ 'description' => ts('Show/Hide Enable pay later option'), 'help_text' => '', 'extra_attributes' => [ - 'section' => 'event_fee', + 'section' => SettingsManager::EVENT_FEE, 'css_class' => 'crm-event-manage-fee-form-block-is_pay_later', ], ], @@ -152,7 +154,7 @@ 'description' => ts('Show/Hide Payment Processor Selection'), 'help_text' => '', 'extra_attributes' => [ - 'section' => 'event_fee', + 'section' => SettingsManager::EVENT_FEE, 'css_class' => 'crm-event-manage-fee-form-block-payment_processor', ], ], @@ -169,7 +171,7 @@ 'description' => ts('Show/Hide Pending Participant Expiration'), 'help_text' => '', 'extra_attributes' => [ - 'section' => 'event_online_registration', + 'section' => SettingsManager::EVENT_REGISTRATION, 'css_class' => 'crm-event-manage-registration-form-block-expiration_time', ], ], @@ -186,7 +188,7 @@ 'description' => ts('Show/Hide Allow self-service cancellation or transfer?'), 'help_text' => '', 'extra_attributes' => [ - 'section' => 'event_online_registration', + 'section' => SettingsManager::EVENT_REGISTRATION, 'css_class' => 'crm-event-manage-registration-form-block-selfcancelxfer', ], ], @@ -203,7 +205,7 @@ 'description' => ts('Show/Hide Register multiple participants?'), 'help_text' => '', 'extra_attributes' => [ - 'section' => 'event_online_registration', + 'section' => SettingsManager::EVENT_REGISTRATION, 'css_class' => 'crm-event-manage-registration-form-block-is_multiple_registrations', ], ], From fad058afcd2330e0f062a577318831917236d322 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Fri, 21 Jun 2019 11:56:14 +0100 Subject: [PATCH 18/97] RSE-204: Restructured base class and removed params on constructur of inherited class --- .../{BuildForm.php => BuildForm/BaseEvent.php} | 16 ++++++++++------ CRM/EventsExtras/Hook/BuildForm/EventFee.php | 11 +++++++---- CRM/EventsExtras/Hook/BuildForm/EventInfo.php | 11 +++++++---- .../Hook/BuildForm/EventRegistration.php | 11 +++++++---- eventsextras.php | 6 +++--- 5 files changed, 34 insertions(+), 21 deletions(-) rename CRM/EventsExtras/Hook/{BuildForm.php => BuildForm/BaseEvent.php} (87%) diff --git a/CRM/EventsExtras/Hook/BuildForm.php b/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php similarity index 87% rename from CRM/EventsExtras/Hook/BuildForm.php rename to CRM/EventsExtras/Hook/BuildForm/BaseEvent.php index e45f275..668bd86 100644 --- a/CRM/EventsExtras/Hook/BuildForm.php +++ b/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php @@ -6,7 +6,7 @@ /** * Abstract class for BuildForm Hook */ -abstract class CRM_EventsExtras_Hook_BuildForm { +abstract class CRM_EventsExtras_Hook_BuildForm_BaseEvent { /** * Event tab to display on the form @@ -21,16 +21,13 @@ abstract class CRM_EventsExtras_Hook_BuildForm { */ protected function __construct($eventTab){ $this->eventTab = $eventTab; - $templatePath = E::path() . '/templates/CRM/EventsExtras/Form/EventTabs.tpl'; - CRM_Core_Region::instance('page-body')->add([ - 'template' => "{$templatePath}" - ]); + $this->addEventTabTemplate(); } /** * fuction to hide fields based on settings * - * @param array $$form + * @param array $form * */ protected function hideField(CRM_Event_Form_ManageEvent &$form){ @@ -46,4 +43,11 @@ protected function hideField(CRM_Event_Form_ManageEvent &$form){ } $form->assign('hiddenCssClasses', $hiddenFields); } + + private function addEventTabTemplate(){ + $templatePath = E::path() . '/templates/CRM/EventsExtras/Form/EventTabs.tpl'; + CRM_Core_Region::instance('page-body')->add([ + 'template' => "{$templatePath}" + ]); + } } \ No newline at end of file diff --git a/CRM/EventsExtras/Hook/BuildForm/EventFee.php b/CRM/EventsExtras/Hook/BuildForm/EventFee.php index f3a49fa..2318c85 100644 --- a/CRM/EventsExtras/Hook/BuildForm/EventFee.php +++ b/CRM/EventsExtras/Hook/BuildForm/EventFee.php @@ -1,15 +1,18 @@ buildForm($form); } if ($formName === 'CRM_Event_Form_ManageEvent_Fee'){ - $eventFeeHook = new CRM_EventsExtras_Hook_BuildForm_EventFee(SettingsManager::EVENT_FEE); + $eventFeeHook = new CRM_EventsExtras_Hook_BuildForm_EventFee(); $eventFeeHook->buildForm($form); } if ($formName === 'CRM_Event_Form_ManageEvent_Registration'){ - $eventFeeRegistration = new CRM_EventsExtras_Hook_BuildForm_EventRegistration(SettingsManager::EVENT_REGISTRATION); + $eventFeeRegistration = new CRM_EventsExtras_Hook_BuildForm_EventRegistration(); $eventFeeRegistration->buildForm($form); } } From e389b2f25f4f89f584496644c6bcc97e9fd7f2fd Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Fri, 21 Jun 2019 12:34:21 +0100 Subject: [PATCH 19/97] Use Listener in BuildForm hook --- CRM/EventsExtras/Hook/BuildForm/BaseEvent.php | 33 +++++++++++++++++++ CRM/EventsExtras/Hook/BuildForm/EventFee.php | 13 +++++--- CRM/EventsExtras/Hook/BuildForm/EventInfo.php | 15 ++++++--- .../Hook/BuildForm/EventRegistration.php | 13 +++++--- eventsextras.php | 18 ++++------ 5 files changed, 68 insertions(+), 24 deletions(-) diff --git a/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php b/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php index 668bd86..3a2eaae 100644 --- a/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php +++ b/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php @@ -24,6 +24,39 @@ protected function __construct($eventTab){ $this->addEventTabTemplate(); } + /** + * Hides options on the localisation page + * + * @param string $formName + * @param CRM_Core_Form $form + */ + public function handle($formName, &$form) { + if (!$this->shouldHandle($formName)) { + return; + } + + } + + /** + * Checks if the hook should be handled. + * + * @param string $formName + * @param class $formClass + * + * @return bool + */ + protected function shouldHandle($formName, $formClass) { + if ($formName === $formClass) { + return TRUE; + } + + return FALSE; + } + + + + + /** * fuction to hide fields based on settings * diff --git a/CRM/EventsExtras/Hook/BuildForm/EventFee.php b/CRM/EventsExtras/Hook/BuildForm/EventFee.php index 2318c85..56fc58b 100644 --- a/CRM/EventsExtras/Hook/BuildForm/EventFee.php +++ b/CRM/EventsExtras/Hook/BuildForm/EventFee.php @@ -16,10 +16,15 @@ public function __construct() { } /** - * - * @param \CRM_Event_Form_ManageEvent_Fee $form - */ - public function buildForm(CRM_Event_Form_ManageEvent_Fee &$form) { + * Hides options on the Event Fee page + * + * @param string $formName + * @param CRM_Event_Form_ManageEvent_Fee $form + */ + public function handle($formName, &$form) { + if (!$this->shouldHandle($formName, CRM_Event_Form_ManageEvent_Fee::class)) { + return; + } $this->hideField($form); } diff --git a/CRM/EventsExtras/Hook/BuildForm/EventInfo.php b/CRM/EventsExtras/Hook/BuildForm/EventInfo.php index b5120f5..04c5487 100644 --- a/CRM/EventsExtras/Hook/BuildForm/EventInfo.php +++ b/CRM/EventsExtras/Hook/BuildForm/EventInfo.php @@ -15,11 +15,16 @@ public function __construct() { parent::__construct(SettingsManager::EVENT_INFO); } - /** - * - * @param \CRM_Event_Form_ManageEvent_EventInfo $form - */ - public function buildForm(CRM_Event_Form_ManageEvent_EventInfo &$form) { + /** + * Hides options on the Event Info page + * + * @param string $formName + * @param CRM_Event_Form_ManageEvent_EventInfo $form + */ + public function handle($formName, &$form) { + if (!$this->shouldHandle($formName, CRM_Event_Form_ManageEvent_EventInfo::class)) { + return; + } $this->hideField($form); } diff --git a/CRM/EventsExtras/Hook/BuildForm/EventRegistration.php b/CRM/EventsExtras/Hook/BuildForm/EventRegistration.php index 8421f3e..abe3b73 100644 --- a/CRM/EventsExtras/Hook/BuildForm/EventRegistration.php +++ b/CRM/EventsExtras/Hook/BuildForm/EventRegistration.php @@ -16,10 +16,15 @@ public function __construct() { } /** - * - * @param \CRM_Event_Form_ManageEvent_Registration $form - */ - public function buildForm(CRM_Event_Form_ManageEvent_Registration &$form) { + * Hides options on the Event Info page + * + * @param string $formName + * @param CRM_Event_Form_ManageEvent_Registration $form + */ + public function handle($formName, &$form) { + if (!$this->shouldHandle($formName, CRM_Event_Form_ManageEvent_Registration::class)) { + return; + } $this->hideField($form); } diff --git a/eventsextras.php b/eventsextras.php index f459f48..9786ad9 100644 --- a/eventsextras.php +++ b/eventsextras.php @@ -10,17 +10,13 @@ * @link hhttps://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_buildForm/ */ function eventsextras_civicrm_buildForm($formName, &$form){ - if ($formName === 'CRM_Event_Form_ManageEvent_EventInfo'){ - $eventInfoHook = new CRM_EventsExtras_Hook_BuildForm_EventInfo(); - $eventInfoHook->buildForm($form); - } - if ($formName === 'CRM_Event_Form_ManageEvent_Fee'){ - $eventFeeHook = new CRM_EventsExtras_Hook_BuildForm_EventFee(); - $eventFeeHook->buildForm($form); - } - if ($formName === 'CRM_Event_Form_ManageEvent_Registration'){ - $eventFeeRegistration = new CRM_EventsExtras_Hook_BuildForm_EventRegistration(); - $eventFeeRegistration->buildForm($form); + $listeners = [ + new CRM_EventsExtras_Hook_BuildForm_EventInfo(), + new CRM_EventsExtras_Hook_BuildForm_EventFee(), + new CRM_EventsExtras_Hook_BuildForm_EventRegistration(), + ]; + foreach ($listeners as $currentListener) { + $currentListener->handle($formName, $form); } } From 746bd2082f504f0b449586d2d1f76d743c6c773a Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Fri, 21 Jun 2019 13:45:11 +0100 Subject: [PATCH 20/97] RSE:204: Implement optional section on getConfigFields function --- CRM/EventsExtras/SettingsManager.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/CRM/EventsExtras/SettingsManager.php b/CRM/EventsExtras/SettingsManager.php index 117aca1..329b24b 100644 --- a/CRM/EventsExtras/SettingsManager.php +++ b/CRM/EventsExtras/SettingsManager.php @@ -47,7 +47,7 @@ public static function getSettingsValue(){ * * @return array */ - public static function getConfigFields() { + public static function getConfigFields($section = NULL) { $configFields = self::fetchSettingFields(); if (!isset($configFields) || empty($configFields)) { $result = civicrm_api3('System', 'flush'); @@ -55,8 +55,15 @@ public static function getConfigFields() { $configFields = self::fetchSettingFields(); } } - + if ($section != NULL){ //if section is passed, only return settings in section + foreach ($configFields as $field){ + if ($field['extra_attributes']['section'] != $section) { + unset($configFields[$field['name']]); + } + } + } return $configFields; + } /** From cf9475715d9f1faf5ff538052f4eda183773e944 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Fri, 21 Jun 2019 14:06:35 +0100 Subject: [PATCH 21/97] RSE-204: define handle as abstract function --- CRM/EventsExtras/Hook/BuildForm/BaseEvent.php | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php b/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php index 3a2eaae..d2c1205 100644 --- a/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php +++ b/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php @@ -13,6 +13,14 @@ abstract class CRM_EventsExtras_Hook_BuildForm_BaseEvent { */ protected $eventTab; + /** + * Hides options on the localisation page + * + * @param string $formName + * @param CRM_Core_Form $form + */ + abstract function handle($formName, &$form); + /** * Constractor for BuildForm class * @@ -24,19 +32,6 @@ protected function __construct($eventTab){ $this->addEventTabTemplate(); } - /** - * Hides options on the localisation page - * - * @param string $formName - * @param CRM_Core_Form $form - */ - public function handle($formName, &$form) { - if (!$this->shouldHandle($formName)) { - return; - } - - } - /** * Checks if the hook should be handled. * From 0cfebf80d6fd0fc4821428a51c718dde1513e8eb Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Fri, 21 Jun 2019 14:09:09 +0100 Subject: [PATCH 22/97] RSE-204: Pass event tab so we get config based on tab loaded --- CRM/EventsExtras/Hook/BuildForm/BaseEvent.php | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php b/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php index d2c1205..b7652eb 100644 --- a/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php +++ b/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php @@ -13,14 +13,6 @@ abstract class CRM_EventsExtras_Hook_BuildForm_BaseEvent { */ protected $eventTab; - /** - * Hides options on the localisation page - * - * @param string $formName - * @param CRM_Core_Form $form - */ - abstract function handle($formName, &$form); - /** * Constractor for BuildForm class * @@ -32,6 +24,14 @@ protected function __construct($eventTab){ $this->addEventTabTemplate(); } + /** + * Hides options on the localisation page + * + * @param string $formName + * @param CRM_Core_Form $form + */ + abstract function handle($formName, &$form); + /** * Checks if the hook should be handled. * @@ -48,10 +48,6 @@ protected function shouldHandle($formName, $formClass) { return FALSE; } - - - - /** * fuction to hide fields based on settings * @@ -59,7 +55,7 @@ protected function shouldHandle($formName, $formClass) { * */ protected function hideField(CRM_Event_Form_ManageEvent &$form){ - $configFields = SettingsManager::getConfigFields(); + $configFields = SettingsManager::getConfigFields($this->eventTab); $settingsValue = SettingsManager::getSettingsValue(); $hiddenFields = []; foreach ($configFields as $config) { From 32541093012d86177d094bee43579966664b6c27 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Fri, 21 Jun 2019 15:30:36 +0100 Subject: [PATCH 23/97] RSE-204: fixed comment and remove condidtion for checking section in hideField function --- CRM/EventsExtras/Hook/BuildForm/BaseEvent.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php b/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php index b7652eb..e88f25c 100644 --- a/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php +++ b/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php @@ -25,7 +25,7 @@ protected function __construct($eventTab){ } /** - * Hides options on the localisation page + * Hides options on the page * * @param string $formName * @param CRM_Core_Form $form @@ -44,7 +44,6 @@ protected function shouldHandle($formName, $formClass) { if ($formName === $formClass) { return TRUE; } - return FALSE; } @@ -60,9 +59,7 @@ protected function hideField(CRM_Event_Form_ManageEvent &$form){ $hiddenFields = []; foreach ($configFields as $config) { if ($settingsValue[$config['name']] == 0){ - if ($config['extra_attributes']['section'] == $this->eventTab){ - $hiddenFields[] = $config['extra_attributes']['css_class']; - } + $hiddenFields[] = $config['extra_attributes']['css_class']; } } $form->assign('hiddenCssClasses', $hiddenFields); From 67a79ab55eb8be21413497bfe2e4b83e13a0e382 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Fri, 21 Jun 2019 15:30:57 +0100 Subject: [PATCH 24/97] RSE-204: fixed comment --- CRM/EventsExtras/Hook/BuildForm/EventRegistration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CRM/EventsExtras/Hook/BuildForm/EventRegistration.php b/CRM/EventsExtras/Hook/BuildForm/EventRegistration.php index abe3b73..f89a6f8 100644 --- a/CRM/EventsExtras/Hook/BuildForm/EventRegistration.php +++ b/CRM/EventsExtras/Hook/BuildForm/EventRegistration.php @@ -16,7 +16,7 @@ public function __construct() { } /** - * Hides options on the Event Info page + * Hides options on the Event Registration page * * @param string $formName * @param CRM_Event_Form_ManageEvent_Registration $form From 7f85cb7b17143f72a0fc11d22f2e3c83f3fb6f31 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Fri, 21 Jun 2019 15:39:13 +0100 Subject: [PATCH 25/97] RSE-204: Added empty line on each php file --- CRM/EventsExtras/Hook/BuildForm/BaseEvent.php | 3 ++- CRM/EventsExtras/Hook/BuildForm/EventFee.php | 4 ++-- CRM/EventsExtras/Hook/BuildForm/EventInfo.php | 2 +- CRM/EventsExtras/Hook/BuildForm/EventRegistration.php | 2 +- CRM/EventsExtras/SettingsManager.php | 2 +- settings/EventsExtras.setting.php | 2 +- 6 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php b/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php index e88f25c..65ce49c 100644 --- a/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php +++ b/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php @@ -71,4 +71,5 @@ private function addEventTabTemplate(){ 'template' => "{$templatePath}" ]); } -} \ No newline at end of file +} + diff --git a/CRM/EventsExtras/Hook/BuildForm/EventFee.php b/CRM/EventsExtras/Hook/BuildForm/EventFee.php index 56fc58b..ef32f87 100644 --- a/CRM/EventsExtras/Hook/BuildForm/EventFee.php +++ b/CRM/EventsExtras/Hook/BuildForm/EventFee.php @@ -27,5 +27,5 @@ public function handle($formName, &$form) { } $this->hideField($form); } - -} \ No newline at end of file + +} diff --git a/CRM/EventsExtras/Hook/BuildForm/EventInfo.php b/CRM/EventsExtras/Hook/BuildForm/EventInfo.php index 04c5487..e16c3b4 100644 --- a/CRM/EventsExtras/Hook/BuildForm/EventInfo.php +++ b/CRM/EventsExtras/Hook/BuildForm/EventInfo.php @@ -28,4 +28,4 @@ public function handle($formName, &$form) { $this->hideField($form); } -} \ No newline at end of file +} diff --git a/CRM/EventsExtras/Hook/BuildForm/EventRegistration.php b/CRM/EventsExtras/Hook/BuildForm/EventRegistration.php index f89a6f8..c1fe8c6 100644 --- a/CRM/EventsExtras/Hook/BuildForm/EventRegistration.php +++ b/CRM/EventsExtras/Hook/BuildForm/EventRegistration.php @@ -28,4 +28,4 @@ public function handle($formName, &$form) { $this->hideField($form); } -} \ No newline at end of file +} diff --git a/CRM/EventsExtras/SettingsManager.php b/CRM/EventsExtras/SettingsManager.php index 329b24b..f513c27 100644 --- a/CRM/EventsExtras/SettingsManager.php +++ b/CRM/EventsExtras/SettingsManager.php @@ -80,4 +80,4 @@ private static function fetchSettingFields() { } return $settingFields; } -} \ No newline at end of file +} diff --git a/settings/EventsExtras.setting.php b/settings/EventsExtras.setting.php index 443a021..c0d83e1 100644 --- a/settings/EventsExtras.setting.php +++ b/settings/EventsExtras.setting.php @@ -209,4 +209,4 @@ 'css_class' => 'crm-event-manage-registration-form-block-is_multiple_registrations', ], ], -]; \ No newline at end of file +]; From 32808d4bb29cef0eaf8a350c987eceeda6a418f4 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Fri, 21 Jun 2019 15:42:55 +0100 Subject: [PATCH 26/97] RSE-204: Apply empty line at the end of file --- CRM/EventsExtras/Hook/BuildForm/EventFee.php | 3 ++- CRM/EventsExtras/Hook/BuildForm/EventInfo.php | 1 + CRM/EventsExtras/Hook/BuildForm/EventRegistration.php | 1 + CRM/EventsExtras/SettingsManager.php | 1 + settings/EventsExtras.setting.php | 1 + 5 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CRM/EventsExtras/Hook/BuildForm/EventFee.php b/CRM/EventsExtras/Hook/BuildForm/EventFee.php index ef32f87..8779051 100644 --- a/CRM/EventsExtras/Hook/BuildForm/EventFee.php +++ b/CRM/EventsExtras/Hook/BuildForm/EventFee.php @@ -27,5 +27,6 @@ public function handle($formName, &$form) { } $this->hideField($form); } - + } + diff --git a/CRM/EventsExtras/Hook/BuildForm/EventInfo.php b/CRM/EventsExtras/Hook/BuildForm/EventInfo.php index e16c3b4..8a0a9eb 100644 --- a/CRM/EventsExtras/Hook/BuildForm/EventInfo.php +++ b/CRM/EventsExtras/Hook/BuildForm/EventInfo.php @@ -29,3 +29,4 @@ public function handle($formName, &$form) { } } + diff --git a/CRM/EventsExtras/Hook/BuildForm/EventRegistration.php b/CRM/EventsExtras/Hook/BuildForm/EventRegistration.php index c1fe8c6..9ce1276 100644 --- a/CRM/EventsExtras/Hook/BuildForm/EventRegistration.php +++ b/CRM/EventsExtras/Hook/BuildForm/EventRegistration.php @@ -29,3 +29,4 @@ public function handle($formName, &$form) { } } + diff --git a/CRM/EventsExtras/SettingsManager.php b/CRM/EventsExtras/SettingsManager.php index f513c27..22f3feb 100644 --- a/CRM/EventsExtras/SettingsManager.php +++ b/CRM/EventsExtras/SettingsManager.php @@ -81,3 +81,4 @@ private static function fetchSettingFields() { return $settingFields; } } + diff --git a/settings/EventsExtras.setting.php b/settings/EventsExtras.setting.php index c0d83e1..f2a85d4 100644 --- a/settings/EventsExtras.setting.php +++ b/settings/EventsExtras.setting.php @@ -210,3 +210,4 @@ ], ], ]; + From fb3b0ba9d5cd96b1ab92ecf0fa2cebaf68f45c04 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Wed, 26 Jun 2019 17:50:40 +0100 Subject: [PATCH 27/97] RSE-210: Add function getSettingValue by passing $setting --- CRM/EventsExtras/SettingsManager.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/CRM/EventsExtras/SettingsManager.php b/CRM/EventsExtras/SettingsManager.php index ddf722e..e2a0958 100644 --- a/CRM/EventsExtras/SettingsManager.php +++ b/CRM/EventsExtras/SettingsManager.php @@ -1,4 +1,4 @@ - $setting, + 'sequential' => 1, + ])['values'][0]; + } + + /** + * Gets the settings Value + * + * @return array + */ public static function getSettingsValue(){ return civicrm_api3('setting', 'get', [ 'return' => self::SETTING_FIELDS, @@ -87,7 +99,7 @@ public static function getConfigFields($section = NULL) { */ private static function fetchSettingFields() { $settingFields = []; - foreach (self::SETTING_FIELDS as $name) { + foreach (self::SETTING_FIELDS as $name) { $settingFields[$name] = civicrm_api3('setting', 'getfields',[ 'filters' => [ 'name' => $name], ])['values'][$name]; From c14bbc24c960cb940184ffcd5a65694c97d8ca80 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Wed, 26 Jun 2019 18:17:31 +0100 Subject: [PATCH 28/97] RSE-210: Implement Hide/Show elements based on setting selected --- templates/CRM/EventsExtras/Form/Settings.tpl | 40 +++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/templates/CRM/EventsExtras/Form/Settings.tpl b/templates/CRM/EventsExtras/Form/Settings.tpl index 98f4756..7c0058d 100644 --- a/templates/CRM/EventsExtras/Form/Settings.tpl +++ b/templates/CRM/EventsExtras/Form/Settings.tpl @@ -26,27 +26,27 @@
{include file="CRM/common/formButtons.tpl" location="bottom"} -
+
{foreach from=$displaySections item=section}

{ts}{$section.name}{/ts}

{foreach from=$section.fields item=elementName} -
+
{if $form.$elementName.type neq 'checkbox'}
- {$form.$elementName.label} + {$form.$elementName.label} {if !$parentSettings.$elementName} {help id=$form.$elementName.name} {/if}
- {/if} + {/if}
{$form.$elementName.html} {if $form.$elementName.type eq 'checkbox'} {$form.$elementName.label}{if !$parentSettings.$elementName} {help id=$form.$elementName.name} {/if} {if !$parentSettings.$elementName} -
{$settingsDescription.$elementName}
+
{$settingsDescription.$elementName}
{/if} - {/if} + {/if}
@@ -56,3 +56,31 @@ {include file="CRM/common/formButtons.tpl" location="bottom"}
+ {literal} + + {/literal} From cded1ce0342e9909b1711e4ccaf9e54f1f7be865 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Wed, 26 Jun 2019 19:57:26 +0100 Subject: [PATCH 29/97] Revert "RSE-210: Implement Hide/Show elements based on setting selected" This reverts commit c14bbc24c960cb940184ffcd5a65694c97d8ca80. --- templates/CRM/EventsExtras/Form/Settings.tpl | 40 +++----------------- 1 file changed, 6 insertions(+), 34 deletions(-) diff --git a/templates/CRM/EventsExtras/Form/Settings.tpl b/templates/CRM/EventsExtras/Form/Settings.tpl index 7c0058d..98f4756 100644 --- a/templates/CRM/EventsExtras/Form/Settings.tpl +++ b/templates/CRM/EventsExtras/Form/Settings.tpl @@ -26,27 +26,27 @@
{include file="CRM/common/formButtons.tpl" location="bottom"} -
+
{foreach from=$displaySections item=section}

{ts}{$section.name}{/ts}

{foreach from=$section.fields item=elementName} -
+
{if $form.$elementName.type neq 'checkbox'}
- {$form.$elementName.label} + {$form.$elementName.label} {if !$parentSettings.$elementName} {help id=$form.$elementName.name} {/if}
- {/if} + {/if}
{$form.$elementName.html} {if $form.$elementName.type eq 'checkbox'} {$form.$elementName.label}{if !$parentSettings.$elementName} {help id=$form.$elementName.name} {/if} {if !$parentSettings.$elementName} -
{$settingsDescription.$elementName}
+
{$settingsDescription.$elementName}
{/if} - {/if} + {/if}
@@ -56,31 +56,3 @@ {include file="CRM/common/formButtons.tpl" location="bottom"}
- {literal} - - {/literal} From 38f093087546a3d16adde2d1cfb9e77add62a3ee Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Wed, 26 Jun 2019 20:12:45 +0100 Subject: [PATCH 30/97] RSE-210: Implement script for handle show/hide when select setting options --- templates/CRM/EventsExtras/Form/Settings.tpl | 40 +++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/templates/CRM/EventsExtras/Form/Settings.tpl b/templates/CRM/EventsExtras/Form/Settings.tpl index 98f4756..5133d8c 100644 --- a/templates/CRM/EventsExtras/Form/Settings.tpl +++ b/templates/CRM/EventsExtras/Form/Settings.tpl @@ -26,27 +26,27 @@
{include file="CRM/common/formButtons.tpl" location="bottom"} -
+
{foreach from=$displaySections item=section}

{ts}{$section.name}{/ts}

{foreach from=$section.fields item=elementName} -
+
{if $form.$elementName.type neq 'checkbox'}
- {$form.$elementName.label} + {$form.$elementName.label} {if !$parentSettings.$elementName} {help id=$form.$elementName.name} {/if}
- {/if} + {/if}
{$form.$elementName.html} {if $form.$elementName.type eq 'checkbox'} {$form.$elementName.label}{if !$parentSettings.$elementName} {help id=$form.$elementName.name} {/if} {if !$parentSettings.$elementName} -
{$settingsDescription.$elementName}
+
{$settingsDescription.$elementName}
{/if} - {/if} + {/if}
@@ -56,3 +56,31 @@ {include file="CRM/common/formButtons.tpl" location="bottom"}
+{literal} + +{/literal} From 54bb5bdebb1d29ffd3ac6fe0a249b5b30f47c559 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Thu, 27 Jun 2019 10:35:01 +0100 Subject: [PATCH 31/97] RSE-210: Added class so javascript can pick up --- templates/CRM/EventsExtras/Form/Settings.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/CRM/EventsExtras/Form/Settings.tpl b/templates/CRM/EventsExtras/Form/Settings.tpl index 5133d8c..e4cf59a 100644 --- a/templates/CRM/EventsExtras/Form/Settings.tpl +++ b/templates/CRM/EventsExtras/Form/Settings.tpl @@ -30,7 +30,7 @@ {foreach from=$displaySections item=section}

{ts}{$section.name}{/ts}

{foreach from=$section.fields item=elementName} -
+
{if $form.$elementName.type neq 'checkbox'}
{$form.$elementName.label} From 81b9eb3e83d4043de8d26ee3c3b9b9b2094c35d8 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Thu, 27 Jun 2019 10:36:18 +0100 Subject: [PATCH 32/97] RSE-210: Changed type of settings --- settings/EventsExtrasDefault.setting.php | 35 +++++++++++------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/settings/EventsExtrasDefault.setting.php b/settings/EventsExtrasDefault.setting.php index 18102a8..db29db9 100644 --- a/settings/EventsExtrasDefault.setting.php +++ b/settings/EventsExtrasDefault.setting.php @@ -53,8 +53,7 @@ 'eventsextras_include_map_event_location_default' => [ 'name' => 'eventsextras_include_map_event_location_default', 'title' => ts('Set Default Include Map to Event Location'), - 'type' => 'Integer', - 'quick_form_type' => 'Element', + 'type' => 'String', 'default' => '', 'html_type' => 'checkbox', 'add' => '1.0', @@ -71,9 +70,8 @@ 'eventsextras_public_event_default' => [ 'name' => 'eventsextras_public_event_default', 'title' => ts('Set Default Public Event'), - 'type' => 'Integer', - 'quick_form_type' => 'Element', - 'default' => '', + 'type' => 'String', + 'default' => 0, 'html_type' => 'checkbox', 'add' => '1.0', 'is_domain' => 1, @@ -105,7 +103,7 @@ 'section' => SettingsManager::EVENT_FEE, 'parent_setting' => 'eventsextras_currency', 'class' => 'crm-select2', - 'placeholder' => ts('--Select--'), + 'placeholder' => ts('--Select--'), ], ], 'eventsextras_payment_processor_selection_default' => [ @@ -113,18 +111,18 @@ 'title' => ts('Set Default Payment Processor Selection'), 'type' => 'String', 'quick_form_type' => 'Checkboxes', - 'default' => TRUE, + 'default' => '', 'html_type' => 'checkboxes', 'add' => '1.0', 'is_domain' => 1, 'is_contact' => 0, 'description' => ts(' - If this is a paid event and you want users to be able to register and pay online, - select a payment processor to use. NOTE: Alternatively, + If this is a paid event and you want users to be able to register and pay online, + select a payment processor to use. NOTE: Alternatively, you can enable the Pay Later feature below without setting up a payment processor. All users will then be asked to submit payment offline - (e.g. mail in a check, call in a credit card, etc.). - (learn more...) '), @@ -134,12 +132,11 @@ 'parent_setting' => 'eventsextras_payment_processor', 'class' => '', ], - ], + ], 'eventsextras_enable_pay_later_option_default' => [ 'name' => 'eventsextras_enable_pay_later_option_default', 'title' => ts('Enable Default Pay Later option?'), - 'type' => 'String', - 'quick_form_type' => 'Checkbox', + 'type' => 'Integer', 'default' => '', 'html_type' => 'checkbox', 'add' => '1.0', @@ -152,7 +149,7 @@ 'parent_setting' => 'eventsextras_enable_pay_later_option', 'class' => '', ], - ], + ], 'eventsextras_enable_pay_later_option_default_label' => [ 'name' => 'eventsextras_enable_pay_later_option_default_label', 'title' => ts('Set Default Pay Later Label'), @@ -169,7 +166,7 @@ 'parent_setting' => 'eventsextras_enable_pay_later_option_default', 'class' => '', ], - ], + ], 'eventsextras_enable_pay_later_option_default_instruction' => [ 'name' => 'eventsextras_enable_pay_later_option_default_instruction', 'title' => ts('Set Default Pay Later Instruction'), @@ -186,7 +183,7 @@ 'parent_setting' => 'eventsextras_enable_pay_later_option_default', 'class' => '', ], - ], + ], 'eventsextras_enable_pay_later_option_default_billing_address_required' => [ 'name' => 'eventsextras_enable_pay_later_option_default_billing_address_required', 'title' => ts('Set Default Billing Address Required?'), @@ -203,7 +200,7 @@ 'parent_setting' => 'eventsextras_enable_pay_later_option_default', 'class' => '', ], - ], + ], 'eventsextras_pending_participant_expiration_default' => [ 'name' => 'eventsextras_pending_participant_expiration_default', @@ -297,4 +294,4 @@ 'parent_setting' => 'eventsextras_register_multiple_participants_default', ], ], -]; \ No newline at end of file +]; From 4b6a7234e42cd280a92ccb9a08ba6cc39b634726 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Thu, 27 Jun 2019 10:36:44 +0100 Subject: [PATCH 33/97] RSE-210: Removed duplicated declaration --- CRM/EventsExtras/Form/Settings.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/CRM/EventsExtras/Form/Settings.php b/CRM/EventsExtras/Form/Settings.php index 391994b..58d0c2b 100644 --- a/CRM/EventsExtras/Form/Settings.php +++ b/CRM/EventsExtras/Form/Settings.php @@ -32,11 +32,11 @@ public function buildQuickForm() { foreach ($configFields as $name => $config) { if(!array_key_exists('parent_setting', $config['extra_attributes'])){ $this->addRadio( - $name, - E::ts($config['title']), + $name, + E::ts($config['title']), [1 => E::ts('Show'), 0 => E::ts('Hide')] ); - $this->parentSettings[$config['name']] = TRUE; + $this->parentSettings[$config['name']] = TRUE; } else { //handle default setting form if ($config['html_type'] == 'select') { $this->generateDefaultSelectList($config); @@ -79,7 +79,7 @@ public function postProcess() { private function generatePaymentProcessorElement($setting){ $paymentProcessor = CRM_Core_PseudoConstant::paymentProcessor(); $this->addCheckBox( - $setting['name'], + $setting['name'], E::ts($setting['title']), array_flip($paymentProcessor), NULL, NULL, NULL, NULL, @@ -116,7 +116,7 @@ private function generateDefaultSelectList($setting) { 'sequential' => 1, 'name' => $setting['pseudoconstant']['optionGroupName'], 'api.OptionValue.get' => [' - option_group_id' => "id", + option_group_id' => "id", 'return' => ['value', 'label'] ] ])['values'][0]['api.OptionValue.get']['values']; @@ -124,7 +124,7 @@ private function generateDefaultSelectList($setting) { $options[$value['value']] = $value['label']; } } else { // for default maxinum participant - foreach (range(1, 9) as $value){ + foreach (range(1, 9) as $value){ $options[$value] = $value; } } @@ -147,7 +147,6 @@ public function setDefaultValues() { $defaults = []; $currentValues = civicrm_api3('setting', 'get', ['return' => array_keys(SettingsManager::getConfigFields())]); - $defaults = []; $domainID = CRM_Core_Config::domainID(); foreach ($currentValues['values'][$domainID] as $name => $value) { $defaults[$name] = $value; From 42072ccbb59e462844aafb9ee5f324afa075b5cf Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Thu, 27 Jun 2019 18:10:09 +0100 Subject: [PATCH 34/97] RSE-210: Using constants array for declare settings --- CRM/EventsExtras/SettingsManager.php | 67 ++++++++++++++-------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/CRM/EventsExtras/SettingsManager.php b/CRM/EventsExtras/SettingsManager.php index e2a0958..4dac26e 100644 --- a/CRM/EventsExtras/SettingsManager.php +++ b/CRM/EventsExtras/SettingsManager.php @@ -12,36 +12,34 @@ class CRM_EventsExtras_SettingsManager { const EVENT_FEE = 'event_fee'; const EVENT_REGISTRATION = 'event_online_registration'; - /** - * Constants value for settings name - */ - const SETTING_FIELDS = [ - 'eventsextras_roles', - 'eventsextras_roles_default', - 'eventsextras_participant_listing', - 'eventsextras_participant_listing_default', - 'eventsextras_event_summary', - 'eventsextras_event_description', - 'eventsextras_include_map_event_location', - 'eventsextras_include_map_event_location_default', - 'eventsextras_public_event', - 'eventsextras_public_event_default', - 'eventsextras_currency', - 'eventsextras_currency_default', - 'eventsextras_payment_processor_selection', - 'eventsextras_payment_processor_selection_default', - 'eventsextras_enable_pay_later_option', - 'eventsextras_enable_pay_later_option_default', - 'eventsextras_enable_pay_later_option_default_label', - 'eventsextras_enable_pay_later_option_default_instruction', - 'eventsextras_enable_pay_later_option_default_billing_address_required', - 'eventsextras_pending_participant_expiration', - 'eventsextras_pending_participant_expiration_default', - 'eventsextras_allow_self_service', - 'eventsextras_allow_self_service_default', - 'eventsextras_allow_self_service_default_time_limit', - 'eventsextras_register_multiple_participants', - 'eventsextras_register_multiple_participants_default_maxinum_participant' + + const SETTING_FIELDS = [ + 'ROLES' => 'eventsextras_roles', + 'ROLES_DEFAULT' => 'eventsextras_roles_default', + 'PARTICIPANT_LISTING' => 'eventsextras_participant_listing', + 'PARTICIPANT_LISTING_DEFAULT' => 'eventsextras_participant_listing_default', + 'PARTICIPANT_SUMMARY' => 'eventsextras_event_summary', + 'EVENT_DESCRTIPTION' => 'eventsextras_event_description', + 'INCLUDE_MAP_LOCATION_EVENT' => 'eventsextras_include_map_event_location', + 'INCLUDE_MAP_LOCATION_EVENT_DEFAULT' => 'eventsextras_include_map_event_location_default', + 'INCLUDE_MAP_PUBLIC_EVENT' => 'eventsextras_public_event', + 'INCLUDE_MAP_PUBLIC_EVENT_DEFAULT' => 'eventsextras_public_event_default', + 'CURRENCY' => 'eventsextras_currency', + 'CURRENCY_DEFAULT' => 'eventsextras_currency_default', + 'PAYMENT_PROCESSOR_SELECTION' => 'eventsextras_payment_processor_selection', + 'PAYMENT_PROCESSOR_SELECTION_DEFAULT' => 'eventsextras_payment_processor_selection_default', + 'PAY_LATER_OPTION' => 'eventsextras_enable_pay_later_option', + 'PAY_LATER_OPTION_DEFAULT' => 'eventsextras_enable_pay_later_option_default', + 'PAY_LATER_OPTION_DEFAULT_LABEL' => 'eventsextras_enable_pay_later_option_default_label', + 'PAY_LATER_OPTION_DEFAULT_LABEL_INSTRUCTION' => 'eventsextras_enable_pay_later_option_default_instruction', + 'PAY_LATER_OPTION_DEFAULT_BILLING_ADDRESS' => 'eventsextras_enable_pay_later_option_default_billing_address_required', + 'PENDING_PARTICIPANT_EXPIRATION' => 'eventsextras_pending_participant_expiration', + 'PENDING_PARTICIPANT_EXPIRATION_DEFAULT' => 'eventsextras_pending_participant_expiration_default', + 'ALLOW_SELF_SERIVCE' => 'eventsextras_allow_self_service', + 'ALLOW_SELF_SERVICE_DEFAULT' => 'eventsextras_allow_self_service_default', + 'ALLOW_SELF_SERVICE_DEFAULT_TIME_LIMIT' => 'eventsextras_allow_self_service_default_time_limit', + 'REGISTER_MULTIPLE_PARTICIPANTS' => 'eventsextras_register_multiple_participants', + 'REGISTER_MULTIPLE_PARTICIPANTS_DEFAULT' => 'eventsextras_register_multiple_participants_default_maxinum_participant' ]; /** @@ -61,9 +59,12 @@ public static function getSettingValue($setting){ * * @return array */ - public static function getSettingsValue(){ + public static function getSettingsValue($settings = NULL){ + if ($settings == NULL){ + $settings = array_values(self::SETTING_FIELDS); + } return civicrm_api3('setting', 'get', [ - 'return' => self::SETTING_FIELDS, + 'return' => $settings, 'sequential' => 1, ])['values'][0]; } @@ -99,7 +100,7 @@ public static function getConfigFields($section = NULL) { */ private static function fetchSettingFields() { $settingFields = []; - foreach (self::SETTING_FIELDS as $name) { + foreach (array_values(self::SETTING_FIELDS) as $name) { $settingFields[$name] = civicrm_api3('setting', 'getfields',[ 'filters' => [ 'name' => $name], ])['values'][$name]; From c46a116d60c46898a69839d0436a17c41ccd894c Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Thu, 27 Jun 2019 18:11:09 +0100 Subject: [PATCH 35/97] RSE-210: Added element html so we use to save into database --- settings/EventsExtrasDefault.setting.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/settings/EventsExtrasDefault.setting.php b/settings/EventsExtrasDefault.setting.php index db29db9..a6fffe3 100644 --- a/settings/EventsExtrasDefault.setting.php +++ b/settings/EventsExtrasDefault.setting.php @@ -23,6 +23,7 @@ 'extra_attributes' => [ 'section' => SettingsManager::EVENT_INFO, 'parent_setting' => 'eventsextras_roles', + 'event_form_element_name' => 'default_role_id', 'class' => 'crm-select2', 'placeholder' => ts('- Select -'), ], @@ -45,6 +46,7 @@ 'extra_attributes' => [ 'section' => SettingsManager::EVENT_INFO, 'parent_setting' => 'eventsextras_participant_listing', + 'event_form_element_name' => 'participant_listing_id', 'class' => 'crm-select2', 'placeholder' => ts('Disabled'), @@ -64,6 +66,7 @@ 'extra_attributes' => [ 'section' => SettingsManager::EVENT_INFO, 'parent_setting' => 'eventsextras_include_map_event_location', + 'event_form_element_name' => 'is_map', 'class' => '', ], ], @@ -81,6 +84,7 @@ 'extra_attributes' => [ 'section' => SettingsManager::EVENT_INFO, 'parent_setting' => 'eventsextras_public_event', + 'event_form_element_name' => 'is_public', 'class' => '', ], ], @@ -102,6 +106,7 @@ 'extra_attributes' => [ 'section' => SettingsManager::EVENT_FEE, 'parent_setting' => 'eventsextras_currency', + 'event_form_element_name' => 'currency', 'class' => 'crm-select2', 'placeholder' => ts('--Select--'), ], @@ -130,6 +135,7 @@ 'extra_attributes' => [ 'section' => SettingsManager::EVENT_FEE, 'parent_setting' => 'eventsextras_payment_processor', + 'event_form_element_name' => 'payment_processor', 'class' => '', ], ], @@ -147,6 +153,7 @@ 'extra_attributes' => [ 'section' => SettingsManager::EVENT_FEE, 'parent_setting' => 'eventsextras_enable_pay_later_option', + 'event_form_element_name' => 'is_pay_later', 'class' => '', ], ], @@ -164,6 +171,7 @@ 'extra_attributes' => [ 'section' => SettingsManager::EVENT_FEE, 'parent_setting' => 'eventsextras_enable_pay_later_option_default', + 'event_form_element_name' => 'pay_later_text', 'class' => '', ], ], @@ -181,6 +189,7 @@ 'extra_attributes' => [ 'section' => SettingsManager::EVENT_FEE, 'parent_setting' => 'eventsextras_enable_pay_later_option_default', + 'event_form_element_name' => 'pay_later_receipt', 'class' => '', ], ], @@ -198,6 +207,7 @@ 'extra_attributes' => [ 'section' => SettingsManager::EVENT_FEE, 'parent_setting' => 'eventsextras_enable_pay_later_option_default', + 'event_form_element_name' => 'is_billing_required', 'class' => '', ], ], @@ -217,6 +227,7 @@ 'extra_attributes' => [ 'section' => SettingsManager::EVENT_REGISTRATION, 'parent_setting' => 'eventsextras_enable_pay_later_option', + 'event_form_element_name' => 'expiration_time', 'class' => '', ], ], @@ -236,6 +247,7 @@ 'extra_attributes' => [ 'section' => SettingsManager::EVENT_REGISTRATION, 'parent_setting' => 'eventsextras_allow_self_service', + 'event_form_element_name' => 'allow_selfcancelxfer', ], ], @@ -254,6 +266,7 @@ 'extra_attributes' => [ 'section' => SettingsManager::EVENT_REGISTRATION, 'parent_setting' => 'eventsextras_allow_self_service_default', + 'event_form_element_name' => 'selfcancelxfer_time', ], ], @@ -272,6 +285,7 @@ 'extra_attributes' => [ 'section' => SettingsManager::EVENT_REGISTRATION, 'parent_setting' => 'eventsextras_register_multiple_participants', + 'event_form_element_name' => 'is_multiple_registrations', ], ], 'eventsextras_register_multiple_participants_default_maxinum_participant' => [ @@ -292,6 +306,7 @@ 'extra_attributes' => [ 'section' => SettingsManager::EVENT_REGISTRATION, 'parent_setting' => 'eventsextras_register_multiple_participants_default', + 'event_form_element_name' => 'registration_end_date', ], ], ]; From 869771e7d4d306a1ead836ba0e543b709764e657 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Thu, 27 Jun 2019 18:13:14 +0100 Subject: [PATCH 36/97] RSE-210: Added setDefault --- CRM/EventsExtras/Hook/BuildForm/EventFee.php | 18 +++++++++++++++++- CRM/EventsExtras/Hook/BuildForm/EventInfo.php | 17 +++++++++++++++++ .../Hook/BuildForm/EventRegistration.php | 2 -- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/CRM/EventsExtras/Hook/BuildForm/EventFee.php b/CRM/EventsExtras/Hook/BuildForm/EventFee.php index 8779051..2843f95 100644 --- a/CRM/EventsExtras/Hook/BuildForm/EventFee.php +++ b/CRM/EventsExtras/Hook/BuildForm/EventFee.php @@ -6,7 +6,7 @@ * Class for Event Fee BuildForm Hook */ class CRM_EventsExtras_Hook_BuildForm_EventFee extends CRM_EventsExtras_Hook_BuildForm_BaseEvent { - + /** * * @param string $eventTab @@ -28,5 +28,21 @@ public function handle($formName, &$form) { $this->hideField($form); } + private function buildForm($formName, &$form) { + $this->setDefaults($form); + } + + private function setDefaults(&$form){ + $defaults = []; + $paymentProcessor = SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION']; + $paymentProcessorDefault = SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION_DEFAULT']; + $settings = [$paymentProcessor, $paymentProcessorDefault]; + $settingValues = SettingsManager::getSettingsValue($settings); + if ($settingValues[$paymentProcessor] == 0){ + $defaults['default_role_id'] = $settingValues[$paymentProcessorDefault]; + } + $form->setDefaults($defaults); + } + } diff --git a/CRM/EventsExtras/Hook/BuildForm/EventInfo.php b/CRM/EventsExtras/Hook/BuildForm/EventInfo.php index 8a0a9eb..d29f639 100644 --- a/CRM/EventsExtras/Hook/BuildForm/EventInfo.php +++ b/CRM/EventsExtras/Hook/BuildForm/EventInfo.php @@ -26,6 +26,23 @@ public function handle($formName, &$form) { return; } $this->hideField($form); + $this->buildForm($formName, $form); + } + + private function buildForm($formName, &$form) { + $this->setDefaults($form); + } + + private function setDefaults(&$form){ + $defaults = []; + $role = SettingsManager::SETTING_FIELDS['ROLES']; + $roleDefault = SettingsManager::SETTING_FIELDS['ROLES_DEFAULT']; + $settings = [$role, $roleDefault]; + $settingValues = SettingsManager::getSettingsValue($settings); + if ($settingValues[$role] == 0){ + $defaults['payment_processor'] = $settingValues[$roleDefault]; + } + $form->setDefaults($defaults); } } diff --git a/CRM/EventsExtras/Hook/BuildForm/EventRegistration.php b/CRM/EventsExtras/Hook/BuildForm/EventRegistration.php index 9ce1276..56d6db4 100644 --- a/CRM/EventsExtras/Hook/BuildForm/EventRegistration.php +++ b/CRM/EventsExtras/Hook/BuildForm/EventRegistration.php @@ -27,6 +27,4 @@ public function handle($formName, &$form) { } $this->hideField($form); } - } - From b5c19368709ce54f3e9dbd687611281cd8ebda96 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Thu, 27 Jun 2019 18:13:57 +0100 Subject: [PATCH 37/97] RSE-210: Use constant in array instead --- CRM/EventsExtras/Form/Settings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CRM/EventsExtras/Form/Settings.php b/CRM/EventsExtras/Form/Settings.php index 58d0c2b..0522dde 100644 --- a/CRM/EventsExtras/Form/Settings.php +++ b/CRM/EventsExtras/Form/Settings.php @@ -93,7 +93,7 @@ private function generatePaymentProcessorElement($setting){ * @param array $field */ private function generateDefaultSettingField($setting) { - if ($setting['name'] == 'eventsextras_payment_processor_selection_default') { + if ($setting['name'] == SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION_DEFAULT']) { $this->generatePaymentProcessorElement($setting); } else { $this->add( From 5d3bd0d284ac7699bee5793b71f4822abb8cad79 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Thu, 27 Jun 2019 18:14:22 +0100 Subject: [PATCH 38/97] RSE-210: Implement Pre Hook for adding default value --- CRM/EventsExtras/Hook/Pre/Event.php | 68 +++++++++++++++++++++++++++++ eventsextras.php | 17 +++++++- 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 CRM/EventsExtras/Hook/Pre/Event.php diff --git a/CRM/EventsExtras/Hook/Pre/Event.php b/CRM/EventsExtras/Hook/Pre/Event.php new file mode 100644 index 0000000..e01ca15 --- /dev/null +++ b/CRM/EventsExtras/Hook/Pre/Event.php @@ -0,0 +1,68 @@ +shouldHandle($op, $objectName)) { + return; + } + $this->preSetData($op, $id, $params); + } + + /** + * Checks whether the hook should be handled or not. + * + * @param string $op + * @param string $objectName + * + * @return bool + */ + private function shouldHandle($op, $objectName) { + return $objectName == 'Event'; + } + + private function preSetData($op, $id, &$params ){ + if ($op == 'delete' || $op == 'view') { + return; + } + if (array_key_exists('event_type_id', $params)) { + $this->preProcessData(SettingsManager::EVENT_INFO, $params); + } elseif (array_key_exists('is_monetary', $params)) { + $this->preProcessData(SettingsManager::EVENT_FEE, $params); + } elseif (array_key_exists('is_online_registration', $params)) { + $this->preProcessData(SettingsManager::EVENT_REGISTRATION, $params); + } + } + + private function preProcessData($section, &$params){ + $fields = SettingsManager::getConfigFields($section); + $settingsToProcess = []; + $fieldToProcess = []; + foreach ($fields as $field){ + $settingName = $field['name']; + $settingValue = SettingsManager::getSettingValue($settingName)[$settingName]; + if(!array_key_exists('parent_setting', $field['extra_attributes'])){ //handle parent setting + if ($settingValue == 0){ + $settingsToProcess[$settingName] = $settingName; + }else { + unset($fields[$settingName]); + } + } else { + if (in_array($field['extra_attributes']['parent_setting'], $settingsToProcess)){ + $formName = $field['extra_attributes']['event_form_element_name']; + $fieldToProcess[$formName] = $settingValue; + } + } + } + foreach ($fieldToProcess as $field => $value){ + $params[$field] = $value; + } + } +} + diff --git a/eventsextras.php b/eventsextras.php index 9786ad9..6ff64f7 100644 --- a/eventsextras.php +++ b/eventsextras.php @@ -20,6 +20,21 @@ function eventsextras_civicrm_buildForm($formName, &$form){ } } + +/** + * Implements hook_civicrm_pre(). + * + * @link hhttps://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_pre/ + */ +function eventsextras_civicrm_pre($op, $objectName, $id, &$params){ + $listeners = [ + new CRM_EventsExtras_Hook_Pre_Event(), + ]; + foreach ($listeners as $currentListener) { + $currentListener->handle($op, $objectName, $id, $params); + } +} + /** * Implements hook_civicrm_config(). * @@ -177,4 +192,4 @@ function eventsextras_civicrm_navigationMenu(&$menu) { 'separator' => 0, )); _eventsextras_civix_navigationMenu($menu); -} +} From 92915072853b06306cc40b3989953117a86e7aaf Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Fri, 28 Jun 2019 11:41:47 +0100 Subject: [PATCH 39/97] RSE-210: Set API to return more than 24 records, options limit = 0 --- CRM/EventsExtras/Form/Settings.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CRM/EventsExtras/Form/Settings.php b/CRM/EventsExtras/Form/Settings.php index 0522dde..2ac4452 100644 --- a/CRM/EventsExtras/Form/Settings.php +++ b/CRM/EventsExtras/Form/Settings.php @@ -117,6 +117,9 @@ private function generateDefaultSelectList($setting) { 'name' => $setting['pseudoconstant']['optionGroupName'], 'api.OptionValue.get' => [' option_group_id' => "id", + 'options' => [ + 'limit' => 0, + ], 'return' => ['value', 'label'] ] ])['values'][0]['api.OptionValue.get']['values']; From b4e5ebd0bafa983ee76305cbc387537874afc8dd Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Fri, 28 Jun 2019 12:26:47 +0100 Subject: [PATCH 40/97] RSE-210: Set default for selected payment processors on Event Fee --- CRM/EventsExtras/Form/Settings.php | 7 +++++++ CRM/EventsExtras/Hook/BuildForm/EventFee.php | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CRM/EventsExtras/Form/Settings.php b/CRM/EventsExtras/Form/Settings.php index 2ac4452..d240cb2 100644 --- a/CRM/EventsExtras/Form/Settings.php +++ b/CRM/EventsExtras/Form/Settings.php @@ -66,6 +66,13 @@ public function buildQuickForm() { public function postProcess() { $configFields = SettingsManager::getConfigFields(); $submittedValues = $this->exportValues(); + $paymentProcessors = $submittedValues[SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION_DEFAULT']]; + //flip selected default paymentProcessors before saving to setting + $flipedPaymentProcessor = []; + foreach ($paymentProcessors as $selectValue => $selected){ + $flipedPaymentProcessor[] = $selectValue; + } + $submittedValues[SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION_DEFAULT']] = $flipedPaymentProcessor; $valuesToSave = array_intersect_key($submittedValues, $configFields); $result = civicrm_api3('setting', 'create', $valuesToSave); $session = CRM_Core_Session::singleton(); diff --git a/CRM/EventsExtras/Hook/BuildForm/EventFee.php b/CRM/EventsExtras/Hook/BuildForm/EventFee.php index 2843f95..ff13c72 100644 --- a/CRM/EventsExtras/Hook/BuildForm/EventFee.php +++ b/CRM/EventsExtras/Hook/BuildForm/EventFee.php @@ -26,6 +26,7 @@ public function handle($formName, &$form) { return; } $this->hideField($form); + $this->buildForm($formName, $form); } private function buildForm($formName, &$form) { @@ -39,7 +40,9 @@ private function setDefaults(&$form){ $settings = [$paymentProcessor, $paymentProcessorDefault]; $settingValues = SettingsManager::getSettingsValue($settings); if ($settingValues[$paymentProcessor] == 0){ - $defaults['default_role_id'] = $settingValues[$paymentProcessorDefault]; + $defaultSettingString = implode(CRM_Core_DAO::VALUE_SEPARATOR, $settingValues[$paymentProcessorDefault]); + $paymentProcessorDefaultValue = (array_fill_keys(explode(CRM_Core_DAO::VALUE_SEPARATOR, $defaultSettingString), '1')); + $defaults['payment_processor'] = $paymentProcessorDefaultValue; } $form->setDefaults($defaults); } From c22244cae35bf62408ae40f29c4f9ff8122cd897 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Fri, 28 Jun 2019 13:54:13 +0100 Subject: [PATCH 41/97] RSE-210: Fixed undefinded css_class --- CRM/EventsExtras/Hook/BuildForm/BaseEvent.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php b/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php index 65ce49c..b1406d7 100644 --- a/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php +++ b/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php @@ -9,15 +9,15 @@ abstract class CRM_EventsExtras_Hook_BuildForm_BaseEvent { /** - * Event tab to display on the form + * Event tab to display on the form */ protected $eventTab; /** * Constractor for BuildForm class - * + * * @param string $eventTab - * + * */ protected function __construct($eventTab){ $this->eventTab = $eventTab; @@ -58,7 +58,7 @@ protected function hideField(CRM_Event_Form_ManageEvent &$form){ $settingsValue = SettingsManager::getSettingsValue(); $hiddenFields = []; foreach ($configFields as $config) { - if ($settingsValue[$config['name']] == 0){ + if ($settingsValue[$config['name']] == 0 && array_key_exists('css_class', $config['extra_attributes'])){ $hiddenFields[] = $config['extra_attributes']['css_class']; } } From 8a71361ee92e65fb5051f2f250fa166adcb0932f Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Fri, 28 Jun 2019 15:50:42 +0100 Subject: [PATCH 42/97] RSE-210: Fixed parent settings so UI can generate it dynamically --- settings/EventsExtrasDefault.setting.php | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/settings/EventsExtrasDefault.setting.php b/settings/EventsExtrasDefault.setting.php index a6fffe3..c469c76 100644 --- a/settings/EventsExtrasDefault.setting.php +++ b/settings/EventsExtrasDefault.setting.php @@ -134,7 +134,7 @@ 'help_text' => '', 'extra_attributes' => [ 'section' => SettingsManager::EVENT_FEE, - 'parent_setting' => 'eventsextras_payment_processor', + 'parent_setting' => 'eventsextras_payment_processor_selection', 'event_form_element_name' => 'payment_processor', 'class' => '', ], @@ -170,7 +170,7 @@ 'is_required' => TRUE, 'extra_attributes' => [ 'section' => SettingsManager::EVENT_FEE, - 'parent_setting' => 'eventsextras_enable_pay_later_option_default', + 'parent_setting' => 'eventsextras_enable_pay_later_option', 'event_form_element_name' => 'pay_later_text', 'class' => '', ], @@ -188,7 +188,7 @@ 'is_required' => TRUE, 'extra_attributes' => [ 'section' => SettingsManager::EVENT_FEE, - 'parent_setting' => 'eventsextras_enable_pay_later_option_default', + 'parent_setting' => 'eventsextras_enable_pay_later_option', 'event_form_element_name' => 'pay_later_receipt', 'class' => '', ], @@ -206,12 +206,11 @@ 'help_text' => '', 'extra_attributes' => [ 'section' => SettingsManager::EVENT_FEE, - 'parent_setting' => 'eventsextras_enable_pay_later_option_default', + 'parent_setting' => 'eventsextras_enable_pay_later_option', 'event_form_element_name' => 'is_billing_required', 'class' => '', ], ], - 'eventsextras_pending_participant_expiration_default' => [ 'name' => 'eventsextras_pending_participant_expiration_default', 'title' => ts('Set Default Pending Participant Expiration'), @@ -226,7 +225,7 @@ 'help_text' => '', 'extra_attributes' => [ 'section' => SettingsManager::EVENT_REGISTRATION, - 'parent_setting' => 'eventsextras_enable_pay_later_option', + 'parent_setting' => 'eventsextras_pending_participant_expiration', 'event_form_element_name' => 'expiration_time', 'class' => '', ], @@ -250,7 +249,6 @@ 'event_form_element_name' => 'allow_selfcancelxfer', ], ], - 'eventsextras_allow_self_service_default_time_limit' => [ 'name' => 'eventsextras_allow_self_service_default_time_limit', 'title' => ts('Set Default Cancellation or transfer time limit (hours) '), @@ -265,11 +263,10 @@ 'help_text' => '', 'extra_attributes' => [ 'section' => SettingsManager::EVENT_REGISTRATION, - 'parent_setting' => 'eventsextras_allow_self_service_default', + 'parent_setting' => 'eventsextras_allow_self_service', 'event_form_element_name' => 'selfcancelxfer_time', ], ], - 'eventsextras_register_multiple_participants_default' => [ 'name' => 'eventsextras_register_multiple_participants_default', 'title' => ts('Set Default Register multiple participants? '), @@ -295,9 +292,6 @@ 'quick_form_type' => 'Select', 'default' => 9, 'html_type' => 'select', - 'pseudoconstant' => [ - 'optionGroupName' => '', - ], 'add' => '1.0', 'is_domain' => 1, 'is_contact' => 0, @@ -305,8 +299,8 @@ 'help_text' => '', 'extra_attributes' => [ 'section' => SettingsManager::EVENT_REGISTRATION, - 'parent_setting' => 'eventsextras_register_multiple_participants_default', - 'event_form_element_name' => 'registration_end_date', + 'parent_setting' => 'eventsextras_register_multiple_participants', + 'event_form_element_name' => 'max_additional_participants', ], ], ]; From c5e10532f356b5051e0f018835dfe0c081c449cc Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Fri, 28 Jun 2019 15:51:43 +0100 Subject: [PATCH 43/97] RSE-210: Removed unused class --- eventsextras.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/eventsextras.php b/eventsextras.php index 6ff64f7..c6c643d 100644 --- a/eventsextras.php +++ b/eventsextras.php @@ -2,7 +2,6 @@ require_once 'eventsextras.civix.php'; use CRM_EventsExtras_ExtensionUtil as E; -use CRM_EventsExtras_SettingsManager as SettingsManager; /** * Implements hook_civicrm_buildForm(). @@ -20,7 +19,6 @@ function eventsextras_civicrm_buildForm($formName, &$form){ } } - /** * Implements hook_civicrm_pre(). * From 9c0b7aeba4d1bb97d55cdcc4270d93ea35e394ef Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Fri, 28 Jun 2019 15:53:28 +0100 Subject: [PATCH 44/97] RSE-210: Fixed warning if payment processors are not submitted --- CRM/EventsExtras/Form/Settings.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/CRM/EventsExtras/Form/Settings.php b/CRM/EventsExtras/Form/Settings.php index d240cb2..1d34cd2 100644 --- a/CRM/EventsExtras/Form/Settings.php +++ b/CRM/EventsExtras/Form/Settings.php @@ -66,13 +66,15 @@ public function buildQuickForm() { public function postProcess() { $configFields = SettingsManager::getConfigFields(); $submittedValues = $this->exportValues(); - $paymentProcessors = $submittedValues[SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION_DEFAULT']]; - //flip selected default paymentProcessors before saving to setting - $flipedPaymentProcessor = []; - foreach ($paymentProcessors as $selectValue => $selected){ - $flipedPaymentProcessor[] = $selectValue; + if (isset($submittedValues[SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION_DEFAULT']])) { + $paymentProcessors = $submittedValues[SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION_DEFAULT']]; + //flip selected default paymentProcessors before saving to setting + $flipedPaymentProcessor = []; + foreach ($paymentProcessors as $selectValue => $selected){ + $flipedPaymentProcessor[] = $selectValue; + } + $submittedValues[SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION_DEFAULT']] = $flipedPaymentProcessor; } - $submittedValues[SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION_DEFAULT']] = $flipedPaymentProcessor; $valuesToSave = array_intersect_key($submittedValues, $configFields); $result = civicrm_api3('setting', 'create', $valuesToSave); $session = CRM_Core_Session::singleton(); From 6f842d4d9dc43374284f3cc7e0c8263647310648 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Fri, 28 Jun 2019 15:54:52 +0100 Subject: [PATCH 45/97] RSE-210: Check only Even is paid or is online and fix warning issue when setting has not value --- CRM/EventsExtras/Hook/Pre/Event.php | 33 +++++++++++++++++------------ 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/CRM/EventsExtras/Hook/Pre/Event.php b/CRM/EventsExtras/Hook/Pre/Event.php index e01ca15..11912d9 100644 --- a/CRM/EventsExtras/Hook/Pre/Event.php +++ b/CRM/EventsExtras/Hook/Pre/Event.php @@ -33,9 +33,9 @@ private function preSetData($op, $id, &$params ){ } if (array_key_exists('event_type_id', $params)) { $this->preProcessData(SettingsManager::EVENT_INFO, $params); - } elseif (array_key_exists('is_monetary', $params)) { + } elseif (array_key_exists('is_monetary', $params) && $params['is_monetary'] == 1) { $this->preProcessData(SettingsManager::EVENT_FEE, $params); - } elseif (array_key_exists('is_online_registration', $params)) { + } elseif (array_key_exists('is_online_registration', $params) && $params['is_online_registration' == 1]) { $this->preProcessData(SettingsManager::EVENT_REGISTRATION, $params); } } @@ -46,22 +46,27 @@ private function preProcessData($section, &$params){ $fieldToProcess = []; foreach ($fields as $field){ $settingName = $field['name']; - $settingValue = SettingsManager::getSettingValue($settingName)[$settingName]; - if(!array_key_exists('parent_setting', $field['extra_attributes'])){ //handle parent setting - if ($settingValue == 0){ - $settingsToProcess[$settingName] = $settingName; - }else { - unset($fields[$settingName]); - } - } else { - if (in_array($field['extra_attributes']['parent_setting'], $settingsToProcess)){ - $formName = $field['extra_attributes']['event_form_element_name']; - $fieldToProcess[$formName] = $settingValue; + $settingValue = SettingsManager::getSettingValue($settingName); + if (isset($settingValue[$settingName])){ + $settingValue = $settingValue[$settingName]; + if (!array_key_exists('parent_setting', $field['extra_attributes'])){ //handle parent setting + if ($settingValue == 0){ + $settingsToProcess[$settingName] = $settingName; + }else { + unset($fields[$settingName]); + } + } else { + if (in_array($field['extra_attributes']['parent_setting'], $settingsToProcess)){ + $formName = $field['extra_attributes']['event_form_element_name']; + $fieldToProcess[$formName] = $settingValue; + } } } } foreach ($fieldToProcess as $field => $value){ - $params[$field] = $value; + if (!($section == SettingsManager::EVENT_FEE && $field == 'payment_processor')){ // dont care about payment processor if it is event section + $params[$field] = $value; + } } } } From 0c82d5404c3675d0bb5a261c15eaa7e9a8ac619d Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Fri, 28 Jun 2019 15:55:45 +0100 Subject: [PATCH 46/97] RSE-210: Check if settingValue is set --- CRM/EventsExtras/Hook/BuildForm/BaseEvent.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php b/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php index b1406d7..bbcad0e 100644 --- a/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php +++ b/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php @@ -58,7 +58,9 @@ protected function hideField(CRM_Event_Form_ManageEvent &$form){ $settingsValue = SettingsManager::getSettingsValue(); $hiddenFields = []; foreach ($configFields as $config) { - if ($settingsValue[$config['name']] == 0 && array_key_exists('css_class', $config['extra_attributes'])){ + if (isset($settingsValue[$config['name']]) && + $settingsValue[$config['name']] == 0 && + array_key_exists('css_class', $config['extra_attributes'])){ $hiddenFields[] = $config['extra_attributes']['css_class']; } } From a8103b2b3ee2e810374c2cf5f6fc7262fb985a5f Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Fri, 28 Jun 2019 15:56:59 +0100 Subject: [PATCH 47/97] RSE-210: Fixed is_allow_multiple participants is not showing in the setting form --- CRM/EventsExtras/SettingsManager.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CRM/EventsExtras/SettingsManager.php b/CRM/EventsExtras/SettingsManager.php index 4dac26e..6b1671c 100644 --- a/CRM/EventsExtras/SettingsManager.php +++ b/CRM/EventsExtras/SettingsManager.php @@ -39,7 +39,8 @@ class CRM_EventsExtras_SettingsManager { 'ALLOW_SELF_SERVICE_DEFAULT' => 'eventsextras_allow_self_service_default', 'ALLOW_SELF_SERVICE_DEFAULT_TIME_LIMIT' => 'eventsextras_allow_self_service_default_time_limit', 'REGISTER_MULTIPLE_PARTICIPANTS' => 'eventsextras_register_multiple_participants', - 'REGISTER_MULTIPLE_PARTICIPANTS_DEFAULT' => 'eventsextras_register_multiple_participants_default_maxinum_participant' + 'REGISTER_MULTIPLE_PARTICIPANTS_DEFULT' => 'eventsextras_register_multiple_participants_default', + 'REGISTER_MULTIPLE_PARTICIPANTS_DEFAULT_MAXINUM_PARTICIPANT' => 'eventsextras_register_multiple_participants_default_maxinum_participant' ]; /** From 4b6437529c4e6339433cfe0fd4c741fc87181427 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Fri, 28 Jun 2019 16:40:20 +0100 Subject: [PATCH 48/97] RSE-210: Show help and description as per settings --- CRM/EventsExtras/Form/Settings.php | 4 +- settings/EventsExtrasDefault.setting.php | 17 +++- templates/CRM/EventsExtras/Form/Settings.hlp | 86 ++++++++++---------- templates/CRM/EventsExtras/Form/Settings.tpl | 17 ++-- 4 files changed, 71 insertions(+), 53 deletions(-) diff --git a/CRM/EventsExtras/Form/Settings.php b/CRM/EventsExtras/Form/Settings.php index 1d34cd2..0a15e06 100644 --- a/CRM/EventsExtras/Form/Settings.php +++ b/CRM/EventsExtras/Form/Settings.php @@ -24,7 +24,7 @@ class CRM_EventsExtras_Form_Settings extends CRM_Core_Form { private $parentSettings = []; private $defaultSettingsDescription = []; - + private $defaultSettingsHelp = []; public function buildQuickForm() { CRM_Utils_System::setTitle(E::ts('CiviEvent Extras Settings')); @@ -44,6 +44,7 @@ public function buildQuickForm() { $this->generateDefaultSettingField($config); } $this->defaultSettingsDescription[$config['name']] = $config['description']; + $this->defaultSettingsHelp[$config['name']] = $config['is_help']; } $this->assignConfigSections($name, $config['extra_attributes']['section']); } @@ -58,6 +59,7 @@ public function buildQuickForm() { 'name' => E::ts('Cancel'), ], ]); + $this->assign('settingsHelp', $this->defaultSettingsHelp); $this->assign('settingsDescription', $this->defaultSettingsDescription); $this->assign('parentSettings', $this->parentSettings); $this->assign('displaySections', $this->displaySections); diff --git a/settings/EventsExtrasDefault.setting.php b/settings/EventsExtrasDefault.setting.php index c469c76..d3f64f9 100644 --- a/settings/EventsExtrasDefault.setting.php +++ b/settings/EventsExtrasDefault.setting.php @@ -19,6 +19,7 @@ 'is_domain' => 1, 'is_contact' => 0, 'description' => '', + 'is_help' => TRUE, 'help_text' => '', 'extra_attributes' => [ 'section' => SettingsManager::EVENT_INFO, @@ -41,6 +42,7 @@ 'add' => '1.0', 'is_domain' => 1, 'is_contact' => 0, + 'is_help' => TRUE, 'description' => '', 'help_text' => '', 'extra_attributes' => [ @@ -61,6 +63,7 @@ 'add' => '1.0', 'is_domain' => 1, 'is_contact' => 0, + 'is_help' => TRUE, 'description' => '', 'help_text' => '', 'extra_attributes' => [ @@ -79,6 +82,7 @@ 'add' => '1.0', 'is_domain' => 1, 'is_contact' => 0, + 'is_help' => TRUE, 'description' => '', 'help_text' => '', 'extra_attributes' => [ @@ -101,6 +105,7 @@ 'add' => '1.0', 'is_domain' => 1, 'is_contact' => 0, + 'is_help' => FALSE, 'description' => ts('Select the currency to be used for event registration.'), 'help_text' => '', 'extra_attributes' => [ @@ -121,6 +126,7 @@ 'add' => '1.0', 'is_domain' => 1, 'is_contact' => 0, + 'is_help' => FALSE, 'description' => ts(' If this is a paid event and you want users to be able to register and pay online, select a payment processor to use. NOTE: Alternatively, @@ -148,6 +154,7 @@ 'add' => '1.0', 'is_domain' => 1, 'is_contact' => 0, + 'is_help' => FALSE, 'description' => ts('Check this box if you want to give users the option to submit payment offline (e.g. mail in a check, call in a credit card, etc.). '), 'help_text' => '', 'extra_attributes' => [ @@ -165,9 +172,9 @@ 'add' => '1.0', 'is_domain' => 1, 'is_contact' => 0, + 'is_help' => FALSE, 'description' => ts('Text displayed next to the checkbox for the "pay later" option on the contribution form. You may include HTML formatting tags.'), 'help_text' => '', - 'is_required' => TRUE, 'extra_attributes' => [ 'section' => SettingsManager::EVENT_FEE, 'parent_setting' => 'eventsextras_enable_pay_later_option', @@ -183,9 +190,9 @@ 'add' => '1.0', 'is_domain' => 1, 'is_contact' => 0, + 'is_help' => FALSE, 'description' => ts('Instructions added to Confirmation and Thank-you pages when the user selects the "pay later" option (e.g. "Mail your check to ... within 3 business days."). '), 'help_text' => '', - 'is_required' => TRUE, 'extra_attributes' => [ 'section' => SettingsManager::EVENT_FEE, 'parent_setting' => 'eventsextras_enable_pay_later_option', @@ -202,6 +209,7 @@ 'add' => '1.0', 'is_domain' => 1, 'is_contact' => 0, + 'is_help' => FALSE, 'description' => ts('Check this box to require users who select the pay later option to provide billing name and address.'), 'help_text' => '', 'extra_attributes' => [ @@ -221,6 +229,7 @@ 'add' => '1.0', 'is_domain' => 1, 'is_contact' => 0, + 'is_help' => TRUE, 'description' => ts(''), 'help_text' => '', 'extra_attributes' => [ @@ -241,6 +250,7 @@ 'add' => '1.0', 'is_domain' => 1, 'is_contact' => 0, + 'is_help' => TRUE, 'description' => ts(''), 'help_text' => '', 'extra_attributes' => [ @@ -259,6 +269,7 @@ 'add' => '1.0', 'is_domain' => 1, 'is_contact' => 0, + 'is_help' => TRUE, 'description' => ts(''), 'help_text' => '', 'extra_attributes' => [ @@ -277,6 +288,7 @@ 'add' => '1.0', 'is_domain' => 1, 'is_contact' => 0, + 'is_help' => TRUE, 'description' => ts(''), 'help_text' => '', 'extra_attributes' => [ @@ -295,6 +307,7 @@ 'add' => '1.0', 'is_domain' => 1, 'is_contact' => 0, + 'is_help' => TRUE, 'description' => ts(''), 'help_text' => '', 'extra_attributes' => [ diff --git a/templates/CRM/EventsExtras/Form/Settings.hlp b/templates/CRM/EventsExtras/Form/Settings.hlp index 533d487..c6bb3a9 100644 --- a/templates/CRM/EventsExtras/Form/Settings.hlp +++ b/templates/CRM/EventsExtras/Form/Settings.hlp @@ -1,77 +1,77 @@ -{htxt id="eventsextras_roles"} +{htxt id="eventsextras_roles_default"} {ts} - Show/Hide Default Role. - If hide is selected, admin can set a global default from available options. + The Role you select here is automatically assigned to people when they register online for this event (usually the default 'Attendee' role). + You can also allow people to choose a Role by creating a Profile with the Participant Role field. + Then include that Profile when you configure the Online Registration page for this event. {/ts} {/htxt} -{htxt id="eventsextras_participant_listing"} +{htxt id="eventsextras_participant_listing_default"} {ts} - Show/Hide: Participant listing - If hide is selected, admin can set a global default (default to disabled) + To allow users to see a listing of participants, set this field to 'Name' (list names only), + 'Name and Email', or 'Name, Status and Register Date'. + You will need to set Access Control permissions to include 'view event participants' for any Roles you want to access this listing. + After adding your event, create links to the listing page by copying the URL provided in the 'Participant Listing' section of the Configure Event page. {/ts} {/htxt} -{htxt id="eventsextras_event_summary"} - {ts}Show/Hide: Events summary{/ts} -{/htxt} - -{htxt id="eventsextras_completed_description"} - {ts}Show/Hide: Complete description{/ts} -{/htxt} - -{htxt id="eventsextras_include_map_event_location"} +{htxt id="eventsextras_include_map_event_location_default"} {ts} - Show/Hide: Include Map to Event Location. - If hide is selected, admin can set a global default from available options + Include map presenting event location on event information page? + (A map provider must be configured under + Administer > System Settings > Mapping and Geocoding) {/ts} {/htxt} -{htxt id="eventsextras_public_event"} +{htxt id="eventsextras_public_event_default"} {ts} - Show/Hide: Public Event, - If hide is selected, admin can set a global default from available options + When enabled, this event will be included in iCalendar feeds + and displayed on your site's "Upcoming Events" block. {/ts} {/htxt} -{htxt id="eventsextras_currency"} - {ts} - Show/Hide: Currency. - if hide is selected, admin can set a global default from available options - {/ts} -{/htxt} -{htxt id="eventsextras_enable_pay_later_option"} +{htxt id="eventsextras_pending_participant_expiration_default"} {ts} - Show/Hide: Enable pay later option - if hide is selected, admin can set a global default from available options + Time limit in hours for confirming/finishing registration by participants with any of the pending statuses. + Enter 0 (or leave empty) to disable this feature. {/ts} {/htxt} -{htxt id="eventsextras_payment_processor_selection"} +{htxt id="eventsextras_allow_self_service_default"} {ts} - Show/Hide: Payment Processor selection - if hide is selected, admin can set a global default from available options + Check this box if you want to allow registered participants to either cancel their registration + OR transfer it to another participant. If this feature is enabled, + event confirmation emails will include a link to a Cancel or Transfer form. + Automated refunds for cancellations are NOT currently supported. + Participants who have paid for an event will be notified that cancellations are not refundable. {/ts} {/htxt} -{htxt id="eventsextras_pending_participant_expiration"} - {ts}Show/Hide: Pending participant expiration (hours) - If hide is selected, admin can set a global default from available options +{htxt id="eventsextras_allow_self_service_default_time_limit"} + {ts} + Number of hours prior to event start date to allow self-service cancellation or transfer. + Enter 0 (or leave empty) to allow cancellation or transfer up until the event has started. {/ts} {/htxt} -{htxt id="eventsextras_allow_self_service"} +{htxt id="eventsextras_register_multiple_participants_default"} {ts} - Show/Hide: Allow self-service cancellation or transfer? - If hide is selected, admin can set a global default from available options - {/ts} + Check this box to allow users to register themselves AND additional participants for an event. + When this feature is enabled, users have the option to specify the number of additional participants they are registering for. + If this is a paid event, they can select a different event fees for each participant - and will be charged the total of those fees. + If a profile is included - they will complete the profile information for each participant. + You can use different profile for the person who is registering than for "Additional Participants". + For example, you may want to require an email address from the person entering the registration + while not requiring (or even requesting) emails for additional participants (i.e. their "guests"). + {/ts} {/htxt} -{htxt id="eventsextras_register_multiple_participants"} +{htxt id="eventsextras_register_multiple_participants_default_maxinum_participant"} {ts} - Show/Hide: Register multiple participants - If hide is selected, admin can set a global default from available options - {/ts} + Limit the number of additional participants that can be registered in a single booking. + Eg: if you choose '2' then the lead booker can bring 2 guests; + there would be a limit of 3 participants in total per booking. + {/ts} {/htxt} diff --git a/templates/CRM/EventsExtras/Form/Settings.tpl b/templates/CRM/EventsExtras/Form/Settings.tpl index e4cf59a..6b84900 100644 --- a/templates/CRM/EventsExtras/Form/Settings.tpl +++ b/templates/CRM/EventsExtras/Form/Settings.tpl @@ -34,19 +34,22 @@ {if $form.$elementName.type neq 'checkbox'}
{$form.$elementName.label} - {if !$parentSettings.$elementName} {help id=$form.$elementName.name} + {if !$parentSettings.$elementName && $settingsHelp.$elementName == TRUE} + {help id=$form.$elementName.name} {/if}
{/if}
- {$form.$elementName.html} - {if $form.$elementName.type eq 'checkbox'} - {$form.$elementName.label}{if !$parentSettings.$elementName} {help id=$form.$elementName.name} - {/if} - {if !$parentSettings.$elementName} -
{$settingsDescription.$elementName}
+ {$form.$elementName.html} + {if $form.$elementName.type eq 'checkbox'} + {$form.$elementName.label} + {if !$parentSettings.$elementName && $settingsHelp.$elementName == TRUE} + {help id=$form.$elementName.name} {/if} {/if} + {if !$parentSettings.$elementName} +
{$settingsDescription.$elementName}
+ {/if}
From abf81cfe225a515146a3778e914a80fa6efc6939 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Fri, 28 Jun 2019 16:53:40 +0100 Subject: [PATCH 49/97] RSE-210: Tweak UI --- CRM/EventsExtras/Form/Settings.php | 6 +++--- templates/CRM/EventsExtras/Form/Settings.tpl | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CRM/EventsExtras/Form/Settings.php b/CRM/EventsExtras/Form/Settings.php index 0a15e06..6848e2e 100644 --- a/CRM/EventsExtras/Form/Settings.php +++ b/CRM/EventsExtras/Form/Settings.php @@ -17,9 +17,9 @@ class CRM_EventsExtras_Form_Settings extends CRM_Core_Form { * @var array[] */ private $displaySections = [ - SettingsManager::EVENT_INFO => ['name' => 'Event Info Settings'], - SettingsManager::EVENT_FEE => ['name' => 'Fee Settings'], - SettingsManager::EVENT_REGISTRATION => ['name' => 'Online Registration Settings'], + SettingsManager::EVENT_INFO => ['title' => 'Event Info Settings'], + SettingsManager::EVENT_FEE => ['title' => 'Fee Settings'], + SettingsManager::EVENT_REGISTRATION => ['title' => 'Online Registration Settings'], ]; private $parentSettings = []; diff --git a/templates/CRM/EventsExtras/Form/Settings.tpl b/templates/CRM/EventsExtras/Form/Settings.tpl index 6b84900..99815ed 100644 --- a/templates/CRM/EventsExtras/Form/Settings.tpl +++ b/templates/CRM/EventsExtras/Form/Settings.tpl @@ -27,14 +27,14 @@
{include file="CRM/common/formButtons.tpl" location="bottom"}
- {foreach from=$displaySections item=section} -

{ts}{$section.name}{/ts}

+ {foreach from=$displaySections key=sectionName item=section} +

{ts}{$section.title}{/ts}

{foreach from=$section.fields item=elementName}
{if $form.$elementName.type neq 'checkbox'}
{$form.$elementName.label} - {if !$parentSettings.$elementName && $settingsHelp.$elementName == TRUE} + {if !$parentSettings.$elementName && $settingsHelp.$elementName eq TRUE} {help id=$form.$elementName.name} {/if}
@@ -43,7 +43,7 @@ {$form.$elementName.html} {if $form.$elementName.type eq 'checkbox'} {$form.$elementName.label} - {if !$parentSettings.$elementName && $settingsHelp.$elementName == TRUE} + {if !$parentSettings.$elementName && $settingsHelp.$elementName eq TRUE} {help id=$form.$elementName.name} {/if} {/if} From e5158f4f1056dbb0425794fa65d5d2b439d5309e Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Fri, 28 Jun 2019 22:28:39 +0100 Subject: [PATCH 50/97] RSE-210: TWeak UK to display similar to Event forms --- CRM/EventsExtras/Form/Settings.php | 1 + templates/CRM/EventsExtras/Form/Settings.tpl | 37 +++++++++++--------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/CRM/EventsExtras/Form/Settings.php b/CRM/EventsExtras/Form/Settings.php index 6848e2e..4606c0b 100644 --- a/CRM/EventsExtras/Form/Settings.php +++ b/CRM/EventsExtras/Form/Settings.php @@ -63,6 +63,7 @@ public function buildQuickForm() { $this->assign('settingsDescription', $this->defaultSettingsDescription); $this->assign('parentSettings', $this->parentSettings); $this->assign('displaySections', $this->displaySections); + $this->assign('eventRegistrationSection', SettingsManager::EVENT_REGISTRATION); } public function postProcess() { diff --git a/templates/CRM/EventsExtras/Form/Settings.tpl b/templates/CRM/EventsExtras/Form/Settings.tpl index 99815ed..6121069 100644 --- a/templates/CRM/EventsExtras/Form/Settings.tpl +++ b/templates/CRM/EventsExtras/Form/Settings.tpl @@ -31,27 +31,30 @@

{ts}{$section.title}{/ts}

{foreach from=$section.fields item=elementName}
- {if $form.$elementName.type neq 'checkbox'} -
+
+ {if $form.$elementName.type eq 'checkbox' && $sectionName neq $eventRegistrationSection} + {$form.$elementName.html} + {else} + {$form.$elementName.label} + {if !$parentSettings.$elementName && $settingsHelp.$elementName eq TRUE} + {help id=$form.$elementName.name} + {/if} + {/if} +
+
+ {if $form.$elementName.type eq 'checkbox' && $sectionName neq $eventRegistrationSection} {$form.$elementName.label} {if !$parentSettings.$elementName && $settingsHelp.$elementName eq TRUE} - {help id=$form.$elementName.name} + {help id=$form.$elementName.name} {/if} -
- {/if} -
- {$form.$elementName.html} - {if $form.$elementName.type eq 'checkbox'} - {$form.$elementName.label} - {if !$parentSettings.$elementName && $settingsHelp.$elementName eq TRUE} - {help id=$form.$elementName.name} + {else} + {$form.$elementName.html} {/if} - {/if} - {if !$parentSettings.$elementName} -
{$settingsDescription.$elementName}
- {/if} -
-
+ {if !$parentSettings.$elementName} +
{$settingsDescription.$elementName}
+ {/if} +
+
{/foreach} {/foreach} From 9aa3e96dd81cf3328c4a4462967369b576443799 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Sat, 29 Jun 2019 10:15:07 +0100 Subject: [PATCH 51/97] RSE-210: Rename section class as per CiviCRM style --- templates/CRM/EventsExtras/Form/Settings.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/CRM/EventsExtras/Form/Settings.tpl b/templates/CRM/EventsExtras/Form/Settings.tpl index 6121069..b274846 100644 --- a/templates/CRM/EventsExtras/Form/Settings.tpl +++ b/templates/CRM/EventsExtras/Form/Settings.tpl @@ -30,7 +30,7 @@ {foreach from=$displaySections key=sectionName item=section}

{ts}{$section.title}{/ts}

{foreach from=$section.fields item=elementName} -
+
{if $form.$elementName.type eq 'checkbox' && $sectionName neq $eventRegistrationSection} {$form.$elementName.html} From 33e5b4705a0b6c70c26469445f3e61555e694fc4 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Sat, 29 Jun 2019 10:15:48 +0100 Subject: [PATCH 52/97] RSE-210: Added validation rules for select to hide the element --- CRM/EventsExtras/Form/Settings.php | 37 ++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/CRM/EventsExtras/Form/Settings.php b/CRM/EventsExtras/Form/Settings.php index 4606c0b..916b5fc 100644 --- a/CRM/EventsExtras/Form/Settings.php +++ b/CRM/EventsExtras/Form/Settings.php @@ -66,6 +66,43 @@ public function buildQuickForm() { $this->assign('eventRegistrationSection', SettingsManager::EVENT_REGISTRATION); } + public function addRules() { + $this->addFormRule(['CRM_EventsExtras_Form_Settings', 'validateRules']); + } + + + public static function validateRules($values) { + $errors = []; + + $roles = SettingsManager::SETTING_FIELDS['ROLES']; + $rolesDefault = SettingsManager::SETTING_FIELDS['ROLES_DEFAULT']; + $paymentProcessor = SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION']; + $paymentProcessorDefault =SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION_DEFAULT']; + $payLaterOption = SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION']; + $paylaterOptionDefault= SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION_DEFAULT']; + $payLaterLabel = SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION_DEFAULT_LABEL']; + $payLaterInsuection = SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION_DEFAULT_LABEL_INSTRUCTION']; + + if ($values[$roles] == 0 && ($values[$rolesDefault]) == NULL) { + $errors[$rolesDefault] = E::ts('Default Role is a required field'); + } + + if ($values[$paymentProcessor] == 0 && !isset($values[$paymentProcessorDefault]) || empty($values[$paymentProcessorDefault])){ + $errors[$paymentProcessorDefault] = E::ts('Please select at least one payment processor and/or enable the pay later option.'); + } + + if ($values[$payLaterOption] == 0 && isset($values[$paylaterOptionDefault]) && $values[$paylaterOptionDefault] == 1){ + if ($values[$payLaterLabel] == NULL){ + $errors[$payLaterLabel] = E::ts(' Please enter the Pay Later prompt to be displayed on the Registration form.'); + } + if ($values[$payLaterInsuection] == NULL){ + $errors[$payLaterInsuection] = E::ts('Please enter the Pay Later instructions to be displayed to your users.'); + } + } + + return empty($errors) ? TRUE : $errors; + } + public function postProcess() { $configFields = SettingsManager::getConfigFields(); $submittedValues = $this->exportValues(); From 6ddea506a6a73a98811abdf8ee4d0e1e7432f697 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Sat, 29 Jun 2019 10:25:51 +0100 Subject: [PATCH 53/97] RSE-210: Fixed validation on payment processor --- CRM/EventsExtras/Form/Settings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CRM/EventsExtras/Form/Settings.php b/CRM/EventsExtras/Form/Settings.php index 916b5fc..d18c893 100644 --- a/CRM/EventsExtras/Form/Settings.php +++ b/CRM/EventsExtras/Form/Settings.php @@ -87,7 +87,7 @@ public static function validateRules($values) { $errors[$rolesDefault] = E::ts('Default Role is a required field'); } - if ($values[$paymentProcessor] == 0 && !isset($values[$paymentProcessorDefault]) || empty($values[$paymentProcessorDefault])){ + if ($values[$paymentProcessor] == 0 && !isset($values[$paymentProcessorDefault])){ $errors[$paymentProcessorDefault] = E::ts('Please select at least one payment processor and/or enable the pay later option.'); } From ea2c9dbc7bdd693474c09d104791a0bcee4fc5d5 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Mon, 1 Jul 2019 17:44:49 +0100 Subject: [PATCH 54/97] RSE-210: Fixed to use correct array index --- CRM/EventsExtras/Hook/BuildForm/EventInfo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CRM/EventsExtras/Hook/BuildForm/EventInfo.php b/CRM/EventsExtras/Hook/BuildForm/EventInfo.php index d29f639..9be2d17 100644 --- a/CRM/EventsExtras/Hook/BuildForm/EventInfo.php +++ b/CRM/EventsExtras/Hook/BuildForm/EventInfo.php @@ -40,7 +40,7 @@ private function setDefaults(&$form){ $settings = [$role, $roleDefault]; $settingValues = SettingsManager::getSettingsValue($settings); if ($settingValues[$role] == 0){ - $defaults['payment_processor'] = $settingValues[$roleDefault]; + $defaults['default_role_id'] = $settingValues[$roleDefault]; } $form->setDefaults($defaults); } From c6f279a14b0d8d411d114aa1a6ddb91f085a73a5 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Mon, 1 Jul 2019 17:45:51 +0100 Subject: [PATCH 55/97] RSE-210: Change checkbox type from String to Integer --- settings/EventsExtrasDefault.setting.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/settings/EventsExtrasDefault.setting.php b/settings/EventsExtrasDefault.setting.php index d3f64f9..9dab656 100644 --- a/settings/EventsExtrasDefault.setting.php +++ b/settings/EventsExtrasDefault.setting.php @@ -57,7 +57,7 @@ 'eventsextras_include_map_event_location_default' => [ 'name' => 'eventsextras_include_map_event_location_default', 'title' => ts('Set Default Include Map to Event Location'), - 'type' => 'String', + 'type' => 'Integer', 'default' => '', 'html_type' => 'checkbox', 'add' => '1.0', @@ -76,7 +76,7 @@ 'eventsextras_public_event_default' => [ 'name' => 'eventsextras_public_event_default', 'title' => ts('Set Default Public Event'), - 'type' => 'String', + 'type' => 'Integer', 'default' => 0, 'html_type' => 'checkbox', 'add' => '1.0', @@ -168,6 +168,7 @@ 'name' => 'eventsextras_enable_pay_later_option_default_label', 'title' => ts('Set Default Pay Later Label'), 'type' => 'String', + 'default' => '', 'html_type' => 'textarea', 'add' => '1.0', 'is_domain' => 1, @@ -186,6 +187,7 @@ 'name' => 'eventsextras_enable_pay_later_option_default_instruction', 'title' => ts('Set Default Pay Later Instruction'), 'type' => 'String', + 'default' => '', 'html_type' => 'textarea', 'add' => '1.0', 'is_domain' => 1, From 774dca270bd563ee4226dff12ef61bec9f0c908a Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Mon, 1 Jul 2019 17:46:19 +0100 Subject: [PATCH 56/97] RSE-210: Clean up comment --- CRM/EventsExtras/SettingsManager.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CRM/EventsExtras/SettingsManager.php b/CRM/EventsExtras/SettingsManager.php index 6b1671c..e75705f 100644 --- a/CRM/EventsExtras/SettingsManager.php +++ b/CRM/EventsExtras/SettingsManager.php @@ -44,7 +44,7 @@ class CRM_EventsExtras_SettingsManager { ]; /** - * Gets the settings Value + * Gets a single setting value * * @return array */ @@ -56,7 +56,7 @@ public static function getSettingValue($setting){ } /** - * Gets the settings Value + * Gets multiple settings values * * @return array */ @@ -108,5 +108,6 @@ private static function fetchSettingFields() { } return $settingFields; } + } From 52730ef1181fd7115eee81e5f4f43939cab10e0e Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Mon, 1 Jul 2019 17:47:23 +0100 Subject: [PATCH 57/97] RSE-210: Fixed condition --- CRM/EventsExtras/Hook/Pre/Event.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/CRM/EventsExtras/Hook/Pre/Event.php b/CRM/EventsExtras/Hook/Pre/Event.php index 11912d9..9cf4bc0 100644 --- a/CRM/EventsExtras/Hook/Pre/Event.php +++ b/CRM/EventsExtras/Hook/Pre/Event.php @@ -35,7 +35,7 @@ private function preSetData($op, $id, &$params ){ $this->preProcessData(SettingsManager::EVENT_INFO, $params); } elseif (array_key_exists('is_monetary', $params) && $params['is_monetary'] == 1) { $this->preProcessData(SettingsManager::EVENT_FEE, $params); - } elseif (array_key_exists('is_online_registration', $params) && $params['is_online_registration' == 1]) { + } elseif (array_key_exists('is_online_registration', $params) && $params['is_online_registration'] == 1) { $this->preProcessData(SettingsManager::EVENT_REGISTRATION, $params); } } @@ -52,10 +52,8 @@ private function preProcessData($section, &$params){ if (!array_key_exists('parent_setting', $field['extra_attributes'])){ //handle parent setting if ($settingValue == 0){ $settingsToProcess[$settingName] = $settingName; - }else { - unset($fields[$settingName]); } - } else { + } else { //handle child setting and get element name if (in_array($field['extra_attributes']['parent_setting'], $settingsToProcess)){ $formName = $field['extra_attributes']['event_form_element_name']; $fieldToProcess[$formName] = $settingValue; From 6af4f65f644cc8f2afe3c2e8304d65b4a0ce9f0b Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Mon, 1 Jul 2019 17:48:18 +0100 Subject: [PATCH 58/97] RSE-210: Assign default value for uncheck checkbox --- CRM/EventsExtras/Form/Settings.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CRM/EventsExtras/Form/Settings.php b/CRM/EventsExtras/Form/Settings.php index d18c893..f74170b 100644 --- a/CRM/EventsExtras/Form/Settings.php +++ b/CRM/EventsExtras/Form/Settings.php @@ -106,6 +106,7 @@ public static function validateRules($values) { public function postProcess() { $configFields = SettingsManager::getConfigFields(); $submittedValues = $this->exportValues(); + $valuesToSave = []; if (isset($submittedValues[SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION_DEFAULT']])) { $paymentProcessors = $submittedValues[SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION_DEFAULT']]; //flip selected default paymentProcessors before saving to setting @@ -116,6 +117,13 @@ public function postProcess() { $submittedValues[SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION_DEFAULT']] = $flipedPaymentProcessor; } $valuesToSave = array_intersect_key($submittedValues, $configFields); + //makesure uncheck checkecbox value is set to default into setting + //when user select hide but did not select the default. + foreach ($configFields as $field => $config){ + if (!isset($submittedValues[$field])){ + $valuesToSave[$field] = $config['default']; + } + } $result = civicrm_api3('setting', 'create', $valuesToSave); $session = CRM_Core_Session::singleton(); if ($result['is_error']== 0){ From f8300b456750ac55480f79c5c8237a659a219781 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Wed, 3 Jul 2019 13:00:13 +0100 Subject: [PATCH 59/97] RSE-210: To ensure that default payment processors that store in settings are being saved --- CRM/EventsExtras/Hook/Pre/Event.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/CRM/EventsExtras/Hook/Pre/Event.php b/CRM/EventsExtras/Hook/Pre/Event.php index 9cf4bc0..048ed09 100644 --- a/CRM/EventsExtras/Hook/Pre/Event.php +++ b/CRM/EventsExtras/Hook/Pre/Event.php @@ -62,7 +62,15 @@ private function preProcessData($section, &$params){ } } foreach ($fieldToProcess as $field => $value){ - if (!($section == SettingsManager::EVENT_FEE && $field == 'payment_processor')){ // dont care about payment processor if it is event section + // flip payment processor if it is event fee section + if (($section == SettingsManager::EVENT_FEE && $field == 'payment_processor')){ + //flip selected default paymentProcessors before saving to setting + $flipedPaymentProcessor = []; + foreach ($value as $selectValue => $selected){ + $flipedPaymentProcessor[$selected] = $selectValue; + } + $params[$field] = $flipedPaymentProcessor; + }else { $params[$field] = $value; } } From 1198e0b7dfbc7c050ec8ec831c9fb2c8e53e8262 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Thu, 4 Jul 2019 16:21:14 +0100 Subject: [PATCH 60/97] RSE-210: Clean up and update some functions as per PR review --- CRM/EventsExtras/Form/Settings.php | 54 ++++++++++++------- CRM/EventsExtras/Hook/BuildForm/BaseEvent.php | 8 +-- CRM/EventsExtras/Hook/BuildForm/EventFee.php | 2 +- CRM/EventsExtras/Hook/BuildForm/EventInfo.php | 4 ++ CRM/EventsExtras/Hook/Pre/Event.php | 19 ++++++- CRM/EventsExtras/SettingsManager.php | 2 +- settings/EventsExtrasDefault.setting.php | 34 ++++++------ 7 files changed, 79 insertions(+), 44 deletions(-) diff --git a/CRM/EventsExtras/Form/Settings.php b/CRM/EventsExtras/Form/Settings.php index f74170b..2a0b0e9 100644 --- a/CRM/EventsExtras/Form/Settings.php +++ b/CRM/EventsExtras/Form/Settings.php @@ -30,21 +30,10 @@ public function buildQuickForm() { CRM_Utils_System::setTitle(E::ts('CiviEvent Extras Settings')); $configFields = SettingsManager::getConfigFields(); foreach ($configFields as $name => $config) { - if(!array_key_exists('parent_setting', $config['extra_attributes'])){ - $this->addRadio( - $name, - E::ts($config['title']), - [1 => E::ts('Show'), 0 => E::ts('Hide')] - ); - $this->parentSettings[$config['name']] = TRUE; + if (!array_key_exists('parent_setting', $config['extra_attributes'])){ + $this->addChildElement($name, $config); } else { //handle default setting form - if ($config['html_type'] == 'select') { - $this->generateDefaultSelectList($config); - }else { - $this->generateDefaultSettingField($config); - } - $this->defaultSettingsDescription[$config['name']] = $config['description']; - $this->defaultSettingsHelp[$config['name']] = $config['is_help']; + $this->addParentElement($config); } $this->assignConfigSections($name, $config['extra_attributes']['section']); } @@ -71,6 +60,11 @@ public function addRules() { } + /** + * This functaion is for validating EventsExtras Setting Form + * + * @param array $values + */ public static function validateRules($values) { $errors = []; @@ -133,7 +127,26 @@ public function postProcess() { } } - private function generatePaymentProcessorElement($setting){ + private function addParentElement($config){ + if ($config['html_type'] == 'select') { + $this->generateDefaultSelectList($config); + } else { + $this->generateDefaultSettingField($config); + } + $this->defaultSettingsDescription[$config['name']] = $config['description']; + $this->defaultSettingsHelp[$config['name']] = $config['is_help']; + } + + private function addChildElement($name, $config){ + $this->addRadio( + $name, + E::ts($config['title']), + [1 => E::ts('Show'), 0 => E::ts('Hide')] + ); + $this->parentSettings[$config['name']] = TRUE; + } + + private function generatePaymentProcessorField($setting){ $paymentProcessor = CRM_Core_PseudoConstant::paymentProcessor(); $this->addCheckBox( $setting['name'], @@ -151,7 +164,7 @@ private function generatePaymentProcessorElement($setting){ */ private function generateDefaultSettingField($setting) { if ($setting['name'] == SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION_DEFAULT']) { - $this->generatePaymentProcessorElement($setting); + $this->generatePaymentProcessorField($setting); } else { $this->add( $setting['html_type'], @@ -173,7 +186,7 @@ private function generateDefaultSelectList($setting) { 'sequential' => 1, 'name' => $setting['pseudoconstant']['optionGroupName'], 'api.OptionValue.get' => [' - option_group_id' => "id", + option_group_id' => 'id', 'options' => [ 'limit' => 0, ], @@ -183,13 +196,14 @@ private function generateDefaultSelectList($setting) { foreach ($values as $value){ $options[$value['value']] = $value['label']; } - } else { // for default maxinum participant - foreach (range(1, 9) as $value){ + } else if ($setting['name'] == SettingsManager::SETTING_FIELDS['REGISTER_MULTIPLE_PARTICIPANTS_DEFAULT_MAXIMUM_PARTICIPANT']){ + // for default maxinum participant + foreach (range(1, 9) as $value){ $options[$value] = $value; } } $this->add( - $setting['html_type'], + 'Select', $setting['name'], E::ts($setting['title']), $options, diff --git a/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php b/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php index bbcad0e..e4bda47 100644 --- a/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php +++ b/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php @@ -57,10 +57,12 @@ protected function hideField(CRM_Event_Form_ManageEvent &$form){ $configFields = SettingsManager::getConfigFields($this->eventTab); $settingsValue = SettingsManager::getSettingsValue(); $hiddenFields = []; + foreach ($configFields as $config) { - if (isset($settingsValue[$config['name']]) && - $settingsValue[$config['name']] == 0 && - array_key_exists('css_class', $config['extra_attributes'])){ + $configNameExists = isset($settingsValue[$config['name']]); + $configNameIsZero = $settingsValue[$config['name']] == 0; + $cssClassExists = array_key_exists('css_class', $config['extra_attributes']); + if ($configNameExists && $configNameIsZero && $cssClassExists){ $hiddenFields[] = $config['extra_attributes']['css_class']; } } diff --git a/CRM/EventsExtras/Hook/BuildForm/EventFee.php b/CRM/EventsExtras/Hook/BuildForm/EventFee.php index ff13c72..a8b50e7 100644 --- a/CRM/EventsExtras/Hook/BuildForm/EventFee.php +++ b/CRM/EventsExtras/Hook/BuildForm/EventFee.php @@ -42,7 +42,7 @@ private function setDefaults(&$form){ if ($settingValues[$paymentProcessor] == 0){ $defaultSettingString = implode(CRM_Core_DAO::VALUE_SEPARATOR, $settingValues[$paymentProcessorDefault]); $paymentProcessorDefaultValue = (array_fill_keys(explode(CRM_Core_DAO::VALUE_SEPARATOR, $defaultSettingString), '1')); - $defaults['payment_processor'] = $paymentProcessorDefaultValue; + $defaults['payment_processor'] = $paymentProcessorDefaultValue; } $form->setDefaults($defaults); } diff --git a/CRM/EventsExtras/Hook/BuildForm/EventInfo.php b/CRM/EventsExtras/Hook/BuildForm/EventInfo.php index 9be2d17..8e809d7 100644 --- a/CRM/EventsExtras/Hook/BuildForm/EventInfo.php +++ b/CRM/EventsExtras/Hook/BuildForm/EventInfo.php @@ -33,6 +33,10 @@ private function buildForm($formName, &$form) { $this->setDefaults($form); } + /** + * Set defaults for form. + * + */ private function setDefaults(&$form){ $defaults = []; $role = SettingsManager::SETTING_FIELDS['ROLES']; diff --git a/CRM/EventsExtras/Hook/Pre/Event.php b/CRM/EventsExtras/Hook/Pre/Event.php index 048ed09..8eef68b 100644 --- a/CRM/EventsExtras/Hook/Pre/Event.php +++ b/CRM/EventsExtras/Hook/Pre/Event.php @@ -7,7 +7,14 @@ */ class CRM_EventsExtras_Hook_Pre_Event { - + /** + * Handle Hook Pre Event + * + * @param string $formName + * @param string $objectName + * @param int $id + * @param array $params + */ public function handle($op, $objectName, $id, &$params) { if (!$this->shouldHandle($op, $objectName)) { return; @@ -27,6 +34,14 @@ private function shouldHandle($op, $objectName) { return $objectName == 'Event'; } + /** + * Set event parameter piror setting to database + * + * @param string $op + * @param int $id + * @param array $params + * + */ private function preSetData($op, $id, &$params ){ if ($op == 'delete' || $op == 'view') { return; @@ -50,7 +65,7 @@ private function preProcessData($section, &$params){ if (isset($settingValue[$settingName])){ $settingValue = $settingValue[$settingName]; if (!array_key_exists('parent_setting', $field['extra_attributes'])){ //handle parent setting - if ($settingValue == 0){ + if ($settingValue == 0) { $settingsToProcess[$settingName] = $settingName; } } else { //handle child setting and get element name diff --git a/CRM/EventsExtras/SettingsManager.php b/CRM/EventsExtras/SettingsManager.php index e75705f..ddec34b 100644 --- a/CRM/EventsExtras/SettingsManager.php +++ b/CRM/EventsExtras/SettingsManager.php @@ -40,7 +40,7 @@ class CRM_EventsExtras_SettingsManager { 'ALLOW_SELF_SERVICE_DEFAULT_TIME_LIMIT' => 'eventsextras_allow_self_service_default_time_limit', 'REGISTER_MULTIPLE_PARTICIPANTS' => 'eventsextras_register_multiple_participants', 'REGISTER_MULTIPLE_PARTICIPANTS_DEFULT' => 'eventsextras_register_multiple_participants_default', - 'REGISTER_MULTIPLE_PARTICIPANTS_DEFAULT_MAXINUM_PARTICIPANT' => 'eventsextras_register_multiple_participants_default_maxinum_participant' + 'REGISTER_MULTIPLE_PARTICIPANTS_DEFAULT_MAXIMUM_PARTICIPANT' => 'eventsextras_register_multiple_participants_default_maximum_participant' ]; /** diff --git a/settings/EventsExtrasDefault.setting.php b/settings/EventsExtrasDefault.setting.php index 9dab656..d9b2867 100644 --- a/settings/EventsExtrasDefault.setting.php +++ b/settings/EventsExtrasDefault.setting.php @@ -23,7 +23,7 @@ 'help_text' => '', 'extra_attributes' => [ 'section' => SettingsManager::EVENT_INFO, - 'parent_setting' => 'eventsextras_roles', + 'parent_setting' => SettingsManager::SETTING_FIELDS['ROLES'], 'event_form_element_name' => 'default_role_id', 'class' => 'crm-select2', 'placeholder' => ts('- Select -'), @@ -47,7 +47,7 @@ 'help_text' => '', 'extra_attributes' => [ 'section' => SettingsManager::EVENT_INFO, - 'parent_setting' => 'eventsextras_participant_listing', + 'parent_setting' => SettingsManager::SETTING_FIELDS['PARTICIPANT_LISTING'], 'event_form_element_name' => 'participant_listing_id', 'class' => 'crm-select2', 'placeholder' => ts('Disabled'), @@ -68,7 +68,7 @@ 'help_text' => '', 'extra_attributes' => [ 'section' => SettingsManager::EVENT_INFO, - 'parent_setting' => 'eventsextras_include_map_event_location', + 'parent_setting' => SettingsManager::SETTING_FIELDS['INCLUDE_MAP_LOCATION_EVENT'], 'event_form_element_name' => 'is_map', 'class' => '', ], @@ -87,7 +87,7 @@ 'help_text' => '', 'extra_attributes' => [ 'section' => SettingsManager::EVENT_INFO, - 'parent_setting' => 'eventsextras_public_event', + 'parent_setting' => SettingsManager::SETTING_FIELDS['INCLUDE_MAP_PUBLIC_EVENT'], 'event_form_element_name' => 'is_public', 'class' => '', ], @@ -110,7 +110,7 @@ 'help_text' => '', 'extra_attributes' => [ 'section' => SettingsManager::EVENT_FEE, - 'parent_setting' => 'eventsextras_currency', + 'parent_setting' => SettingsManager::SETTING_FIELDS['CURRENCY'], 'event_form_element_name' => 'currency', 'class' => 'crm-select2', 'placeholder' => ts('--Select--'), @@ -140,7 +140,7 @@ 'help_text' => '', 'extra_attributes' => [ 'section' => SettingsManager::EVENT_FEE, - 'parent_setting' => 'eventsextras_payment_processor_selection', + 'parent_setting' => SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION'], 'event_form_element_name' => 'payment_processor', 'class' => '', ], @@ -159,7 +159,7 @@ 'help_text' => '', 'extra_attributes' => [ 'section' => SettingsManager::EVENT_FEE, - 'parent_setting' => 'eventsextras_enable_pay_later_option', + 'parent_setting' => SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION'], 'event_form_element_name' => 'is_pay_later', 'class' => '', ], @@ -178,7 +178,7 @@ 'help_text' => '', 'extra_attributes' => [ 'section' => SettingsManager::EVENT_FEE, - 'parent_setting' => 'eventsextras_enable_pay_later_option', + 'parent_setting' => SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION'], 'event_form_element_name' => 'pay_later_text', 'class' => '', ], @@ -197,7 +197,7 @@ 'help_text' => '', 'extra_attributes' => [ 'section' => SettingsManager::EVENT_FEE, - 'parent_setting' => 'eventsextras_enable_pay_later_option', + 'parent_setting' => SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION'], 'event_form_element_name' => 'pay_later_receipt', 'class' => '', ], @@ -216,7 +216,7 @@ 'help_text' => '', 'extra_attributes' => [ 'section' => SettingsManager::EVENT_FEE, - 'parent_setting' => 'eventsextras_enable_pay_later_option', + 'parent_setting' => SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION'], 'event_form_element_name' => 'is_billing_required', 'class' => '', ], @@ -236,7 +236,7 @@ 'help_text' => '', 'extra_attributes' => [ 'section' => SettingsManager::EVENT_REGISTRATION, - 'parent_setting' => 'eventsextras_pending_participant_expiration', + 'parent_setting' => SettingsManager::SETTING_FIELDS['PENDING_PARTICIPANT_EXPIRATION'], 'event_form_element_name' => 'expiration_time', 'class' => '', ], @@ -257,7 +257,7 @@ 'help_text' => '', 'extra_attributes' => [ 'section' => SettingsManager::EVENT_REGISTRATION, - 'parent_setting' => 'eventsextras_allow_self_service', + 'parent_setting' => SettingsManager::SETTING_FIELDS['ALLOW_SELF_SERIVCE'], 'event_form_element_name' => 'allow_selfcancelxfer', ], ], @@ -276,7 +276,7 @@ 'help_text' => '', 'extra_attributes' => [ 'section' => SettingsManager::EVENT_REGISTRATION, - 'parent_setting' => 'eventsextras_allow_self_service', + 'parent_setting' => SettingsManager::SETTING_FIELDS['ALLOW_SELF_SERIVCE'], 'event_form_element_name' => 'selfcancelxfer_time', ], ], @@ -295,12 +295,12 @@ 'help_text' => '', 'extra_attributes' => [ 'section' => SettingsManager::EVENT_REGISTRATION, - 'parent_setting' => 'eventsextras_register_multiple_participants', + 'parent_setting' => SettingsManager::SETTING_FIELDS['REGISTER_MULTIPLE_PARTICIPANTS'], 'event_form_element_name' => 'is_multiple_registrations', ], ], -'eventsextras_register_multiple_participants_default_maxinum_participant' => [ - 'name' => 'eventsextras_register_multiple_participants_default_maxinum_participant', +'eventsextras_register_multiple_participants_default_maximum_participant' => [ + 'name' => 'eventsextras_register_multiple_participants_default_maximum_participant', 'title' => ts('Set Default Maximum additional participants '), 'type' => 'Integer', 'quick_form_type' => 'Select', @@ -314,7 +314,7 @@ 'help_text' => '', 'extra_attributes' => [ 'section' => SettingsManager::EVENT_REGISTRATION, - 'parent_setting' => 'eventsextras_register_multiple_participants', + 'parent_setting' => SettingsManager::SETTING_FIELDS['REGISTER_MULTIPLE_PARTICIPANTS'], 'event_form_element_name' => 'max_additional_participants', ], ], From 37de2827740c652ff5b2c3d38989cf1c1af75e4d Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Thu, 4 Jul 2019 18:04:58 +0100 Subject: [PATCH 61/97] RSE-210: Change class name for better understanding --- CRM/EventsExtras/Hook/Pre/{Event.php => ManageEvent.php} | 0 eventsextras.php | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename CRM/EventsExtras/Hook/Pre/{Event.php => ManageEvent.php} (100%) diff --git a/CRM/EventsExtras/Hook/Pre/Event.php b/CRM/EventsExtras/Hook/Pre/ManageEvent.php similarity index 100% rename from CRM/EventsExtras/Hook/Pre/Event.php rename to CRM/EventsExtras/Hook/Pre/ManageEvent.php diff --git a/eventsextras.php b/eventsextras.php index c6c643d..1577a88 100644 --- a/eventsextras.php +++ b/eventsextras.php @@ -26,7 +26,7 @@ function eventsextras_civicrm_buildForm($formName, &$form){ */ function eventsextras_civicrm_pre($op, $objectName, $id, &$params){ $listeners = [ - new CRM_EventsExtras_Hook_Pre_Event(), + new CRM_EventsExtras_Hook_Pre_ManageEvent(), ]; foreach ($listeners as $currentListener) { $currentListener->handle($op, $objectName, $id, $params); From 6347c42f50d5202a8ba71ae586bb693fddf4a480 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Thu, 4 Jul 2019 18:06:52 +0100 Subject: [PATCH 62/97] RSE-210: Added comment --- CRM/EventsExtras/Form/Settings.php | 10 ++++++++++ CRM/EventsExtras/Hook/BuildForm/EventInfo.php | 2 ++ 2 files changed, 12 insertions(+) diff --git a/CRM/EventsExtras/Form/Settings.php b/CRM/EventsExtras/Form/Settings.php index 2a0b0e9..177eee1 100644 --- a/CRM/EventsExtras/Form/Settings.php +++ b/CRM/EventsExtras/Form/Settings.php @@ -127,6 +127,11 @@ public function postProcess() { } } + /** + * Add html element to the form for parent default setting. + * + * @param array $config + */ private function addParentElement($config){ if ($config['html_type'] == 'select') { $this->generateDefaultSelectList($config); @@ -137,6 +142,11 @@ private function addParentElement($config){ $this->defaultSettingsHelp[$config['name']] = $config['is_help']; } + /** + * Add html element to the form for child a default (global) setting. + * + * @param array $config + */ private function addChildElement($name, $config){ $this->addRadio( $name, diff --git a/CRM/EventsExtras/Hook/BuildForm/EventInfo.php b/CRM/EventsExtras/Hook/BuildForm/EventInfo.php index 8e809d7..7525b9e 100644 --- a/CRM/EventsExtras/Hook/BuildForm/EventInfo.php +++ b/CRM/EventsExtras/Hook/BuildForm/EventInfo.php @@ -36,6 +36,8 @@ private function buildForm($formName, &$form) { /** * Set defaults for form. * + * @param array $form + * */ private function setDefaults(&$form){ $defaults = []; From 43c094b979e0fed52b98ac8b38a71b16a6f49c2a Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Wed, 3 Jul 2019 13:48:20 +0100 Subject: [PATCH 63/97] RSE-211: Added Upgrader and SQL script to remove Events Extras settings when uninstall the extension --- CRM/EventsExtras/Upgrader.php | 16 ++ CRM/EventsExtras/Upgrader/Base.php | 376 +++++++++++++++++++++++++++++ eventsextras.civix.php | 2 +- sql/auto_uninstall.sql | 6 + 4 files changed, 399 insertions(+), 1 deletion(-) create mode 100644 CRM/EventsExtras/Upgrader.php create mode 100644 CRM/EventsExtras/Upgrader/Base.php create mode 100644 sql/auto_uninstall.sql diff --git a/CRM/EventsExtras/Upgrader.php b/CRM/EventsExtras/Upgrader.php new file mode 100644 index 0000000..69a00e4 --- /dev/null +++ b/CRM/EventsExtras/Upgrader.php @@ -0,0 +1,16 @@ +executeSqlFile('sql/auto_uninstall.sql'); + } + +} diff --git a/CRM/EventsExtras/Upgrader/Base.php b/CRM/EventsExtras/Upgrader/Base.php new file mode 100644 index 0000000..6e508a1 --- /dev/null +++ b/CRM/EventsExtras/Upgrader/Base.php @@ -0,0 +1,376 @@ +ctx = array_shift($args); + $instance->queue = $instance->ctx->queue; + $method = array_shift($args); + return call_user_func_array(array($instance, $method), $args); + } + + public function __construct($extensionName, $extensionDir) { + $this->extensionName = $extensionName; + $this->extensionDir = $extensionDir; + } + + // ******** Task helpers ******** + + /** + * Run a CustomData file. + * + * @param string $relativePath the CustomData XML file path (relative to this extension's dir) + * @return bool + */ + public function executeCustomDataFile($relativePath) { + $xml_file = $this->extensionDir . '/' . $relativePath; + return $this->executeCustomDataFileByAbsPath($xml_file); + } + + /** + * Run a CustomData file + * + * @param string $xml_file the CustomData XML file path (absolute path) + * + * @return bool + */ + protected static function executeCustomDataFileByAbsPath($xml_file) { + $import = new CRM_Utils_Migrate_Import(); + $import->run($xml_file); + return TRUE; + } + + /** + * Run a SQL file. + * + * @param string $relativePath the SQL file path (relative to this extension's dir) + * + * @return bool + */ + public function executeSqlFile($relativePath) { + CRM_Utils_File::sourceSQLFile( + CIVICRM_DSN, + $this->extensionDir . DIRECTORY_SEPARATOR . $relativePath + ); + return TRUE; + } + + /** + * @param string $tplFile + * The SQL file path (relative to this extension's dir). + * Ex: "sql/mydata.mysql.tpl". + * @return bool + */ + public function executeSqlTemplate($tplFile) { + // Assign multilingual variable to Smarty. + $upgrade = new CRM_Upgrade_Form(); + + $tplFile = CRM_Utils_File::isAbsolute($tplFile) ? $tplFile : $this->extensionDir . DIRECTORY_SEPARATOR . $tplFile; + $smarty = CRM_Core_Smarty::singleton(); + $smarty->assign('domainID', CRM_Core_Config::domainID()); + CRM_Utils_File::sourceSQLFile( + CIVICRM_DSN, $smarty->fetch($tplFile), NULL, TRUE + ); + return TRUE; + } + + /** + * Run one SQL query. + * + * This is just a wrapper for CRM_Core_DAO::executeSql, but it + * provides syntatic sugar for queueing several tasks that + * run different queries + */ + public function executeSql($query, $params = array()) { + // FIXME verify that we raise an exception on error + CRM_Core_DAO::executeQuery($query, $params); + return TRUE; + } + + /** + * Syntatic sugar for enqueuing a task which calls a function in this class. + * + * The task is weighted so that it is processed + * as part of the currently-pending revision. + * + * After passing the $funcName, you can also pass parameters that will go to + * the function. Note that all params must be serializable. + */ + public function addTask($title) { + $args = func_get_args(); + $title = array_shift($args); + $task = new CRM_Queue_Task( + array(get_class($this), '_queueAdapter'), + $args, + $title + ); + return $this->queue->createItem($task, array('weight' => -1)); + } + + // ******** Revision-tracking helpers ******** + + /** + * Determine if there are any pending revisions. + * + * @return bool + */ + public function hasPendingRevisions() { + $revisions = $this->getRevisions(); + $currentRevision = $this->getCurrentRevision(); + + if (empty($revisions)) { + return FALSE; + } + if (empty($currentRevision)) { + return TRUE; + } + + return ($currentRevision < max($revisions)); + } + + /** + * Add any pending revisions to the queue. + */ + public function enqueuePendingRevisions(CRM_Queue_Queue $queue) { + $this->queue = $queue; + + $currentRevision = $this->getCurrentRevision(); + foreach ($this->getRevisions() as $revision) { + if ($revision > $currentRevision) { + $title = ts('Upgrade %1 to revision %2', array( + 1 => $this->extensionName, + 2 => $revision, + )); + + // note: don't use addTask() because it sets weight=-1 + + $task = new CRM_Queue_Task( + array(get_class($this), '_queueAdapter'), + array('upgrade_' . $revision), + $title + ); + $this->queue->createItem($task); + + $task = new CRM_Queue_Task( + array(get_class($this), '_queueAdapter'), + array('setCurrentRevision', $revision), + $title + ); + $this->queue->createItem($task); + } + } + } + + /** + * Get a list of revisions. + * + * @return array(revisionNumbers) sorted numerically + */ + public function getRevisions() { + if (!is_array($this->revisions)) { + $this->revisions = array(); + + $clazz = new ReflectionClass(get_class($this)); + $methods = $clazz->getMethods(); + foreach ($methods as $method) { + if (preg_match('/^upgrade_(.*)/', $method->name, $matches)) { + $this->revisions[] = $matches[1]; + } + } + sort($this->revisions, SORT_NUMERIC); + } + + return $this->revisions; + } + + public function getCurrentRevision() { + $revision = CRM_Core_BAO_Extension::getSchemaVersion($this->extensionName); + if (!$revision) { + $revision = $this->getCurrentRevisionDeprecated(); + } + return $revision; + } + + private function getCurrentRevisionDeprecated() { + $key = $this->extensionName . ':version'; + if ($revision = CRM_Core_BAO_Setting::getItem('Extension', $key)) { + $this->revisionStorageIsDeprecated = TRUE; + } + return $revision; + } + + public function setCurrentRevision($revision) { + CRM_Core_BAO_Extension::setSchemaVersion($this->extensionName, $revision); + // clean up legacy schema version store (CRM-19252) + $this->deleteDeprecatedRevision(); + return TRUE; + } + + private function deleteDeprecatedRevision() { + if ($this->revisionStorageIsDeprecated) { + $setting = new CRM_Core_BAO_Setting(); + $setting->name = $this->extensionName . ':version'; + $setting->delete(); + CRM_Core_Error::debug_log_message("Migrated extension schema revision ID for {$this->extensionName} from civicrm_setting (deprecated) to civicrm_extension.\n"); + } + } + + // ******** Hook delegates ******** + + /** + * @see https://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_install + */ + public function onInstall() { + $files = glob($this->extensionDir . '/sql/*_install.sql'); + if (is_array($files)) { + foreach ($files as $file) { + CRM_Utils_File::sourceSQLFile(CIVICRM_DSN, $file); + } + } + $files = glob($this->extensionDir . '/sql/*_install.mysql.tpl'); + if (is_array($files)) { + foreach ($files as $file) { + $this->executeSqlTemplate($file); + } + } + $files = glob($this->extensionDir . '/xml/*_install.xml'); + if (is_array($files)) { + foreach ($files as $file) { + $this->executeCustomDataFileByAbsPath($file); + } + } + if (is_callable(array($this, 'install'))) { + $this->install(); + } + } + + /** + * @see https://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_postInstall + */ + public function onPostInstall() { + $revisions = $this->getRevisions(); + if (!empty($revisions)) { + $this->setCurrentRevision(max($revisions)); + } + if (is_callable(array($this, 'postInstall'))) { + $this->postInstall(); + } + } + + /** + * @see https://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_uninstall + */ + public function onUninstall() { + $files = glob($this->extensionDir . '/sql/*_uninstall.mysql.tpl'); + if (is_array($files)) { + foreach ($files as $file) { + $this->executeSqlTemplate($file); + } + } + if (is_callable(array($this, 'uninstall'))) { + $this->uninstall(); + } + $files = glob($this->extensionDir . '/sql/*_uninstall.sql'); + if (is_array($files)) { + foreach ($files as $file) { + CRM_Utils_File::sourceSQLFile(CIVICRM_DSN, $file); + } + } + } + + /** + * @see https://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_enable + */ + public function onEnable() { + // stub for possible future use + if (is_callable(array($this, 'enable'))) { + $this->enable(); + } + } + + /** + * @see https://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_disable + */ + public function onDisable() { + // stub for possible future use + if (is_callable(array($this, 'disable'))) { + $this->disable(); + } + } + + public function onUpgrade($op, CRM_Queue_Queue $queue = NULL) { + switch ($op) { + case 'check': + return array($this->hasPendingRevisions()); + + case 'enqueue': + return $this->enqueuePendingRevisions($queue); + + default: + } + } + +} diff --git a/eventsextras.civix.php b/eventsextras.civix.php index 07ff10a..e9857ed 100644 --- a/eventsextras.civix.php +++ b/eventsextras.civix.php @@ -208,7 +208,7 @@ function _eventsextras_civix_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) * @return CRM_EventsExtras_Upgrader */ function _eventsextras_civix_upgrader() { - if (!file_exists(__DIR__ . '/CRM/Eventsextras/Upgrader.php')) { + if (!file_exists(__DIR__ . '/CRM/EventsExtras/Upgrader.php')) { return NULL; } else { diff --git a/sql/auto_uninstall.sql b/sql/auto_uninstall.sql new file mode 100644 index 0000000..4628a37 --- /dev/null +++ b/sql/auto_uninstall.sql @@ -0,0 +1,6 @@ +-- /******************************************************* +-- * Delete evens extras settings +-- *******************************************************/ + + +DELETE FROM civicrm_setting WHERE `name` LIKE 'eventsextras_%'; From fa52ee1ea382a1058eb2526c95be8074a1ec78f7 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Wed, 3 Jul 2019 13:58:30 +0100 Subject: [PATCH 64/97] RSE-211: Fixed typo on help text --- sql/auto_uninstall.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/auto_uninstall.sql b/sql/auto_uninstall.sql index 4628a37..365d0d8 100644 --- a/sql/auto_uninstall.sql +++ b/sql/auto_uninstall.sql @@ -1,5 +1,5 @@ -- /******************************************************* --- * Delete evens extras settings +-- * Delete event extras settings -- *******************************************************/ From 8b8e8c5d407e83e338391b13f84a311450da09ae Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Tue, 13 Aug 2019 11:33:45 +0100 Subject: [PATCH 65/97] RSE-247: Correct class name --- CRM/EventsExtras/Hook/Pre/ManageEvent.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CRM/EventsExtras/Hook/Pre/ManageEvent.php b/CRM/EventsExtras/Hook/Pre/ManageEvent.php index 8eef68b..173c73c 100644 --- a/CRM/EventsExtras/Hook/Pre/ManageEvent.php +++ b/CRM/EventsExtras/Hook/Pre/ManageEvent.php @@ -3,9 +3,9 @@ use CRM_EventsExtras_SettingsManager as SettingsManager; /** - * Class for Event Fee Pre Hook + * Class for for Pre Manage Event Hook */ -class CRM_EventsExtras_Hook_Pre_Event { +class CRM_EventsExtras_Hook_Pre_ManageEvent { /** * Handle Hook Pre Event From aa53d45c01797a199d041507bd419dd5aa30b708 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Tue, 13 Aug 2019 14:47:02 +0100 Subject: [PATCH 66/97] RSE-246: Added Enable and Disable Tab functionality --- CRM/EventsExtras/Form/Settings.php | 7 ++- CRM/EventsExtras/Hook/BuildForm/TabHeader.php | 52 +++++++++++++++++++ CRM/EventsExtras/Hook/Pre/ManageEvent.php | 2 +- CRM/EventsExtras/SettingsManager.php | 4 ++ eventsextras.php | 16 ++++++ settings/EventsExtras.setting.php | 51 ++++++++++++++++++ 6 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 CRM/EventsExtras/Hook/BuildForm/TabHeader.php diff --git a/CRM/EventsExtras/Form/Settings.php b/CRM/EventsExtras/Form/Settings.php index 177eee1..beb531f 100644 --- a/CRM/EventsExtras/Form/Settings.php +++ b/CRM/EventsExtras/Form/Settings.php @@ -17,7 +17,8 @@ class CRM_EventsExtras_Form_Settings extends CRM_Core_Form { * @var array[] */ private $displaySections = [ - SettingsManager::EVENT_INFO => ['title' => 'Event Info Settings'], + SettingsManager::EVENT_TAB=> ['title' => 'Tab Settings'], + SettingsManager::EVENT_INFO => ['title' => 'Info Settings'], SettingsManager::EVENT_FEE => ['title' => 'Fee Settings'], SettingsManager::EVENT_REGISTRATION => ['title' => 'Online Registration Settings'], ]; @@ -246,6 +247,10 @@ public function setDefaultValues() { */ private function assignConfigSections($name, $section) { switch ($section) { + case SettingsManager::EVENT_TAB: + $this->displaySections[SettingsManager::EVENT_TAB]['fields'][$name] = $name; + break; + case SettingsManager::EVENT_INFO: $this->displaySections[SettingsManager::EVENT_INFO]['fields'][$name] = $name; break; diff --git a/CRM/EventsExtras/Hook/BuildForm/TabHeader.php b/CRM/EventsExtras/Hook/BuildForm/TabHeader.php new file mode 100644 index 0000000..9ff508d --- /dev/null +++ b/CRM/EventsExtras/Hook/BuildForm/TabHeader.php @@ -0,0 +1,52 @@ +shouldHandle($formName, $form)) { + return; + } + $this->hideTab($form); + } + + /** + * Checks if the hook should be handled. + * + * @param string $formName + * @param object $form + * + * @return bool + */ + protected function shouldHandle($formName, &$form) { + if ($form instanceof CRM_Event_Form_ManageEvent) { + return TRUE; + } + return FALSE; + + } + + private function hideTab(&$form){ + $vars = $form->get_template_vars('tabHeader'); + if (SettingsManager::getSettingValue(SettingsManager::SETTING_FIELDS['LOCATION_TAB']) == TRUE){ + unset($vars['location']); + } + if (SettingsManager::getSettingValue(SettingsManager::SETTING_FIELDS['TELL_FRIEND_TAB']) == TRUE){ + unset($vars['friend']); + } + if (SettingsManager::getSettingValue(SettingsManager::SETTING_FIELDS['PCP_TAB']) == TRUE){ + unset($vars['pcp']); + } + $form->assign_by_ref('tabHeader', $vars); + } +} diff --git a/CRM/EventsExtras/Hook/Pre/ManageEvent.php b/CRM/EventsExtras/Hook/Pre/ManageEvent.php index 173c73c..8c3446d 100644 --- a/CRM/EventsExtras/Hook/Pre/ManageEvent.php +++ b/CRM/EventsExtras/Hook/Pre/ManageEvent.php @@ -3,7 +3,7 @@ use CRM_EventsExtras_SettingsManager as SettingsManager; /** - * Class for for Pre Manage Event Hook + * Class for for Pre Hook */ class CRM_EventsExtras_Hook_Pre_ManageEvent { diff --git a/CRM/EventsExtras/SettingsManager.php b/CRM/EventsExtras/SettingsManager.php index ddec34b..0f6f1ee 100644 --- a/CRM/EventsExtras/SettingsManager.php +++ b/CRM/EventsExtras/SettingsManager.php @@ -8,12 +8,16 @@ class CRM_EventsExtras_SettingsManager { /** * Constants for setting sections */ + const EVENT_TAB = 'event_tab'; const EVENT_INFO = 'event_info'; const EVENT_FEE = 'event_fee'; const EVENT_REGISTRATION = 'event_online_registration'; const SETTING_FIELDS = [ + 'LOCATION_TAB' => 'eventsextras_location_tab', + 'TELL_FRIEND_TAB' => 'eventsextras_tell_friend_tab', + 'PCP_TAB' => 'eventsextras_pcp_tab', 'ROLES' => 'eventsextras_roles', 'ROLES_DEFAULT' => 'eventsextras_roles_default', 'PARTICIPANT_LISTING' => 'eventsextras_participant_listing', diff --git a/eventsextras.php b/eventsextras.php index 1577a88..db78437 100644 --- a/eventsextras.php +++ b/eventsextras.php @@ -10,6 +10,7 @@ */ function eventsextras_civicrm_buildForm($formName, &$form){ $listeners = [ + new CRM_EventsExtras_Hook_BuildForm_TabHeader(), new CRM_EventsExtras_Hook_BuildForm_EventInfo(), new CRM_EventsExtras_Hook_BuildForm_EventFee(), new CRM_EventsExtras_Hook_BuildForm_EventRegistration(), @@ -33,6 +34,21 @@ function eventsextras_civicrm_pre($op, $objectName, $id, &$params){ } } +/** + * Implements hook_civicrm_pre(). + * + * @link hhttps://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_tab/ + */ +function eventsextras_civicrm_tab(&$tabs, $contactID) { + /*$listeners = [ + new CRM_EventsExtras_Hook_Pre_ManageEvent(), + ]; + foreach ($listeners as $currentListener) { + $currentListener->handle((&$tabs, $contactID); + }*/ + +} + /** * Implements hook_civicrm_config(). * diff --git a/settings/EventsExtras.setting.php b/settings/EventsExtras.setting.php index f2a85d4..77d5295 100644 --- a/settings/EventsExtras.setting.php +++ b/settings/EventsExtras.setting.php @@ -5,6 +5,57 @@ * Settings metadata file */ return [ + 'eventsextras_location_tab' => [ + 'name' => 'eventsextras_location_tab', + 'title' => ts('Location Tab'), + 'type' => 'Boolean', + 'quick_form_type' => 'YesNo', + 'default' => TRUE, + 'html_type' => 'radio', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('Show/Hide Location Tab'), + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_TAB, + 'css_class' => '', + ], + ], + 'eventsextras_tell_friend_tab' => [ + 'name' => 'eventsextras_tell_friend_tab', + 'title' => ts('Tell Friend Tab'), + 'type' => 'Boolean', + 'quick_form_type' => 'YesNo', + 'default' => TRUE, + 'html_type' => 'radio', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('Show/Hide Tell Friend Tab'), + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_TAB, + 'css_class' => '', + ], + ], + 'eventsextras_pcp_tab' => [ + 'name' => 'eventsextras_pcp_tab', + 'title' => ts('Personal Compaings Tab'), + 'type' => 'Boolean', + 'quick_form_type' => 'YesNo', + 'default' => TRUE, + 'html_type' => 'radio', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('Show/Hide Personal Campaigns Tab'), + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_TAB, + 'css_class' => '', + ], + ], 'eventsextras_roles' => [ 'name' => 'eventsextras_roles', 'title' => ts('Default Role'), From 7be38417eee768db2c875bb8fd3f167c2c5113c2 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Tue, 13 Aug 2019 15:01:54 +0100 Subject: [PATCH 67/97] RSE-246: Fix comparing value instead of array --- CRM/EventsExtras/Hook/BuildForm/TabHeader.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/CRM/EventsExtras/Hook/BuildForm/TabHeader.php b/CRM/EventsExtras/Hook/BuildForm/TabHeader.php index 9ff508d..43f2c21 100644 --- a/CRM/EventsExtras/Hook/BuildForm/TabHeader.php +++ b/CRM/EventsExtras/Hook/BuildForm/TabHeader.php @@ -38,13 +38,17 @@ protected function shouldHandle($formName, &$form) { private function hideTab(&$form){ $vars = $form->get_template_vars('tabHeader'); - if (SettingsManager::getSettingValue(SettingsManager::SETTING_FIELDS['LOCATION_TAB']) == TRUE){ + + $locationTabSetting = SettingsManager::getSettingValue(SettingsManager::SETTING_FIELDS['LOCATION_TAB']); + $tellFriendTabSetting = SettingsManager::getSettingValue(SettingsManager::SETTING_FIELDS['TELL_FRIEND_TAB']); + $pcpTabSetting = SettingsManager::getSettingValue(SettingsManager::SETTING_FIELDS['PCP_TAB']); + if (reset($locationTabSetting) == 0){ unset($vars['location']); } - if (SettingsManager::getSettingValue(SettingsManager::SETTING_FIELDS['TELL_FRIEND_TAB']) == TRUE){ + if (reset($tellFriendTabSetting) == 0){ unset($vars['friend']); } - if (SettingsManager::getSettingValue(SettingsManager::SETTING_FIELDS['PCP_TAB']) == TRUE){ + if (reset($pcpTabSetting) == 0){ unset($vars['pcp']); } $form->assign_by_ref('tabHeader', $vars); From d45daebe988d6ca81efa513eeae924cf5cb1c773 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Tue, 13 Aug 2019 15:02:24 +0100 Subject: [PATCH 68/97] RSE-246: clean up space --- CRM/EventsExtras/Hook/BuildForm/TabHeader.php | 1 - 1 file changed, 1 deletion(-) diff --git a/CRM/EventsExtras/Hook/BuildForm/TabHeader.php b/CRM/EventsExtras/Hook/BuildForm/TabHeader.php index 43f2c21..acaae7f 100644 --- a/CRM/EventsExtras/Hook/BuildForm/TabHeader.php +++ b/CRM/EventsExtras/Hook/BuildForm/TabHeader.php @@ -38,7 +38,6 @@ protected function shouldHandle($formName, &$form) { private function hideTab(&$form){ $vars = $form->get_template_vars('tabHeader'); - $locationTabSetting = SettingsManager::getSettingValue(SettingsManager::SETTING_FIELDS['LOCATION_TAB']); $tellFriendTabSetting = SettingsManager::getSettingValue(SettingsManager::SETTING_FIELDS['TELL_FRIEND_TAB']); $pcpTabSetting = SettingsManager::getSettingValue(SettingsManager::SETTING_FIELDS['PCP_TAB']); From 9848dba4bff7453fe5709448890fab0387253dab Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Tue, 13 Aug 2019 15:05:20 +0100 Subject: [PATCH 69/97] RSE-246: clean up code --- CRM/EventsExtras/Hook/BuildForm/TabHeader.php | 1 - 1 file changed, 1 deletion(-) diff --git a/CRM/EventsExtras/Hook/BuildForm/TabHeader.php b/CRM/EventsExtras/Hook/BuildForm/TabHeader.php index acaae7f..bc7848b 100644 --- a/CRM/EventsExtras/Hook/BuildForm/TabHeader.php +++ b/CRM/EventsExtras/Hook/BuildForm/TabHeader.php @@ -33,7 +33,6 @@ protected function shouldHandle($formName, &$form) { return TRUE; } return FALSE; - } private function hideTab(&$form){ From 59471684aa43e29784d35f90bddb6314dca8ed41 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Tue, 13 Aug 2019 17:22:34 +0100 Subject: [PATCH 70/97] RSE-246: Change TabHeader class and fixed as per comment on PR --- .../Hook/BuildForm/EventTabHeader.php | 62 +++++++++++++++++++ CRM/EventsExtras/Hook/BuildForm/TabHeader.php | 54 ---------------- eventsextras.php | 2 +- 3 files changed, 63 insertions(+), 55 deletions(-) create mode 100644 CRM/EventsExtras/Hook/BuildForm/EventTabHeader.php delete mode 100644 CRM/EventsExtras/Hook/BuildForm/TabHeader.php diff --git a/CRM/EventsExtras/Hook/BuildForm/EventTabHeader.php b/CRM/EventsExtras/Hook/BuildForm/EventTabHeader.php new file mode 100644 index 0000000..c84ad7d --- /dev/null +++ b/CRM/EventsExtras/Hook/BuildForm/EventTabHeader.php @@ -0,0 +1,62 @@ +shouldHandle($formName, $form)) { + return; + } + $this->hideTab($form); + } + + /** + * Checks if the hook should be handled. + * + * @param string $formName + * @param object $form + * + * @return bool + */ + protected function shouldHandle($formName, &$form) { + if ($form instanceof CRM_Event_Form_ManageEvent) { + + return TRUE; + } + return FALSE; + } + + private function hideTab(&$form){ + $vars = $form->get_template_vars('tabHeader'); + $locationTabSetting = SettingsManager::SETTING_FIELDS['LOCATION_TAB']; + $pcpTabSetting = SettingsManager::SETTING_FIELDS['PCP_TAB']; + $tellFriendTabSetting = SettingsManager::SETTING_FIELDS['TELL_FRIEND_TAB']; + $settingsValue = SettingsManager::getSettingsValue([ + $locationTabSetting, + $pcpTabSetting, + $tellFriendTabSetting + ]); + foreach ($settingsValue as $setting => $value){ + if ($setting == $locationTabSetting && $value == 0){ + set($vars['location']); + } + if ($setting == $tellFriendTabSetting && $value == 0){ + unset($vars['friend']); + } + if ($setting == $pcpTabSetting && $value == 0){ + unset($vars['pcp']); + } + } + $form->assign_by_ref('tabHeader', $vars); + } +} diff --git a/CRM/EventsExtras/Hook/BuildForm/TabHeader.php b/CRM/EventsExtras/Hook/BuildForm/TabHeader.php deleted file mode 100644 index bc7848b..0000000 --- a/CRM/EventsExtras/Hook/BuildForm/TabHeader.php +++ /dev/null @@ -1,54 +0,0 @@ -shouldHandle($formName, $form)) { - return; - } - $this->hideTab($form); - } - - /** - * Checks if the hook should be handled. - * - * @param string $formName - * @param object $form - * - * @return bool - */ - protected function shouldHandle($formName, &$form) { - if ($form instanceof CRM_Event_Form_ManageEvent) { - return TRUE; - } - return FALSE; - } - - private function hideTab(&$form){ - $vars = $form->get_template_vars('tabHeader'); - $locationTabSetting = SettingsManager::getSettingValue(SettingsManager::SETTING_FIELDS['LOCATION_TAB']); - $tellFriendTabSetting = SettingsManager::getSettingValue(SettingsManager::SETTING_FIELDS['TELL_FRIEND_TAB']); - $pcpTabSetting = SettingsManager::getSettingValue(SettingsManager::SETTING_FIELDS['PCP_TAB']); - if (reset($locationTabSetting) == 0){ - unset($vars['location']); - } - if (reset($tellFriendTabSetting) == 0){ - unset($vars['friend']); - } - if (reset($pcpTabSetting) == 0){ - unset($vars['pcp']); - } - $form->assign_by_ref('tabHeader', $vars); - } -} diff --git a/eventsextras.php b/eventsextras.php index db78437..9ce9908 100644 --- a/eventsextras.php +++ b/eventsextras.php @@ -10,7 +10,7 @@ */ function eventsextras_civicrm_buildForm($formName, &$form){ $listeners = [ - new CRM_EventsExtras_Hook_BuildForm_TabHeader(), + new CRM_EventsExtras_Hook_BuildForm_EventTabHeader(), new CRM_EventsExtras_Hook_BuildForm_EventInfo(), new CRM_EventsExtras_Hook_BuildForm_EventFee(), new CRM_EventsExtras_Hook_BuildForm_EventRegistration(), From edfbcc0e9670c94b0177dd6c9ec98a950af2e666 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Wed, 21 Aug 2019 15:53:58 +0100 Subject: [PATCH 71/97] RSE-246: Fixed code to follow standard --- .../Hook/BuildForm/EventTabHeader.php | 16 +++++++++++----- eventsextras.php | 10 ++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/CRM/EventsExtras/Hook/BuildForm/EventTabHeader.php b/CRM/EventsExtras/Hook/BuildForm/EventTabHeader.php index c84ad7d..2519033 100644 --- a/CRM/EventsExtras/Hook/BuildForm/EventTabHeader.php +++ b/CRM/EventsExtras/Hook/BuildForm/EventTabHeader.php @@ -30,17 +30,23 @@ public function handle($formName, &$form) { */ protected function shouldHandle($formName, &$form) { if ($form instanceof CRM_Event_Form_ManageEvent) { - return TRUE; } + return FALSE; } + /** + * This function is to hide Event tabs based on settings. + * + * @param object $form + * + */ private function hideTab(&$form){ $vars = $form->get_template_vars('tabHeader'); - $locationTabSetting = SettingsManager::SETTING_FIELDS['LOCATION_TAB']; - $pcpTabSetting = SettingsManager::SETTING_FIELDS['PCP_TAB']; - $tellFriendTabSetting = SettingsManager::SETTING_FIELDS['TELL_FRIEND_TAB']; + $locationTabSetting = SettingsManager::SETTING_FIELDS['LOCATION_TAB']; + $pcpTabSetting = SettingsManager::SETTING_FIELDS['PCP_TAB']; + $tellFriendTabSetting = SettingsManager::SETTING_FIELDS['TELL_FRIEND_TAB']; $settingsValue = SettingsManager::getSettingsValue([ $locationTabSetting, $pcpTabSetting, @@ -48,7 +54,7 @@ private function hideTab(&$form){ ]); foreach ($settingsValue as $setting => $value){ if ($setting == $locationTabSetting && $value == 0){ - set($vars['location']); + unset($vars['location']); } if ($setting == $tellFriendTabSetting && $value == 0){ unset($vars['friend']); diff --git a/eventsextras.php b/eventsextras.php index 9ce9908..b0abe75 100644 --- a/eventsextras.php +++ b/eventsextras.php @@ -3,6 +3,16 @@ require_once 'eventsextras.civix.php'; use CRM_EventsExtras_ExtensionUtil as E; +function eventsextra_civicrm_links($op, $objectName, $objectId, &$links, &$mask, &$values){ + CRM_Core_Error::debug($op); + CRM_Core_Error::debug($objectName); + CRM_Core_Error::debug($links); + + +} + + + /** * Implements hook_civicrm_buildForm(). * From dc380ffcfd302eadbe2b66275c8c4ae4f4fb7aee Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Wed, 21 Aug 2019 16:09:31 +0100 Subject: [PATCH 72/97] RSE-246: Removed tested links hook --- eventsextras.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/eventsextras.php b/eventsextras.php index b0abe75..9ce9908 100644 --- a/eventsextras.php +++ b/eventsextras.php @@ -3,16 +3,6 @@ require_once 'eventsextras.civix.php'; use CRM_EventsExtras_ExtensionUtil as E; -function eventsextra_civicrm_links($op, $objectName, $objectId, &$links, &$mask, &$values){ - CRM_Core_Error::debug($op); - CRM_Core_Error::debug($objectName); - CRM_Core_Error::debug($links); - - -} - - - /** * Implements hook_civicrm_buildForm(). * From 0db34bfc1afd5e119604b36177a4cb4bc646f05a Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Mon, 9 Sep 2019 14:57:45 +0100 Subject: [PATCH 73/97] RSE-142: Fixed typo in info.xml --- info.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/info.xml b/info.xml index c3d1ded..94c5b51 100644 --- a/info.xml +++ b/info.xml @@ -5,8 +5,8 @@ This extensions allows CiviCRM admin to config generic Event pages AGPL-3.0 - Compucropt Ltd. - hello@compucorp.co.ukk + Compucorp Ltd. + hello@compucorp.co.uk https://github.com/compucorp/uk.co.compucorp.eventsextras From 83f01387e442b4869baf6bbdbcf635cf619fc86d Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Mon, 9 Sep 2019 11:13:14 +0100 Subject: [PATCH 74/97] Revert "RSE-245: Moved Events Extras Settings Menu" --- eventsextras.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eventsextras.php b/eventsextras.php index 50c4c3f..4ef11ac 100644 --- a/eventsextras.php +++ b/eventsextras.php @@ -197,7 +197,7 @@ function eventsextras_civicrm_preProcess($formName, &$form) { * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_navigationMenu */ function eventsextras_civicrm_navigationMenu(&$menu) { - _eventsextras_civix_insert_navigation_menu($menu, 'Administer/CiviEvent', array( + _eventsextras_civix_insert_navigation_menu($menu, 'Administer/', array( 'label' => E::ts('Events Extras Settings'), 'name' => 'events_extras_settings', 'url' => 'civicrm/admin/setting/preferences/eventsextras', @@ -206,4 +206,4 @@ function eventsextras_civicrm_navigationMenu(&$menu) { 'separator' => 0, )); _eventsextras_civix_navigationMenu($menu); -} +} From cbb577c06f2b1c4160f5566453e3d7d032ac5a28 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Thu, 2 Jul 2020 12:12:49 +0100 Subject: [PATCH 75/97] MAE-326: Fix default payment process check box shows incorrect selection values --- CRM/EventsExtras/Form/Settings.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/CRM/EventsExtras/Form/Settings.php b/CRM/EventsExtras/Form/Settings.php index beb531f..1fe6490 100644 --- a/CRM/EventsExtras/Form/Settings.php +++ b/CRM/EventsExtras/Form/Settings.php @@ -101,16 +101,20 @@ public static function validateRules($values) { public function postProcess() { $configFields = SettingsManager::getConfigFields(); $submittedValues = $this->exportValues(); + $valuesToSave = []; if (isset($submittedValues[SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION_DEFAULT']])) { $paymentProcessors = $submittedValues[SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION_DEFAULT']]; + //flip selected default paymentProcessors before saving to setting $flipedPaymentProcessor = []; foreach ($paymentProcessors as $selectValue => $selected){ $flipedPaymentProcessor[] = $selectValue; } + $submittedValues[SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION_DEFAULT']] = $flipedPaymentProcessor; } + $valuesToSave = array_intersect_key($submittedValues, $configFields); //makesure uncheck checkecbox value is set to default into setting //when user select hide but did not select the default. @@ -164,7 +168,7 @@ private function generatePaymentProcessorField($setting){ E::ts($setting['title']), array_flip($paymentProcessor), NULL, NULL, NULL, NULL, - array('  ', '  ', '  ', '
') + ['  ', '  ', '  ', '
'] ); } @@ -236,6 +240,10 @@ public function setDefaultValues() { foreach ($currentValues['values'][$domainID] as $name => $value) { $defaults[$name] = $value; } + + $defaults['eventsextras_payment_processor_selection_default'] = + array_fill_keys($defaults['eventsextras_payment_processor_selection_default'], '1'); + return $defaults; } From 04e8d165f7331207dcbf5ee373f90c6b3b832404 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Thu, 2 Jul 2020 12:20:10 +0100 Subject: [PATCH 76/97] MAE-326: Add phpcs linter and phpcs rule set --- bin/install-php-linter | 22 ++++++++++++++++++++++ phpcs-ruleset.xml | 8 ++++++++ 2 files changed, 30 insertions(+) create mode 100644 bin/install-php-linter create mode 100644 phpcs-ruleset.xml diff --git a/bin/install-php-linter b/bin/install-php-linter new file mode 100644 index 0000000..7b6a5e2 --- /dev/null +++ b/bin/install-php-linter @@ -0,0 +1,22 @@ +#!/bin/bash +set -e + +# Download PHPCS if it already does not exist +if [ ! -f phpcs.phar ]; then + curl -OL https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar +fi +# Give executable permission to PHPCS +chmod +x phpcs.phar + +# Download PHPCBF if it already does not exist +if [ ! -f phpcbf.phar ]; then + curl -OL https://squizlabs.github.io/PHP_CodeSniffer/phpcbf.phar +fi + +# Give executable permission to PHPCBF +chmod +x phpcbf.phar + +# Clone CiviCRM Coder repo +if [ ! -d drupal/coder ]; then + git clone --depth 1 https://github.com/civicrm/coder.git civicrm/coder +fi diff --git a/phpcs-ruleset.xml b/phpcs-ruleset.xml new file mode 100644 index 0000000..69ffbe2 --- /dev/null +++ b/phpcs-ruleset.xml @@ -0,0 +1,8 @@ + + + CiviCRM Coder Ruleset + + tests/phpunit/bootstrap.php + eventsextras.civix.php + + From 97236598ba4a55358d019b231639e8340ad12194 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Thu, 2 Jul 2020 12:20:55 +0100 Subject: [PATCH 77/97] MAE-326: Add phpunit test skeleton --- phpunit.xml.dist | 27 +++++++++++++ tests/phpunit/BaseHeadlessTest.php | 21 ++++++++++ tests/phpunit/bootstrap.php | 65 ++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 phpunit.xml.dist create mode 100644 tests/phpunit/BaseHeadlessTest.php create mode 100644 tests/phpunit/bootstrap.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..7ec1d29 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,27 @@ + + + + + ./tests/phpunit + + + + + ./ + + + + + + + + diff --git a/tests/phpunit/BaseHeadlessTest.php b/tests/phpunit/BaseHeadlessTest.php new file mode 100644 index 0000000..4b8c39b --- /dev/null +++ b/tests/phpunit/BaseHeadlessTest.php @@ -0,0 +1,21 @@ +installMe(__DIR__) + ->apply(); + } + +} diff --git a/tests/phpunit/bootstrap.php b/tests/phpunit/bootstrap.php new file mode 100644 index 0000000..8abab97 --- /dev/null +++ b/tests/phpunit/bootstrap.php @@ -0,0 +1,65 @@ +apply(); +} + +/** + * Call the "cv" command. + * + * @param string $cmd + * The rest of the command to send. + * @param string $decode + * Ex: 'json' or 'phpcode'. + * + * @return string + * Response output (if the command executed normally). + * + * @throws \RuntimeException + * If the command terminates abnormally. + */ +function cv($cmd, $decode = 'json') { + $cmd = 'cv ' . $cmd; + $descriptorSpec = [0 => ["pipe", "r"], 1 => ["pipe", "w"], 2 => STDERR]; + $oldOutput = getenv('CV_OUTPUT'); + putenv("CV_OUTPUT=json"); + $process = proc_open($cmd, $descriptorSpec, $pipes, __DIR__); + putenv("CV_OUTPUT=$oldOutput"); + fclose($pipes[0]); + $result = stream_get_contents($pipes[1]); + fclose($pipes[1]); + if (proc_close($process) !== 0) { + throw new RuntimeException("Command failed ($cmd):\n$result"); + } + switch ($decode) { + case 'raw': + return $result; + + case 'phpcode': + // If the last output is /*PHPCODE*/ + // then we managed to complete execution. + if (substr(trim($result), 0, 12) !== "/*BEGINPHP*/" || substr(trim($result), -10) !== "/*ENDPHP*/") { + throw new \RuntimeException("Command failed ($cmd):\n$result"); + } + return $result; + + case 'json': + return json_decode($result, 1); + + default: + throw new RuntimeException("Bad decoder format ($decode)"); + } +} From 29b6b53e3a1417e5e6a7950a688e2803b91e68c3 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Thu, 2 Jul 2020 13:25:01 +0100 Subject: [PATCH 78/97] MAE-326: Fix smell code throwed by phpcs --- CRM/EventsExtras/Form/Settings.php | 92 ++++++++++++++++-------------- 1 file changed, 50 insertions(+), 42 deletions(-) diff --git a/CRM/EventsExtras/Form/Settings.php b/CRM/EventsExtras/Form/Settings.php index 1fe6490..489b29a 100644 --- a/CRM/EventsExtras/Form/Settings.php +++ b/CRM/EventsExtras/Form/Settings.php @@ -17,7 +17,7 @@ class CRM_EventsExtras_Form_Settings extends CRM_Core_Form { * @var array[] */ private $displaySections = [ - SettingsManager::EVENT_TAB=> ['title' => 'Tab Settings'], + SettingsManager::EVENT_TAB => ['title' => 'Tab Settings'], SettingsManager::EVENT_INFO => ['title' => 'Info Settings'], SettingsManager::EVENT_FEE => ['title' => 'Fee Settings'], SettingsManager::EVENT_REGISTRATION => ['title' => 'Online Registration Settings'], @@ -31,10 +31,12 @@ public function buildQuickForm() { CRM_Utils_System::setTitle(E::ts('CiviEvent Extras Settings')); $configFields = SettingsManager::getConfigFields(); foreach ($configFields as $name => $config) { - if (!array_key_exists('parent_setting', $config['extra_attributes'])){ - $this->addChildElement($name, $config); - } else { //handle default setting form - $this->addParentElement($config); + if (!array_key_exists('parent_setting', $config['extra_attributes'])) { + $this->addChildElement($name, $config); + //handle default setting form + } + else { + $this->addParentElement($config); } $this->assignConfigSections($name, $config['extra_attributes']['section']); } @@ -60,8 +62,7 @@ public function addRules() { $this->addFormRule(['CRM_EventsExtras_Form_Settings', 'validateRules']); } - - /** + /** * This functaion is for validating EventsExtras Setting Form * * @param array $values @@ -72,9 +73,9 @@ public static function validateRules($values) { $roles = SettingsManager::SETTING_FIELDS['ROLES']; $rolesDefault = SettingsManager::SETTING_FIELDS['ROLES_DEFAULT']; $paymentProcessor = SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION']; - $paymentProcessorDefault =SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION_DEFAULT']; + $paymentProcessorDefault = SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION_DEFAULT']; $payLaterOption = SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION']; - $paylaterOptionDefault= SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION_DEFAULT']; + $paylaterOptionDefault = SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION_DEFAULT']; $payLaterLabel = SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION_DEFAULT_LABEL']; $payLaterInsuection = SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION_DEFAULT_LABEL_INSTRUCTION']; @@ -82,15 +83,15 @@ public static function validateRules($values) { $errors[$rolesDefault] = E::ts('Default Role is a required field'); } - if ($values[$paymentProcessor] == 0 && !isset($values[$paymentProcessorDefault])){ + if ($values[$paymentProcessor] == 0 && !isset($values[$paymentProcessorDefault])) { $errors[$paymentProcessorDefault] = E::ts('Please select at least one payment processor and/or enable the pay later option.'); } - if ($values[$payLaterOption] == 0 && isset($values[$paylaterOptionDefault]) && $values[$paylaterOptionDefault] == 1){ - if ($values[$payLaterLabel] == NULL){ + if ($values[$payLaterOption] == 0 && isset($values[$paylaterOptionDefault]) && $values[$paylaterOptionDefault] == 1) { + if ($values[$payLaterLabel] == NULL) { $errors[$payLaterLabel] = E::ts(' Please enter the Pay Later prompt to be displayed on the Registration form.'); } - if ($values[$payLaterInsuection] == NULL){ + if ($values[$payLaterInsuection] == NULL) { $errors[$payLaterInsuection] = E::ts('Please enter the Pay Later instructions to be displayed to your users.'); } } @@ -102,13 +103,13 @@ public function postProcess() { $configFields = SettingsManager::getConfigFields(); $submittedValues = $this->exportValues(); - $valuesToSave = []; + $valuesToSave = []; if (isset($submittedValues[SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION_DEFAULT']])) { $paymentProcessors = $submittedValues[SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION_DEFAULT']]; //flip selected default paymentProcessors before saving to setting $flipedPaymentProcessor = []; - foreach ($paymentProcessors as $selectValue => $selected){ + foreach ($paymentProcessors as $selectValue => $selected) { $flipedPaymentProcessor[] = $selectValue; } @@ -118,41 +119,44 @@ public function postProcess() { $valuesToSave = array_intersect_key($submittedValues, $configFields); //makesure uncheck checkecbox value is set to default into setting //when user select hide but did not select the default. - foreach ($configFields as $field => $config){ - if (!isset($submittedValues[$field])){ + foreach ($configFields as $field => $config) { + if (!isset($submittedValues[$field])) { $valuesToSave[$field] = $config['default']; } } $result = civicrm_api3('setting', 'create', $valuesToSave); $session = CRM_Core_Session::singleton(); - if ($result['is_error']== 0){ - $session->setStatus(E::ts('Settings have been saved'),E::ts('Events Extra Settings'), 'success'); - } else{ - $session->setStatus(E::ts('Settings could not be saved, please contact Administrator'),E::ts('Events Extra Settings'), 'error'); + if ($result['is_error'] == 0) { + $session->setStatus(E::ts('Settings have been saved'), E::ts('Events Extra Settings'), 'success'); + } + else { + $session->setStatus(E::ts('Settings could not be saved, please contact Administrator'), E::ts('Events Extra Settings'), 'error'); } } - /** + /** * Add html element to the form for parent default setting. * * @param array $config */ - private function addParentElement($config){ + private function addParentElement($config) { if ($config['html_type'] == 'select') { $this->generateDefaultSelectList($config); - } else { + } + else { $this->generateDefaultSettingField($config); } $this->defaultSettingsDescription[$config['name']] = $config['description']; $this->defaultSettingsHelp[$config['name']] = $config['is_help']; } - /** + /** * Add html element to the form for child a default (global) setting. * + * @param $name * @param array $config */ - private function addChildElement($name, $config){ + private function addChildElement($name, $config) { $this->addRadio( $name, E::ts($config['title']), @@ -161,7 +165,7 @@ private function addChildElement($name, $config){ $this->parentSettings[$config['name']] = TRUE; } - private function generatePaymentProcessorField($setting){ + private function generatePaymentProcessorField($setting) { $paymentProcessor = CRM_Core_PseudoConstant::paymentProcessor(); $this->addCheckBox( $setting['name'], @@ -172,48 +176,51 @@ private function generatePaymentProcessorField($setting){ ); } - /** + /** * Generate a default Setting field to the form. * - * @param array $field + * @param array $setting */ private function generateDefaultSettingField($setting) { - if ($setting['name'] == SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION_DEFAULT']) { + if ($setting['name'] == SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION_DEFAULT']) { $this->generatePaymentProcessorField($setting); - } else { + } + else { $this->add( $setting['html_type'], $setting['name'], E::ts($setting['title']) - ); + ); } } - /** + /** * Generate select options from settings. * * @param array $setting */ private function generateDefaultSelectList($setting) { $options = []; - if (!empty($setting['pseudoconstant']['optionGroupName'])){ + if (!empty($setting['pseudoconstant']['optionGroupName'])) { $values = civicrm_api3('OptionGroup', 'get', [ 'sequential' => 1, - 'name' => $setting['pseudoconstant']['optionGroupName'], - 'api.OptionValue.get' => [' + 'name' => $setting['pseudoconstant']['optionGroupName'], + 'api.OptionValue.get' => [ + ' option_group_id' => 'id', 'options' => [ 'limit' => 0, ], - 'return' => ['value', 'label'] - ] + 'return' => ['value', 'label'], + ], ])['values'][0]['api.OptionValue.get']['values']; - foreach ($values as $value){ + foreach ($values as $value) { $options[$value['value']] = $value['label']; } - } else if ($setting['name'] == SettingsManager::SETTING_FIELDS['REGISTER_MULTIPLE_PARTICIPANTS_DEFAULT_MAXIMUM_PARTICIPANT']){ - // for default maxinum participant - foreach (range(1, 9) as $value){ + } + elseif ($setting['name'] == SettingsManager::SETTING_FIELDS['REGISTER_MULTIPLE_PARTICIPANTS_DEFAULT_MAXIMUM_PARTICIPANT']) { + // for default maxinum participant + foreach (range(1, 9) as $value) { $options[$value] = $value; } } @@ -272,4 +279,5 @@ private function assignConfigSections($name, $section) { break; } } + } From b0fb332ce0ad45ca3aa2ffb36139dcd75e98ce7c Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Thu, 2 Jul 2020 14:35:46 +0100 Subject: [PATCH 79/97] MAE-326: Do not assign default value for payment processor as the payment has already been set in the form --- CRM/EventsExtras/Hook/Pre/ManageEvent.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/CRM/EventsExtras/Hook/Pre/ManageEvent.php b/CRM/EventsExtras/Hook/Pre/ManageEvent.php index 8c3446d..526579b 100644 --- a/CRM/EventsExtras/Hook/Pre/ManageEvent.php +++ b/CRM/EventsExtras/Hook/Pre/ManageEvent.php @@ -77,15 +77,7 @@ private function preProcessData($section, &$params){ } } foreach ($fieldToProcess as $field => $value){ - // flip payment processor if it is event fee section - if (($section == SettingsManager::EVENT_FEE && $field == 'payment_processor')){ - //flip selected default paymentProcessors before saving to setting - $flipedPaymentProcessor = []; - foreach ($value as $selectValue => $selected){ - $flipedPaymentProcessor[$selected] = $selectValue; - } - $params[$field] = $flipedPaymentProcessor; - }else { + if ($section != SettingsManager::EVENT_FEE && $field != 'payment_processor'){ $params[$field] = $value; } } From c8359233b314ca138a36941e22d2fedb131066ce Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Thu, 2 Jul 2020 14:42:46 +0100 Subject: [PATCH 80/97] MAE-326: Fix phpcs linter error / warning --- CRM/EventsExtras/Hook/Pre/ManageEvent.php | 35 +++++++++++++---------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/CRM/EventsExtras/Hook/Pre/ManageEvent.php b/CRM/EventsExtras/Hook/Pre/ManageEvent.php index 526579b..061f8d6 100644 --- a/CRM/EventsExtras/Hook/Pre/ManageEvent.php +++ b/CRM/EventsExtras/Hook/Pre/ManageEvent.php @@ -10,7 +10,7 @@ class CRM_EventsExtras_Hook_Pre_ManageEvent { /** * Handle Hook Pre Event * - * @param string $formName + * @param $op * @param string $objectName * @param int $id * @param array $params @@ -34,53 +34,58 @@ private function shouldHandle($op, $objectName) { return $objectName == 'Event'; } - /** - * Set event parameter piror setting to database + /** + * Set event parameter prior setting to database * * @param string $op * @param int $id * @param array $params * */ - private function preSetData($op, $id, &$params ){ + private function preSetData($op, $id, &$params) { if ($op == 'delete' || $op == 'view') { return; } if (array_key_exists('event_type_id', $params)) { $this->preProcessData(SettingsManager::EVENT_INFO, $params); - } elseif (array_key_exists('is_monetary', $params) && $params['is_monetary'] == 1) { + } + elseif (array_key_exists('is_monetary', $params) && $params['is_monetary'] == 1) { $this->preProcessData(SettingsManager::EVENT_FEE, $params); - } elseif (array_key_exists('is_online_registration', $params) && $params['is_online_registration'] == 1) { + } + elseif (array_key_exists('is_online_registration', $params) && $params['is_online_registration'] == 1) { $this->preProcessData(SettingsManager::EVENT_REGISTRATION, $params); } } - private function preProcessData($section, &$params){ + private function preProcessData($section, &$params) { $fields = SettingsManager::getConfigFields($section); $settingsToProcess = []; $fieldToProcess = []; - foreach ($fields as $field){ + foreach ($fields as $field) { $settingName = $field['name']; $settingValue = SettingsManager::getSettingValue($settingName); - if (isset($settingValue[$settingName])){ + if (isset($settingValue[$settingName])) { $settingValue = $settingValue[$settingName]; - if (!array_key_exists('parent_setting', $field['extra_attributes'])){ //handle parent setting + //handle parent setting + if (!array_key_exists('parent_setting', $field['extra_attributes'])) { if ($settingValue == 0) { $settingsToProcess[$settingName] = $settingName; } - } else { //handle child setting and get element name - if (in_array($field['extra_attributes']['parent_setting'], $settingsToProcess)){ + //handle child setting and get element name + } + else { + if (in_array($field['extra_attributes']['parent_setting'], $settingsToProcess)) { $formName = $field['extra_attributes']['event_form_element_name']; $fieldToProcess[$formName] = $settingValue; } } } } - foreach ($fieldToProcess as $field => $value){ - if ($section != SettingsManager::EVENT_FEE && $field != 'payment_processor'){ + foreach ($fieldToProcess as $field => $value) { + if ($section != SettingsManager::EVENT_FEE && $field != 'payment_processor') { $params[$field] = $value; } } } -} +} From a1633c6db3ea165ba29d5f2d195c20bda20a8099 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Thu, 2 Jul 2020 15:43:46 +0100 Subject: [PATCH 81/97] MAE-326: Exclude Upgarder Base class from linter as it is auto generated by civix --- phpcs-ruleset.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/phpcs-ruleset.xml b/phpcs-ruleset.xml index 69ffbe2..f3172c5 100644 --- a/phpcs-ruleset.xml +++ b/phpcs-ruleset.xml @@ -4,5 +4,6 @@ tests/phpunit/bootstrap.php eventsextras.civix.php + CRM/EventsExtras/Upgrader/Base.php From 58a193ae16f8d8838c546324d6a2cb17468ac9c8 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Thu, 2 Jul 2020 15:44:49 +0100 Subject: [PATCH 82/97] MAE-326: Fix bad code reported by phpcs --- CRM/EventsExtras/Hook/BuildForm/BaseEvent.php | 15 +- CRM/EventsExtras/Hook/BuildForm/EventFee.php | 28 +- CRM/EventsExtras/Hook/BuildForm/EventInfo.php | 18 +- .../Hook/BuildForm/EventRegistration.php | 6 +- .../Hook/BuildForm/EventTabHeader.php | 15 +- CRM/EventsExtras/SettingsManager.php | 92 +-- CRM/EventsExtras/Upgrader.php | 3 +- CRM/EventsExtras/Upgrader/Base.php | 15 +- eventsextras.php | 12 +- settings/EventsExtras.setting.php | 408 ++++++------ settings/EventsExtrasDefault.setting.php | 587 +++++++++--------- 11 files changed, 598 insertions(+), 601 deletions(-) diff --git a/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php b/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php index e4bda47..8e966a0 100644 --- a/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php +++ b/CRM/EventsExtras/Hook/BuildForm/BaseEvent.php @@ -10,6 +10,7 @@ abstract class CRM_EventsExtras_Hook_BuildForm_BaseEvent { /** * Event tab to display on the form + * @var eventTab */ protected $eventTab; @@ -19,7 +20,7 @@ abstract class CRM_EventsExtras_Hook_BuildForm_BaseEvent { * @param string $eventTab * */ - protected function __construct($eventTab){ + protected function __construct($eventTab) { $this->eventTab = $eventTab; $this->addEventTabTemplate(); } @@ -30,7 +31,7 @@ protected function __construct($eventTab){ * @param string $formName * @param CRM_Core_Form $form */ - abstract function handle($formName, &$form); + abstract public function handle($formName, &$form); /** * Checks if the hook should be handled. @@ -53,7 +54,7 @@ protected function shouldHandle($formName, $formClass) { * @param array $form * */ - protected function hideField(CRM_Event_Form_ManageEvent &$form){ + protected function hideField(&$form) { $configFields = SettingsManager::getConfigFields($this->eventTab); $settingsValue = SettingsManager::getSettingsValue(); $hiddenFields = []; @@ -62,18 +63,18 @@ protected function hideField(CRM_Event_Form_ManageEvent &$form){ $configNameExists = isset($settingsValue[$config['name']]); $configNameIsZero = $settingsValue[$config['name']] == 0; $cssClassExists = array_key_exists('css_class', $config['extra_attributes']); - if ($configNameExists && $configNameIsZero && $cssClassExists){ + if ($configNameExists && $configNameIsZero && $cssClassExists) { $hiddenFields[] = $config['extra_attributes']['css_class']; } } $form->assign('hiddenCssClasses', $hiddenFields); } - private function addEventTabTemplate(){ + private function addEventTabTemplate() { $templatePath = E::path() . '/templates/CRM/EventsExtras/Form/EventTabs.tpl'; CRM_Core_Region::instance('page-body')->add([ - 'template' => "{$templatePath}" + 'template' => "{$templatePath}", ]); } -} +} diff --git a/CRM/EventsExtras/Hook/BuildForm/EventFee.php b/CRM/EventsExtras/Hook/BuildForm/EventFee.php index a8b50e7..80f5445 100644 --- a/CRM/EventsExtras/Hook/BuildForm/EventFee.php +++ b/CRM/EventsExtras/Hook/BuildForm/EventFee.php @@ -8,9 +8,8 @@ class CRM_EventsExtras_Hook_BuildForm_EventFee extends CRM_EventsExtras_Hook_BuildForm_BaseEvent { /** - * - * @param string $eventTab - */ + * CRM_EventsExtras_Hook_BuildForm_EventFee constructor. + */ public function __construct() { parent::__construct(SettingsManager::EVENT_FEE); } @@ -31,21 +30,20 @@ public function handle($formName, &$form) { private function buildForm($formName, &$form) { $this->setDefaults($form); - } + } - private function setDefaults(&$form){ - $defaults = []; - $paymentProcessor = SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION']; - $paymentProcessorDefault = SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION_DEFAULT']; - $settings = [$paymentProcessor, $paymentProcessorDefault]; - $settingValues = SettingsManager::getSettingsValue($settings); - if ($settingValues[$paymentProcessor] == 0){ + private function setDefaults(&$form) { + $defaults = []; + $paymentProcessor = SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION']; + $paymentProcessorDefault = SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION_DEFAULT']; + $settings = [$paymentProcessor, $paymentProcessorDefault]; + $settingValues = SettingsManager::getSettingsValue($settings); + if ($settingValues[$paymentProcessor] == 0) { $defaultSettingString = implode(CRM_Core_DAO::VALUE_SEPARATOR, $settingValues[$paymentProcessorDefault]); $paymentProcessorDefaultValue = (array_fill_keys(explode(CRM_Core_DAO::VALUE_SEPARATOR, $defaultSettingString), '1')); $defaults['payment_processor'] = $paymentProcessorDefaultValue; - } - $form->setDefaults($defaults); - } + } + $form->setDefaults($defaults); + } } - diff --git a/CRM/EventsExtras/Hook/BuildForm/EventInfo.php b/CRM/EventsExtras/Hook/BuildForm/EventInfo.php index 7525b9e..236077f 100644 --- a/CRM/EventsExtras/Hook/BuildForm/EventInfo.php +++ b/CRM/EventsExtras/Hook/BuildForm/EventInfo.php @@ -7,15 +7,14 @@ */ class CRM_EventsExtras_Hook_BuildForm_EventInfo extends CRM_EventsExtras_Hook_BuildForm_BaseEvent { - /** - * - * @param string $eventTab - */ + /** + * CRM_EventsExtras_Hook_BuildForm_EventInfo constructor. + */ public function __construct() { parent::__construct(SettingsManager::EVENT_INFO); } - /** + /** * Hides options on the Event Info page * * @param string $formName @@ -30,26 +29,25 @@ public function handle($formName, &$form) { } private function buildForm($formName, &$form) { - $this->setDefaults($form); + $this->setDefaults($form); } - /** + /** * Set defaults for form. * * @param array $form * */ - private function setDefaults(&$form){ + private function setDefaults(&$form) { $defaults = []; $role = SettingsManager::SETTING_FIELDS['ROLES']; $roleDefault = SettingsManager::SETTING_FIELDS['ROLES_DEFAULT']; $settings = [$role, $roleDefault]; $settingValues = SettingsManager::getSettingsValue($settings); - if ($settingValues[$role] == 0){ + if ($settingValues[$role] == 0) { $defaults['default_role_id'] = $settingValues[$roleDefault]; } $form->setDefaults($defaults); } } - diff --git a/CRM/EventsExtras/Hook/BuildForm/EventRegistration.php b/CRM/EventsExtras/Hook/BuildForm/EventRegistration.php index 56d6db4..cfe051c 100644 --- a/CRM/EventsExtras/Hook/BuildForm/EventRegistration.php +++ b/CRM/EventsExtras/Hook/BuildForm/EventRegistration.php @@ -8,9 +8,8 @@ class CRM_EventsExtras_Hook_BuildForm_EventRegistration extends CRM_EventsExtras_Hook_BuildForm_BaseEvent { /** - * - * @param string $eventTab - */ + * CRM_EventsExtras_Hook_BuildForm_EventRegistration constructor. + */ public function __construct() { parent::__construct(SettingsManager::EVENT_REGISTRATION); } @@ -27,4 +26,5 @@ public function handle($formName, &$form) { } $this->hideField($form); } + } diff --git a/CRM/EventsExtras/Hook/BuildForm/EventTabHeader.php b/CRM/EventsExtras/Hook/BuildForm/EventTabHeader.php index 2519033..a9afb75 100644 --- a/CRM/EventsExtras/Hook/BuildForm/EventTabHeader.php +++ b/CRM/EventsExtras/Hook/BuildForm/EventTabHeader.php @@ -20,7 +20,7 @@ public function handle($formName, &$form) { $this->hideTab($form); } - /** + /** * Checks if the hook should be handled. * * @param string $formName @@ -42,7 +42,7 @@ protected function shouldHandle($formName, &$form) { * @param object $form * */ - private function hideTab(&$form){ + private function hideTab(&$form) { $vars = $form->get_template_vars('tabHeader'); $locationTabSetting = SettingsManager::SETTING_FIELDS['LOCATION_TAB']; $pcpTabSetting = SettingsManager::SETTING_FIELDS['PCP_TAB']; @@ -50,19 +50,20 @@ private function hideTab(&$form){ $settingsValue = SettingsManager::getSettingsValue([ $locationTabSetting, $pcpTabSetting, - $tellFriendTabSetting + $tellFriendTabSetting, ]); - foreach ($settingsValue as $setting => $value){ - if ($setting == $locationTabSetting && $value == 0){ + foreach ($settingsValue as $setting => $value) { + if ($setting == $locationTabSetting && $value == 0) { unset($vars['location']); } - if ($setting == $tellFriendTabSetting && $value == 0){ + if ($setting == $tellFriendTabSetting && $value == 0) { unset($vars['friend']); } - if ($setting == $pcpTabSetting && $value == 0){ + if ($setting == $pcpTabSetting && $value == 0) { unset($vars['pcp']); } } $form->assign_by_ref('tabHeader', $vars); } + } diff --git a/CRM/EventsExtras/SettingsManager.php b/CRM/EventsExtras/SettingsManager.php index 0f6f1ee..891bbd2 100644 --- a/CRM/EventsExtras/SettingsManager.php +++ b/CRM/EventsExtras/SettingsManager.php @@ -15,57 +15,57 @@ class CRM_EventsExtras_SettingsManager { const SETTING_FIELDS = [ - 'LOCATION_TAB' => 'eventsextras_location_tab', - 'TELL_FRIEND_TAB' => 'eventsextras_tell_friend_tab', - 'PCP_TAB' => 'eventsextras_pcp_tab', - 'ROLES' => 'eventsextras_roles', - 'ROLES_DEFAULT' => 'eventsextras_roles_default', - 'PARTICIPANT_LISTING' => 'eventsextras_participant_listing', - 'PARTICIPANT_LISTING_DEFAULT' => 'eventsextras_participant_listing_default', - 'PARTICIPANT_SUMMARY' => 'eventsextras_event_summary', - 'EVENT_DESCRTIPTION' => 'eventsextras_event_description', - 'INCLUDE_MAP_LOCATION_EVENT' => 'eventsextras_include_map_event_location', - 'INCLUDE_MAP_LOCATION_EVENT_DEFAULT' => 'eventsextras_include_map_event_location_default', - 'INCLUDE_MAP_PUBLIC_EVENT' => 'eventsextras_public_event', - 'INCLUDE_MAP_PUBLIC_EVENT_DEFAULT' => 'eventsextras_public_event_default', - 'CURRENCY' => 'eventsextras_currency', - 'CURRENCY_DEFAULT' => 'eventsextras_currency_default', - 'PAYMENT_PROCESSOR_SELECTION' => 'eventsextras_payment_processor_selection', - 'PAYMENT_PROCESSOR_SELECTION_DEFAULT' => 'eventsextras_payment_processor_selection_default', - 'PAY_LATER_OPTION' => 'eventsextras_enable_pay_later_option', - 'PAY_LATER_OPTION_DEFAULT' => 'eventsextras_enable_pay_later_option_default', - 'PAY_LATER_OPTION_DEFAULT_LABEL' => 'eventsextras_enable_pay_later_option_default_label', - 'PAY_LATER_OPTION_DEFAULT_LABEL_INSTRUCTION' => 'eventsextras_enable_pay_later_option_default_instruction', - 'PAY_LATER_OPTION_DEFAULT_BILLING_ADDRESS' => 'eventsextras_enable_pay_later_option_default_billing_address_required', - 'PENDING_PARTICIPANT_EXPIRATION' => 'eventsextras_pending_participant_expiration', - 'PENDING_PARTICIPANT_EXPIRATION_DEFAULT' => 'eventsextras_pending_participant_expiration_default', - 'ALLOW_SELF_SERIVCE' => 'eventsextras_allow_self_service', - 'ALLOW_SELF_SERVICE_DEFAULT' => 'eventsextras_allow_self_service_default', - 'ALLOW_SELF_SERVICE_DEFAULT_TIME_LIMIT' => 'eventsextras_allow_self_service_default_time_limit', - 'REGISTER_MULTIPLE_PARTICIPANTS' => 'eventsextras_register_multiple_participants', - 'REGISTER_MULTIPLE_PARTICIPANTS_DEFULT' => 'eventsextras_register_multiple_participants_default', - 'REGISTER_MULTIPLE_PARTICIPANTS_DEFAULT_MAXIMUM_PARTICIPANT' => 'eventsextras_register_multiple_participants_default_maximum_participant' + 'LOCATION_TAB' => 'eventsextras_location_tab', + 'TELL_FRIEND_TAB' => 'eventsextras_tell_friend_tab', + 'PCP_TAB' => 'eventsextras_pcp_tab', + 'ROLES' => 'eventsextras_roles', + 'ROLES_DEFAULT' => 'eventsextras_roles_default', + 'PARTICIPANT_LISTING' => 'eventsextras_participant_listing', + 'PARTICIPANT_LISTING_DEFAULT' => 'eventsextras_participant_listing_default', + 'PARTICIPANT_SUMMARY' => 'eventsextras_event_summary', + 'EVENT_DESCRTIPTION' => 'eventsextras_event_description', + 'INCLUDE_MAP_LOCATION_EVENT' => 'eventsextras_include_map_event_location', + 'INCLUDE_MAP_LOCATION_EVENT_DEFAULT' => 'eventsextras_include_map_event_location_default', + 'INCLUDE_MAP_PUBLIC_EVENT' => 'eventsextras_public_event', + 'INCLUDE_MAP_PUBLIC_EVENT_DEFAULT' => 'eventsextras_public_event_default', + 'CURRENCY' => 'eventsextras_currency', + 'CURRENCY_DEFAULT' => 'eventsextras_currency_default', + 'PAYMENT_PROCESSOR_SELECTION' => 'eventsextras_payment_processor_selection', + 'PAYMENT_PROCESSOR_SELECTION_DEFAULT' => 'eventsextras_payment_processor_selection_default', + 'PAY_LATER_OPTION' => 'eventsextras_enable_pay_later_option', + 'PAY_LATER_OPTION_DEFAULT' => 'eventsextras_enable_pay_later_option_default', + 'PAY_LATER_OPTION_DEFAULT_LABEL' => 'eventsextras_enable_pay_later_option_default_label', + 'PAY_LATER_OPTION_DEFAULT_LABEL_INSTRUCTION' => 'eventsextras_enable_pay_later_option_default_instruction', + 'PAY_LATER_OPTION_DEFAULT_BILLING_ADDRESS' => 'eventsextras_enable_pay_later_option_default_billing_address_required', + 'PENDING_PARTICIPANT_EXPIRATION' => 'eventsextras_pending_participant_expiration', + 'PENDING_PARTICIPANT_EXPIRATION_DEFAULT' => 'eventsextras_pending_participant_expiration_default', + 'ALLOW_SELF_SERIVCE' => 'eventsextras_allow_self_service', + 'ALLOW_SELF_SERVICE_DEFAULT' => 'eventsextras_allow_self_service_default', + 'ALLOW_SELF_SERVICE_DEFAULT_TIME_LIMIT' => 'eventsextras_allow_self_service_default_time_limit', + 'REGISTER_MULTIPLE_PARTICIPANTS' => 'eventsextras_register_multiple_participants', + 'REGISTER_MULTIPLE_PARTICIPANTS_DEFULT' => 'eventsextras_register_multiple_participants_default', + 'REGISTER_MULTIPLE_PARTICIPANTS_DEFAULT_MAXIMUM_PARTICIPANT' => 'eventsextras_register_multiple_participants_default_maximum_participant', ]; - /** + /** * Gets a single setting value * * @return array - */ - public static function getSettingValue($setting){ + */ + public static function getSettingValue($setting) { return civicrm_api3('setting', 'get', [ 'return' => $setting, 'sequential' => 1, ])['values'][0]; } - /** + /** * Gets multiple settings values * * @return array - */ - public static function getSettingsValue($settings = NULL){ - if ($settings == NULL){ + */ + public static function getSettingsValue($settings = NULL) { + if ($settings == NULL) { $settings = array_values(self::SETTING_FIELDS); } return civicrm_api3('setting', 'get', [ @@ -83,12 +83,13 @@ public static function getConfigFields($section = NULL) { $configFields = self::fetchSettingFields(); if (!isset($configFields) || empty($configFields)) { $result = civicrm_api3('System', 'flush'); - if ($result['is_error'] == 0){ - $configFields = self::fetchSettingFields(); + if ($result['is_error'] == 0) { + $configFields = self::fetchSettingFields(); } } - if ($section != NULL){ //if section is passed, only return settings in section - foreach ($configFields as $field){ + //if section is passed, only return settings in section + if ($section != NULL) { + foreach ($configFields as $field) { if ($field['extra_attributes']['section'] != $section) { unset($configFields[$field['name']]); } @@ -105,13 +106,12 @@ public static function getConfigFields($section = NULL) { */ private static function fetchSettingFields() { $settingFields = []; - foreach (array_values(self::SETTING_FIELDS) as $name) { - $settingFields[$name] = civicrm_api3('setting', 'getfields',[ - 'filters' => [ 'name' => $name], - ])['values'][$name]; + foreach (array_values(self::SETTING_FIELDS) as $name) { + $settingFields[$name] = civicrm_api3('setting', 'getfields', [ + 'filters' => ['name' => $name], + ])['values'][$name]; } return $settingFields; } } - diff --git a/CRM/EventsExtras/Upgrader.php b/CRM/EventsExtras/Upgrader.php index 69a00e4..8513fb9 100644 --- a/CRM/EventsExtras/Upgrader.php +++ b/CRM/EventsExtras/Upgrader.php @@ -1,5 +1,4 @@ executeSqlFile('sql/auto_uninstall.sql'); + $this->executeSqlFile('sql/auto_uninstall.sql'); } } diff --git a/CRM/EventsExtras/Upgrader/Base.php b/CRM/EventsExtras/Upgrader/Base.php index 6e508a1..ab3781a 100644 --- a/CRM/EventsExtras/Upgrader/Base.php +++ b/CRM/EventsExtras/Upgrader/Base.php @@ -1,7 +1,6 @@ ctx = array_shift($args); diff --git a/eventsextras.php b/eventsextras.php index 4ef11ac..c125121 100644 --- a/eventsextras.php +++ b/eventsextras.php @@ -8,7 +8,7 @@ * * @link hhttps://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_buildForm/ */ -function eventsextras_civicrm_buildForm($formName, &$form){ +function eventsextras_civicrm_buildForm($formName, &$form) { $listeners = [ new CRM_EventsExtras_Hook_BuildForm_EventTabHeader(), new CRM_EventsExtras_Hook_BuildForm_EventInfo(), @@ -25,7 +25,7 @@ function eventsextras_civicrm_buildForm($formName, &$form){ * * @link hhttps://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_pre/ */ -function eventsextras_civicrm_pre($op, $objectName, $id, &$params){ +function eventsextras_civicrm_pre($op, $objectName, $id, &$params) { $listeners = [ new CRM_EventsExtras_Hook_Pre_ManageEvent(), ]; @@ -41,10 +41,10 @@ function eventsextras_civicrm_pre($op, $objectName, $id, &$params){ */ function eventsextras_civicrm_tab(&$tabs, $contactID) { /*$listeners = [ - new CRM_EventsExtras_Hook_Pre_ManageEvent(), + new CRM_EventsExtras_Hook_Pre_ManageEvent(), ]; foreach ($listeners as $currentListener) { - $currentListener->handle((&$tabs, $contactID); + $currentListener->handle((&$tabs, $contactID); }*/ } @@ -187,8 +187,8 @@ function eventsextras_civicrm_entityTypes(&$entityTypes) { * * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_preProcess * -function eventsextras_civicrm_preProcess($formName, &$form) { - + * function eventsextras_civicrm_preProcess($formName, &$form) { + * } // */ /** diff --git a/settings/EventsExtras.setting.php b/settings/EventsExtras.setting.php index 77d5295..32a45b7 100644 --- a/settings/EventsExtras.setting.php +++ b/settings/EventsExtras.setting.php @@ -1,9 +1,10 @@ [ 'name' => 'eventsextras_location_tab', @@ -18,9 +19,9 @@ 'description' => ts('Show/Hide Location Tab'), 'help_text' => '', 'extra_attributes' => [ - 'section' => SettingsManager::EVENT_TAB, - 'css_class' => '', - ], + 'section' => SettingsManager::EVENT_TAB, + 'css_class' => '', + ], ], 'eventsextras_tell_friend_tab' => [ 'name' => 'eventsextras_tell_friend_tab', @@ -35,9 +36,9 @@ 'description' => ts('Show/Hide Tell Friend Tab'), 'help_text' => '', 'extra_attributes' => [ - 'section' => SettingsManager::EVENT_TAB, - 'css_class' => '', - ], + 'section' => SettingsManager::EVENT_TAB, + 'css_class' => '', + ], ], 'eventsextras_pcp_tab' => [ 'name' => 'eventsextras_pcp_tab', @@ -52,213 +53,212 @@ 'description' => ts('Show/Hide Personal Campaigns Tab'), 'help_text' => '', 'extra_attributes' => [ - 'section' => SettingsManager::EVENT_TAB, - 'css_class' => '', - ], + 'section' => SettingsManager::EVENT_TAB, + 'css_class' => '', + ], ], - 'eventsextras_roles' => [ - 'name' => 'eventsextras_roles', - 'title' => ts('Default Role'), - 'type' => 'Boolean', - 'quick_form_type' => 'YesNo', - 'default' => TRUE, - 'html_type' => 'radio', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'description' => ts('Show/Hide Default Role'), - 'help_text' => '', - 'extra_attributes' => [ - 'section' => SettingsManager::EVENT_INFO, - 'css_class' => 'crm-event-manage-eventinfo-form-block-default_role_id', + 'eventsextras_roles' => [ + 'name' => 'eventsextras_roles', + 'title' => ts('Default Role'), + 'type' => 'Boolean', + 'quick_form_type' => 'YesNo', + 'default' => TRUE, + 'html_type' => 'radio', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('Show/Hide Default Role'), + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_INFO, + 'css_class' => 'crm-event-manage-eventinfo-form-block-default_role_id', + ], ], - ], - 'eventsextras_participant_listing' => [ - 'name' => 'eventsextras_participant_listing', - 'title' => ts('Participant listing'), - 'type' => 'Boolean', - 'quick_form_type' => 'YesNo', - 'default' => TRUE, - 'html_type' => 'radio', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'description' => ts('Show/Hide Participant listing'), - 'help_text' => '', - 'extra_attributes' => [ - 'section' => SettingsManager::EVENT_INFO, - 'css_class' => 'crm-event-manage-eventinfo-form-block-participant_listing_id', + 'eventsextras_participant_listing' => [ + 'name' => 'eventsextras_participant_listing', + 'title' => ts('Participant listing'), + 'type' => 'Boolean', + 'quick_form_type' => 'YesNo', + 'default' => TRUE, + 'html_type' => 'radio', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('Show/Hide Participant listing'), + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_INFO, + 'css_class' => 'crm-event-manage-eventinfo-form-block-participant_listing_id', + ], ], - ], - 'eventsextras_event_summary' => [ - 'name' => 'eventsextras_event_summary', - 'title' => ts('Events Summary'), - 'type' => 'Boolean', - 'quick_form_type' => 'YesNo', - 'default' => TRUE, - 'html_type' => 'radio', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'description' => ts('Show/Hide Event Summary'), - 'help_text' => '', - 'extra_attributes' => [ - 'section' => SettingsManager::EVENT_INFO, - 'css_class' => 'crm-event-manage-eventinfo-form-block-summary', + 'eventsextras_event_summary' => [ + 'name' => 'eventsextras_event_summary', + 'title' => ts('Events Summary'), + 'type' => 'Boolean', + 'quick_form_type' => 'YesNo', + 'default' => TRUE, + 'html_type' => 'radio', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('Show/Hide Event Summary'), + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_INFO, + 'css_class' => 'crm-event-manage-eventinfo-form-block-summary', + ], ], - ], - 'eventsextras_event_description' => [ - 'name' => 'eventsextras_event_description', - 'title' => ts('Complete Description'), - 'type' => 'Boolean', - 'quick_form_type' => 'YesNo', - 'default' => TRUE, - 'html_type' => 'radio', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'description' => ts('Show/Hide Complete Description'), - 'help_text' => '', - 'extra_attributes' => [ - 'section' => SettingsManager::EVENT_INFO, - 'css_class' => 'crm-event-manage-eventinfo-form-block-description', + 'eventsextras_event_description' => [ + 'name' => 'eventsextras_event_description', + 'title' => ts('Complete Description'), + 'type' => 'Boolean', + 'quick_form_type' => 'YesNo', + 'default' => TRUE, + 'html_type' => 'radio', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('Show/Hide Complete Description'), + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_INFO, + 'css_class' => 'crm-event-manage-eventinfo-form-block-description', + ], ], - ], - 'eventsextras_include_map_event_location' => [ - 'name' => 'eventsextras_include_map_event_location', - 'title' => ts('Include Map to Event Location'), - 'type' => 'Boolean', - 'quick_form_type' => 'YesNo', - 'default' => TRUE, - 'html_type' => 'radio', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'description' => ts('Show/Hide Include Map to Event Location'), - 'help_text' => '', - 'extra_attributes' => [ - 'section' => SettingsManager::EVENT_INFO, - 'css_class' => 'crm-event-manage-eventinfo-form-block-is_map', + 'eventsextras_include_map_event_location' => [ + 'name' => 'eventsextras_include_map_event_location', + 'title' => ts('Include Map to Event Location'), + 'type' => 'Boolean', + 'quick_form_type' => 'YesNo', + 'default' => TRUE, + 'html_type' => 'radio', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('Show/Hide Include Map to Event Location'), + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_INFO, + 'css_class' => 'crm-event-manage-eventinfo-form-block-is_map', + ], ], - ], - 'eventsextras_public_event' => [ - 'name' => 'eventsextras_public_event', - 'title' => ts('Public Event'), - 'type' => 'Boolean', - 'quick_form_type' => 'YesNo', - 'default' => TRUE, - 'html_type' => 'radio', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'description' => ts('Show/Hide Public Event'), - 'help_text' => '', - 'extra_attributes' => [ - 'section' => SettingsManager::EVENT_INFO, - 'css_class' => 'crm-event-manage-eventinfo-form-block-is_public', + 'eventsextras_public_event' => [ + 'name' => 'eventsextras_public_event', + 'title' => ts('Public Event'), + 'type' => 'Boolean', + 'quick_form_type' => 'YesNo', + 'default' => TRUE, + 'html_type' => 'radio', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('Show/Hide Public Event'), + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_INFO, + 'css_class' => 'crm-event-manage-eventinfo-form-block-is_public', + ], ], - ], - 'eventsextras_currency' => [ - 'name' => 'eventsextras_currency', - 'title' => ts('Currency'), - 'type' => 'Boolean', - 'quick_form_type' => 'YesNo', - 'default' => TRUE, - 'html_type' => 'radio', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'description' => ts('Show/Hide Currency'), - 'help_text' => '', - 'extra_attributes' => [ - 'section' => SettingsManager::EVENT_FEE, - 'css_class' => 'crm-event-manage-fee-form-block-currency', + 'eventsextras_currency' => [ + 'name' => 'eventsextras_currency', + 'title' => ts('Currency'), + 'type' => 'Boolean', + 'quick_form_type' => 'YesNo', + 'default' => TRUE, + 'html_type' => 'radio', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('Show/Hide Currency'), + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_FEE, + 'css_class' => 'crm-event-manage-fee-form-block-currency', + ], ], - ], - 'eventsextras_enable_pay_later_option' => [ - 'name' => 'eventsextras_enable_pay_later_option', - 'title' => ts('Enable pay later option'), - 'type' => 'Boolean', - 'quick_form_type' => 'YesNo', - 'default' => TRUE, - 'html_type' => 'radio', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'description' => ts('Show/Hide Enable pay later option'), - 'help_text' => '', - 'extra_attributes' => [ - 'section' => SettingsManager::EVENT_FEE, - 'css_class' => 'crm-event-manage-fee-form-block-is_pay_later', + 'eventsextras_enable_pay_later_option' => [ + 'name' => 'eventsextras_enable_pay_later_option', + 'title' => ts('Enable pay later option'), + 'type' => 'Boolean', + 'quick_form_type' => 'YesNo', + 'default' => TRUE, + 'html_type' => 'radio', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('Show/Hide Enable pay later option'), + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_FEE, + 'css_class' => 'crm-event-manage-fee-form-block-is_pay_later', + ], ], - ], - 'eventsextras_payment_processor_selection' => [ - 'name' => 'eventsextras_payment_processor_selection', - 'title' => ts('Payment Processor Selection'), - 'type' => 'Boolean', - 'quick_form_type' => 'YesNo', - 'default' => TRUE, - 'html_type' => 'radio', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'description' => ts('Show/Hide Payment Processor Selection'), - 'help_text' => '', - 'extra_attributes' => [ - 'section' => SettingsManager::EVENT_FEE, - 'css_class' => 'crm-event-manage-fee-form-block-payment_processor', + 'eventsextras_payment_processor_selection' => [ + 'name' => 'eventsextras_payment_processor_selection', + 'title' => ts('Payment Processor Selection'), + 'type' => 'Boolean', + 'quick_form_type' => 'YesNo', + 'default' => TRUE, + 'html_type' => 'radio', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('Show/Hide Payment Processor Selection'), + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_FEE, + 'css_class' => 'crm-event-manage-fee-form-block-payment_processor', + ], ], - ], - 'eventsextras_pending_participant_expiration' => [ - 'name' => 'eventsextras_pending_participant_expiration', - 'title' => ts('Pending Participant Expiration'), - 'type' => 'Boolean', - 'quick_form_type' => 'YesNo', - 'default' => TRUE, - 'html_type' => 'radio', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'description' => ts('Show/Hide Pending Participant Expiration'), - 'help_text' => '', - 'extra_attributes' => [ - 'section' => SettingsManager::EVENT_REGISTRATION, - 'css_class' => 'crm-event-manage-registration-form-block-expiration_time', + 'eventsextras_pending_participant_expiration' => [ + 'name' => 'eventsextras_pending_participant_expiration', + 'title' => ts('Pending Participant Expiration'), + 'type' => 'Boolean', + 'quick_form_type' => 'YesNo', + 'default' => TRUE, + 'html_type' => 'radio', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('Show/Hide Pending Participant Expiration'), + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_REGISTRATION, + 'css_class' => 'crm-event-manage-registration-form-block-expiration_time', + ], ], - ], - 'eventsextras_allow_self_service' => [ - 'name' => 'eventsextras_allow_self_service', - 'title' => ts('Allow Self Service'), - 'type' => 'Boolean', - 'quick_form_type' => 'YesNo', - 'default' => TRUE, - 'html_type' => 'radio', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'description' => ts('Show/Hide Allow self-service cancellation or transfer?'), - 'help_text' => '', - 'extra_attributes' => [ - 'section' => SettingsManager::EVENT_REGISTRATION, - 'css_class' => 'crm-event-manage-registration-form-block-selfcancelxfer', + 'eventsextras_allow_self_service' => [ + 'name' => 'eventsextras_allow_self_service', + 'title' => ts('Allow Self Service'), + 'type' => 'Boolean', + 'quick_form_type' => 'YesNo', + 'default' => TRUE, + 'html_type' => 'radio', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('Show/Hide Allow self-service cancellation or transfer?'), + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_REGISTRATION, + 'css_class' => 'crm-event-manage-registration-form-block-selfcancelxfer', + ], ], - ], - 'eventsextras_register_multiple_participants' => [ - 'name' => 'eventsextras_register_multiple_participants', - 'title' => ts('Register Multiple Participants'), - 'type' => 'Boolean', - 'quick_form_type' => 'YesNo', - 'default' => TRUE, - 'html_type' => 'radio', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'description' => ts('Show/Hide Register multiple participants?'), - 'help_text' => '', - 'extra_attributes' => [ - 'section' => SettingsManager::EVENT_REGISTRATION, - 'css_class' => 'crm-event-manage-registration-form-block-is_multiple_registrations', + 'eventsextras_register_multiple_participants' => [ + 'name' => 'eventsextras_register_multiple_participants', + 'title' => ts('Register Multiple Participants'), + 'type' => 'Boolean', + 'quick_form_type' => 'YesNo', + 'default' => TRUE, + 'html_type' => 'radio', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('Show/Hide Register multiple participants?'), + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_REGISTRATION, + 'css_class' => 'crm-event-manage-registration-form-block-is_multiple_registrations', + ], ], - ], ]; - diff --git a/settings/EventsExtrasDefault.setting.php b/settings/EventsExtrasDefault.setting.php index d9b2867..4f9cf45 100644 --- a/settings/EventsExtrasDefault.setting.php +++ b/settings/EventsExtrasDefault.setting.php @@ -1,133 +1,134 @@ [ - 'name' => 'eventsextras_roles_default', - 'title' => ts('Set Default Setting of Default Role'), - 'type' => 'Integer', - 'quick_form_type' => 'Select', - 'default' => '', - 'html_type' => 'select', - 'pseudoconstant' => [ - 'optionGroupName' => 'participant_role', + 'eventsextras_roles_default' => [ + 'name' => 'eventsextras_roles_default', + 'title' => ts('Set Default Setting of Default Role'), + 'type' => 'Integer', + 'quick_form_type' => 'Select', + 'default' => '', + 'html_type' => 'select', + 'pseudoconstant' => [ + 'optionGroupName' => 'participant_role', + ], + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => '', + 'is_help' => TRUE, + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_INFO, + 'parent_setting' => SettingsManager::SETTING_FIELDS['ROLES'], + 'event_form_element_name' => 'default_role_id', + 'class' => 'crm-select2', + 'placeholder' => ts('- Select -'), ], - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'description' => '', - 'is_help' => TRUE, - 'help_text' => '', - 'extra_attributes' => [ - 'section' => SettingsManager::EVENT_INFO, - 'parent_setting' => SettingsManager::SETTING_FIELDS['ROLES'], - 'event_form_element_name' => 'default_role_id', - 'class' => 'crm-select2', - 'placeholder' => ts('- Select -'), - ], - ], -'eventsextras_participant_listing_default' => [ - 'name' => 'eventsextras_participant_listing_default', - 'title' => ts('Set Default Setting of Participant Listing'), - 'type' => 'Integer', - 'quick_form_type' => 'Select', - 'default' => '', - 'html_type' => 'select', - 'pseudoconstant' => [ - 'optionGroupName' => 'participant_listing', ], - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'is_help' => TRUE, - 'description' => '', - 'help_text' => '', - 'extra_attributes' => [ - 'section' => SettingsManager::EVENT_INFO, - 'parent_setting' => SettingsManager::SETTING_FIELDS['PARTICIPANT_LISTING'], - 'event_form_element_name' => 'participant_listing_id', - 'class' => 'crm-select2', - 'placeholder' => ts('Disabled'), + 'eventsextras_participant_listing_default' => [ + 'name' => 'eventsextras_participant_listing_default', + 'title' => ts('Set Default Setting of Participant Listing'), + 'type' => 'Integer', + 'quick_form_type' => 'Select', + 'default' => '', + 'html_type' => 'select', + 'pseudoconstant' => [ + 'optionGroupName' => 'participant_listing', + ], + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'is_help' => TRUE, + 'description' => '', + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_INFO, + 'parent_setting' => SettingsManager::SETTING_FIELDS['PARTICIPANT_LISTING'], + 'event_form_element_name' => 'participant_listing_id', + 'class' => 'crm-select2', + 'placeholder' => ts('Disabled'), + ], + ], + 'eventsextras_include_map_event_location_default' => [ + 'name' => 'eventsextras_include_map_event_location_default', + 'title' => ts('Set Default Include Map to Event Location'), + 'type' => 'Integer', + 'default' => '', + 'html_type' => 'checkbox', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'is_help' => TRUE, + 'description' => '', + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_INFO, + 'parent_setting' => SettingsManager::SETTING_FIELDS['INCLUDE_MAP_LOCATION_EVENT'], + 'event_form_element_name' => 'is_map', + 'class' => '', + ], ], - ], - 'eventsextras_include_map_event_location_default' => [ - 'name' => 'eventsextras_include_map_event_location_default', - 'title' => ts('Set Default Include Map to Event Location'), - 'type' => 'Integer', - 'default' => '', - 'html_type' => 'checkbox', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'is_help' => TRUE, - 'description' => '', - 'help_text' => '', - 'extra_attributes' => [ - 'section' => SettingsManager::EVENT_INFO, - 'parent_setting' => SettingsManager::SETTING_FIELDS['INCLUDE_MAP_LOCATION_EVENT'], - 'event_form_element_name' => 'is_map', - 'class' => '', - ], -], -'eventsextras_public_event_default' => [ - 'name' => 'eventsextras_public_event_default', - 'title' => ts('Set Default Public Event'), - 'type' => 'Integer', - 'default' => 0, - 'html_type' => 'checkbox', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'is_help' => TRUE, - 'description' => '', - 'help_text' => '', - 'extra_attributes' => [ - 'section' => SettingsManager::EVENT_INFO, - 'parent_setting' => SettingsManager::SETTING_FIELDS['INCLUDE_MAP_PUBLIC_EVENT'], - 'event_form_element_name' => 'is_public', - 'class' => '', + 'eventsextras_public_event_default' => [ + 'name' => 'eventsextras_public_event_default', + 'title' => ts('Set Default Public Event'), + 'type' => 'Integer', + 'default' => 0, + 'html_type' => 'checkbox', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'is_help' => TRUE, + 'description' => '', + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_INFO, + 'parent_setting' => SettingsManager::SETTING_FIELDS['INCLUDE_MAP_PUBLIC_EVENT'], + 'event_form_element_name' => 'is_public', + 'class' => '', + ], ], - ], - 'eventsextras_currency_default' => [ - 'name' => 'eventsextras_currency_default', - 'title' => ts('Set Default Currency'), - 'type' => 'String', - 'quick_form_type' => 'Select', - 'default' => '', - 'html_type' => 'select', - 'pseudoconstant' => [ - 'optionGroupName' => 'currencies_enabled', - ], - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'is_help' => FALSE, - 'description' => ts('Select the currency to be used for event registration.'), - 'help_text' => '', - 'extra_attributes' => [ - 'section' => SettingsManager::EVENT_FEE, - 'parent_setting' => SettingsManager::SETTING_FIELDS['CURRENCY'], - 'event_form_element_name' => 'currency', - 'class' => 'crm-select2', - 'placeholder' => ts('--Select--'), + 'eventsextras_currency_default' => [ + 'name' => 'eventsextras_currency_default', + 'title' => ts('Set Default Currency'), + 'type' => 'String', + 'quick_form_type' => 'Select', + 'default' => '', + 'html_type' => 'select', + 'pseudoconstant' => [ + 'optionGroupName' => 'currencies_enabled', + ], + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'is_help' => FALSE, + 'description' => ts('Select the currency to be used for event registration.'), + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_FEE, + 'parent_setting' => SettingsManager::SETTING_FIELDS['CURRENCY'], + 'event_form_element_name' => 'currency', + 'class' => 'crm-select2', + 'placeholder' => ts('--Select--'), + ], ], - ], - 'eventsextras_payment_processor_selection_default' => [ - 'name' => 'eventsextras_payment_processor_selection_default', - 'title' => ts('Set Default Payment Processor Selection'), - 'type' => 'String', - 'quick_form_type' => 'Checkboxes', - 'default' => '', - 'html_type' => 'checkboxes', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'is_help' => FALSE, - 'description' => ts(' + 'eventsextras_payment_processor_selection_default' => [ + 'name' => 'eventsextras_payment_processor_selection_default', + 'title' => ts('Set Default Payment Processor Selection'), + 'type' => 'String', + 'quick_form_type' => 'Checkboxes', + 'default' => '', + 'html_type' => 'checkboxes', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'is_help' => FALSE, + 'description' => ts(' If this is a paid event and you want users to be able to register and pay online, select a payment processor to use. NOTE: Alternatively, you can enable the Pay Later feature below without setting up a payment processor. @@ -137,185 +138,185 @@ target="_blank" class="crm-doc-link no-popup" title="Opens documentation in a new window."> (learn more...) '), - 'help_text' => '', - 'extra_attributes' => [ - 'section' => SettingsManager::EVENT_FEE, - 'parent_setting' => SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION'], - 'event_form_element_name' => 'payment_processor', - 'class' => '', + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_FEE, + 'parent_setting' => SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION'], + 'event_form_element_name' => 'payment_processor', + 'class' => '', + ], ], - ], - 'eventsextras_enable_pay_later_option_default' => [ - 'name' => 'eventsextras_enable_pay_later_option_default', - 'title' => ts('Enable Default Pay Later option?'), - 'type' => 'Integer', - 'default' => '', - 'html_type' => 'checkbox', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'is_help' => FALSE, - 'description' => ts('Check this box if you want to give users the option to submit payment offline (e.g. mail in a check, call in a credit card, etc.). '), - 'help_text' => '', - 'extra_attributes' => [ - 'section' => SettingsManager::EVENT_FEE, - 'parent_setting' => SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION'], - 'event_form_element_name' => 'is_pay_later', - 'class' => '', + 'eventsextras_enable_pay_later_option_default' => [ + 'name' => 'eventsextras_enable_pay_later_option_default', + 'title' => ts('Enable Default Pay Later option?'), + 'type' => 'Integer', + 'default' => '', + 'html_type' => 'checkbox', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'is_help' => FALSE, + 'description' => ts('Check this box if you want to give users the option to submit payment offline (e.g. mail in a check, call in a credit card, etc.). '), + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_FEE, + 'parent_setting' => SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION'], + 'event_form_element_name' => 'is_pay_later', + 'class' => '', + ], ], - ], - 'eventsextras_enable_pay_later_option_default_label' => [ - 'name' => 'eventsextras_enable_pay_later_option_default_label', - 'title' => ts('Set Default Pay Later Label'), - 'type' => 'String', - 'default' => '', - 'html_type' => 'textarea', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'is_help' => FALSE, - 'description' => ts('Text displayed next to the checkbox for the "pay later" option on the contribution form. You may include HTML formatting tags.'), - 'help_text' => '', - 'extra_attributes' => [ - 'section' => SettingsManager::EVENT_FEE, - 'parent_setting' => SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION'], - 'event_form_element_name' => 'pay_later_text', - 'class' => '', + 'eventsextras_enable_pay_later_option_default_label' => [ + 'name' => 'eventsextras_enable_pay_later_option_default_label', + 'title' => ts('Set Default Pay Later Label'), + 'type' => 'String', + 'default' => '', + 'html_type' => 'textarea', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'is_help' => FALSE, + 'description' => ts('Text displayed next to the checkbox for the "pay later" option on the contribution form. You may include HTML formatting tags.'), + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_FEE, + 'parent_setting' => SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION'], + 'event_form_element_name' => 'pay_later_text', + 'class' => '', + ], ], - ], - 'eventsextras_enable_pay_later_option_default_instruction' => [ - 'name' => 'eventsextras_enable_pay_later_option_default_instruction', - 'title' => ts('Set Default Pay Later Instruction'), - 'type' => 'String', - 'default' => '', - 'html_type' => 'textarea', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'is_help' => FALSE, - 'description' => ts('Instructions added to Confirmation and Thank-you pages when the user selects the "pay later" option (e.g. "Mail your check to ... within 3 business days."). '), - 'help_text' => '', - 'extra_attributes' => [ - 'section' => SettingsManager::EVENT_FEE, - 'parent_setting' => SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION'], - 'event_form_element_name' => 'pay_later_receipt', - 'class' => '', + 'eventsextras_enable_pay_later_option_default_instruction' => [ + 'name' => 'eventsextras_enable_pay_later_option_default_instruction', + 'title' => ts('Set Default Pay Later Instruction'), + 'type' => 'String', + 'default' => '', + 'html_type' => 'textarea', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'is_help' => FALSE, + 'description' => ts('Instructions added to Confirmation and Thank-you pages when the user selects the "pay later" option (e.g. "Mail your check to ... within 3 business days."). '), + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_FEE, + 'parent_setting' => SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION'], + 'event_form_element_name' => 'pay_later_receipt', + 'class' => '', + ], + ], + 'eventsextras_enable_pay_later_option_default_billing_address_required' => [ + 'name' => 'eventsextras_enable_pay_later_option_default_billing_address_required', + 'title' => ts('Set Default Billing Address Required?'), + 'type' => 'Integer', + 'default' => '', + 'html_type' => 'checkbox', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'is_help' => FALSE, + 'description' => ts('Check this box to require users who select the pay later option to provide billing name and address.'), + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_FEE, + 'parent_setting' => SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION'], + 'event_form_element_name' => 'is_billing_required', + 'class' => '', + ], ], - ], - 'eventsextras_enable_pay_later_option_default_billing_address_required' => [ - 'name' => 'eventsextras_enable_pay_later_option_default_billing_address_required', - 'title' => ts('Set Default Billing Address Required?'), - 'type' => 'Integer', - 'default' => '', - 'html_type' => 'checkbox', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'is_help' => FALSE, - 'description' => ts('Check this box to require users who select the pay later option to provide billing name and address.'), - 'help_text' => '', - 'extra_attributes' => [ - 'section' => SettingsManager::EVENT_FEE, - 'parent_setting' => SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION'], - 'event_form_element_name' => 'is_billing_required', - 'class' => '', + 'eventsextras_pending_participant_expiration_default' => [ + 'name' => 'eventsextras_pending_participant_expiration_default', + 'title' => ts('Set Default Pending Participant Expiration'), + 'type' => 'Integer', + 'quick_form_type' => 'Text', + 'default' => '', + 'html_type' => 'text', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'is_help' => TRUE, + 'description' => ts(''), + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_REGISTRATION, + 'parent_setting' => SettingsManager::SETTING_FIELDS['PENDING_PARTICIPANT_EXPIRATION'], + 'event_form_element_name' => 'expiration_time', + 'class' => '', + ], ], - ], - 'eventsextras_pending_participant_expiration_default' => [ - 'name' => 'eventsextras_pending_participant_expiration_default', - 'title' => ts('Set Default Pending Participant Expiration'), - 'type' => 'Integer', - 'quick_form_type' => 'Text', - 'default' => '', - 'html_type' => 'text', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'is_help' => TRUE, - 'description' => ts(''), - 'help_text' => '', - 'extra_attributes' => [ - 'section' => SettingsManager::EVENT_REGISTRATION, - 'parent_setting' => SettingsManager::SETTING_FIELDS['PENDING_PARTICIPANT_EXPIRATION'], - 'event_form_element_name' => 'expiration_time', - 'class' => '', - ], -], -'eventsextras_allow_self_service_default' => [ - 'name' => 'eventsextras_allow_self_service_default', - 'title' => ts('Set Default Allow Self-Service Cancellation or Transfer?'), - 'type' => 'Integer', - 'quick_form_type' => 'Checkbox', - 'default' => '', - 'html_type' => 'checkbox', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'is_help' => TRUE, - 'description' => ts(''), - 'help_text' => '', - 'extra_attributes' => [ - 'section' => SettingsManager::EVENT_REGISTRATION, - 'parent_setting' => SettingsManager::SETTING_FIELDS['ALLOW_SELF_SERIVCE'], - 'event_form_element_name' => 'allow_selfcancelxfer', - ], -], -'eventsextras_allow_self_service_default_time_limit' => [ - 'name' => 'eventsextras_allow_self_service_default_time_limit', - 'title' => ts('Set Default Cancellation or transfer time limit (hours) '), - 'type' => 'Integer', - 'quick_form_type' => 'Text', - 'default' => '', - 'html_type' => 'text', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'is_help' => TRUE, - 'description' => ts(''), - 'help_text' => '', - 'extra_attributes' => [ - 'section' => SettingsManager::EVENT_REGISTRATION, - 'parent_setting' => SettingsManager::SETTING_FIELDS['ALLOW_SELF_SERIVCE'], - 'event_form_element_name' => 'selfcancelxfer_time', - ], -], -'eventsextras_register_multiple_participants_default' => [ - 'name' => 'eventsextras_register_multiple_participants_default', - 'title' => ts('Set Default Register multiple participants? '), - 'type' => 'Integer', - 'quick_form_type' => 'Checkbox', - 'default' => '', - 'html_type' => 'checkbox', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'is_help' => TRUE, - 'description' => ts(''), - 'help_text' => '', - 'extra_attributes' => [ - 'section' => SettingsManager::EVENT_REGISTRATION, - 'parent_setting' => SettingsManager::SETTING_FIELDS['REGISTER_MULTIPLE_PARTICIPANTS'], - 'event_form_element_name' => 'is_multiple_registrations', - ], -], -'eventsextras_register_multiple_participants_default_maximum_participant' => [ - 'name' => 'eventsextras_register_multiple_participants_default_maximum_participant', - 'title' => ts('Set Default Maximum additional participants '), - 'type' => 'Integer', - 'quick_form_type' => 'Select', - 'default' => 9, - 'html_type' => 'select', - 'add' => '1.0', - 'is_domain' => 1, - 'is_contact' => 0, - 'is_help' => TRUE, - 'description' => ts(''), - 'help_text' => '', - 'extra_attributes' => [ - 'section' => SettingsManager::EVENT_REGISTRATION, - 'parent_setting' => SettingsManager::SETTING_FIELDS['REGISTER_MULTIPLE_PARTICIPANTS'], - 'event_form_element_name' => 'max_additional_participants', + 'eventsextras_allow_self_service_default' => [ + 'name' => 'eventsextras_allow_self_service_default', + 'title' => ts('Set Default Allow Self-Service Cancellation or Transfer?'), + 'type' => 'Integer', + 'quick_form_type' => 'Checkbox', + 'default' => '', + 'html_type' => 'checkbox', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'is_help' => TRUE, + 'description' => ts(''), + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_REGISTRATION, + 'parent_setting' => SettingsManager::SETTING_FIELDS['ALLOW_SELF_SERIVCE'], + 'event_form_element_name' => 'allow_selfcancelxfer', + ], + ], + 'eventsextras_allow_self_service_default_time_limit' => [ + 'name' => 'eventsextras_allow_self_service_default_time_limit', + 'title' => ts('Set Default Cancellation or transfer time limit (hours) '), + 'type' => 'Integer', + 'quick_form_type' => 'Text', + 'default' => '', + 'html_type' => 'text', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'is_help' => TRUE, + 'description' => ts(''), + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_REGISTRATION, + 'parent_setting' => SettingsManager::SETTING_FIELDS['ALLOW_SELF_SERIVCE'], + 'event_form_element_name' => 'selfcancelxfer_time', + ], + ], + 'eventsextras_register_multiple_participants_default' => [ + 'name' => 'eventsextras_register_multiple_participants_default', + 'title' => ts('Set Default Register multiple participants? '), + 'type' => 'Integer', + 'quick_form_type' => 'Checkbox', + 'default' => '', + 'html_type' => 'checkbox', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'is_help' => TRUE, + 'description' => ts(''), + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_REGISTRATION, + 'parent_setting' => SettingsManager::SETTING_FIELDS['REGISTER_MULTIPLE_PARTICIPANTS'], + 'event_form_element_name' => 'is_multiple_registrations', + ], + ], + 'eventsextras_register_multiple_participants_default_maximum_participant' => [ + 'name' => 'eventsextras_register_multiple_participants_default_maximum_participant', + 'title' => ts('Set Default Maximum additional participants '), + 'type' => 'Integer', + 'quick_form_type' => 'Select', + 'default' => 9, + 'html_type' => 'select', + 'add' => '1.0', + 'is_domain' => 1, + 'is_contact' => 0, + 'is_help' => TRUE, + 'description' => ts(''), + 'help_text' => '', + 'extra_attributes' => [ + 'section' => SettingsManager::EVENT_REGISTRATION, + 'parent_setting' => SettingsManager::SETTING_FIELDS['REGISTER_MULTIPLE_PARTICIPANTS'], + 'event_form_element_name' => 'max_additional_participants', + ], ], - ], ]; From 334370e5523169efefde4c512d4b60055215a013 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Thu, 2 Jul 2020 15:48:21 +0100 Subject: [PATCH 83/97] MAE-326: Add linters Github workflow --- .github/workflows/linters.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/linters.yml diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml new file mode 100644 index 0000000..2bc4358 --- /dev/null +++ b/.github/workflows/linters.yml @@ -0,0 +1,23 @@ +name: Linters + +on: pull_request + +env: + GITHUB_BASE_REF: ${{ github.base_ref }} + +jobs: + run-linters: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Install phpcs + run: cd bin && ./install-php-linter + + - name: Fetch target branch + run: git fetch -n origin ${GITHUB_BASE_REF} + + - name: Run phpcs linter + run: git diff --diff-filter=d origin/${GITHUB_BASE_REF} --name-only -- '*.php' | xargs -r ./bin/phpcs.phar --standard=phpcs-ruleset.xml From b5cf457167fcf4b0a5d139d54d136bf78e5e4c0b Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Thu, 2 Jul 2020 15:49:50 +0100 Subject: [PATCH 84/97] MAE-326: Make install-php-linter execuable. --- bin/install-php-linter | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 bin/install-php-linter diff --git a/bin/install-php-linter b/bin/install-php-linter old mode 100644 new mode 100755 From 51df52de4c7c4f7b2d1c7253d5d1d432dda66e83 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Thu, 2 Jul 2020 15:53:21 +0100 Subject: [PATCH 85/97] MAE-326: Add tests Github workflow --- .github/workflows/tests.yml | 52 +++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..5af0f3e --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,52 @@ +name: Tests + +on: pull_request + +jobs: + run-unit-tests: + + runs-on: ubuntu-latest + container: compucorp/civicrm-buildkit:1.0.0 + + env: + CIVICRM_EXTENSIONS_DIR: site/web/sites/all/modules/civicrm/tools/extensions + + services: + mysql: + image: mysql:5.7 + env: + MYSQL_ROOT_PASSWORD: root + ports: + - 3306 + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + + steps: + + - name: Config mysql database as per CiviCRM requirement + run: echo "SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));" | mysql -u root --password=root --host=mysql + + - name: Config amp + run : amp config:set --mysql_dsn=mysql://root:root@mysql:3306 + + - name: Build Drupal site + run: civibuild create drupal-clean --civi-ver 5.24.6 --web-root $GITHUB_WORKSPACE/site + + - uses: compucorp/apply-patch@1.0.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + repo: compucorp/civicrm-core + version: 5.24.6 + path: site/web/sites/all/modules/civicrm + + - uses: actions/checkout@v2 + with: + path: ${{ env.CIVICRM_EXTENSIONS_DIR }}/uk.co.compucorp.eventsextras + + - name: Installing Eventsextras + working-directory: ${{ env.CIVICRM_EXTENSIONS_DIR }} + run: cv en uk.co.compucorp.eventsextras + + - name: Run phpunit tests + working-directory: ${{ env.CIVICRM_EXTENSIONS_DIR }}/uk.co.compucorp.eventsextras + run: phpunit5 From 9fe4616d7889acc6f7101705659a3e46774a3931 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Thu, 2 Jul 2020 17:06:52 +0100 Subject: [PATCH 86/97] MAE-326: Add SettingsManagerTest --- .../CRM/EventsExtras/SettingsManagerTest.php | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 tests/phpunit/CRM/EventsExtras/SettingsManagerTest.php diff --git a/tests/phpunit/CRM/EventsExtras/SettingsManagerTest.php b/tests/phpunit/CRM/EventsExtras/SettingsManagerTest.php new file mode 100644 index 0000000..d897fc8 --- /dev/null +++ b/tests/phpunit/CRM/EventsExtras/SettingsManagerTest.php @@ -0,0 +1,75 @@ +getSettingValue(CRM_EventsExtras_SettingsManager::SETTING_FIELDS['LOCATION_TAB']); + $this->assertNotEmpty($locationTab); + } + + + /** + * Tests getSettingsValue + */ + public function testGetSettingsValue() { + $settingsManager = new CRM_EventsExtras_SettingsManager(); + $settings = $settingsManager->getSettingsValue(); + $this->assertArrayHasKey(SettingsManager::SETTING_FIELDS['LOCATION_TAB'], $settings); + $this->assertArrayHasKey(SettingsManager::SETTING_FIELDS['TELL_FRIEND_TAB'], $settings); + $this->assertArrayHasKey(SettingsManager::SETTING_FIELDS['PCP_TAB'], $settings); + $this->assertArrayHasKey(SettingsManager::SETTING_FIELDS['ROLES'], $settings); + $this->assertArrayHasKey(SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION_DEFAULT'], $settings); + + } + + /** + * Tests getSettingsValue with Params + */ + public function getSettingsValueWithParams() { + $settingsManager = new CRM_EventsExtras_SettingsManager(); + $params = [ + SettingsManager::SETTING_FIELDS['LOCATION_TAB'], + SettingsManager::SETTING_FIELDS['TELL_FRIEND_TAB'], + ]; + $settings = $settingsManager->getSettingsValue($params); + $this->assertEquals(2, count($settings)); + $this->assertArrayHasKey(SettingsManager::SETTING_FIELDS['LOCATION_TAB'], $settings); + $this->assertArrayHasKey(SettingsManager::SETTING_FIELDS['TELL_FRIEND_TAB'], $settings); + } + + /** + * Tests getConfigFields + */ + public function testGetConfigFields() { + $settingsManager = new CRM_EventsExtras_SettingsManager(); + $configFields = $settingsManager->getConfigFields(); + $this->assertNotEmpty($configFields); + $configFields = $settingsManager->getConfigFields(SettingsManager::EVENT_TAB); + $this->assertNotEmpty($configFields); + $this->assertEquals(3, count($configFields)); + $configFields = $settingsManager->getConfigFields(SettingsManager::EVENT_INFO); + $this->assertNotEmpty($configFields); + $this->assertEquals(10, count($configFields)); + $configFields = $settingsManager->getConfigFields(SettingsManager::EVENT_FEE); + $this->assertNotEmpty($configFields); + $this->assertEquals(9, count($configFields)); + $configFields = $settingsManager->getConfigFields(SettingsManager::EVENT_REGISTRATION); + $this->assertNotEmpty($configFields); + $this->assertEquals(8, count($configFields)); + } + + +} From f7bc45bac99006f55725d3b1b4b340123094ff66 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Thu, 2 Jul 2020 17:08:23 +0100 Subject: [PATCH 87/97] MAE-326: Fix variable typo --- CRM/EventsExtras/Form/Settings.php | 10 +++++----- CRM/EventsExtras/SettingsManager.php | 6 +++--- eventsextras.php | 2 +- settings/EventsExtrasDefault.setting.php | 4 ++-- tests/phpunit/CRM/EventsExtras/SettingsManagerTest.php | 3 --- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/CRM/EventsExtras/Form/Settings.php b/CRM/EventsExtras/Form/Settings.php index 489b29a..3ce210a 100644 --- a/CRM/EventsExtras/Form/Settings.php +++ b/CRM/EventsExtras/Form/Settings.php @@ -75,9 +75,9 @@ public static function validateRules($values) { $paymentProcessor = SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION']; $paymentProcessorDefault = SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION_DEFAULT']; $payLaterOption = SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION']; - $paylaterOptionDefault = SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION_DEFAULT']; + $payLaterOptionDefault = SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION_DEFAULT']; $payLaterLabel = SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION_DEFAULT_LABEL']; - $payLaterInsuection = SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION_DEFAULT_LABEL_INSTRUCTION']; + $payLaterInstruction = SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION_DEFAULT_LABEL_INSTRUCTION']; if ($values[$roles] == 0 && ($values[$rolesDefault]) == NULL) { $errors[$rolesDefault] = E::ts('Default Role is a required field'); @@ -87,12 +87,12 @@ public static function validateRules($values) { $errors[$paymentProcessorDefault] = E::ts('Please select at least one payment processor and/or enable the pay later option.'); } - if ($values[$payLaterOption] == 0 && isset($values[$paylaterOptionDefault]) && $values[$paylaterOptionDefault] == 1) { + if ($values[$payLaterOption] == 0 && isset($values[$payLaterOptionDefault]) && $values[$payLaterOptionDefault] == 1) { if ($values[$payLaterLabel] == NULL) { $errors[$payLaterLabel] = E::ts(' Please enter the Pay Later prompt to be displayed on the Registration form.'); } - if ($values[$payLaterInsuection] == NULL) { - $errors[$payLaterInsuection] = E::ts('Please enter the Pay Later instructions to be displayed to your users.'); + if ($values[$payLaterInstruction] == NULL) { + $errors[$payLaterInstruction] = E::ts('Please enter the Pay Later instructions to be displayed to your users.'); } } diff --git a/CRM/EventsExtras/SettingsManager.php b/CRM/EventsExtras/SettingsManager.php index 891bbd2..2cc976f 100644 --- a/CRM/EventsExtras/SettingsManager.php +++ b/CRM/EventsExtras/SettingsManager.php @@ -23,7 +23,7 @@ class CRM_EventsExtras_SettingsManager { 'PARTICIPANT_LISTING' => 'eventsextras_participant_listing', 'PARTICIPANT_LISTING_DEFAULT' => 'eventsextras_participant_listing_default', 'PARTICIPANT_SUMMARY' => 'eventsextras_event_summary', - 'EVENT_DESCRTIPTION' => 'eventsextras_event_description', + 'EVENT_DESCRIPTION' => 'eventsextras_event_description', 'INCLUDE_MAP_LOCATION_EVENT' => 'eventsextras_include_map_event_location', 'INCLUDE_MAP_LOCATION_EVENT_DEFAULT' => 'eventsextras_include_map_event_location_default', 'INCLUDE_MAP_PUBLIC_EVENT' => 'eventsextras_public_event', @@ -39,11 +39,11 @@ class CRM_EventsExtras_SettingsManager { 'PAY_LATER_OPTION_DEFAULT_BILLING_ADDRESS' => 'eventsextras_enable_pay_later_option_default_billing_address_required', 'PENDING_PARTICIPANT_EXPIRATION' => 'eventsextras_pending_participant_expiration', 'PENDING_PARTICIPANT_EXPIRATION_DEFAULT' => 'eventsextras_pending_participant_expiration_default', - 'ALLOW_SELF_SERIVCE' => 'eventsextras_allow_self_service', + 'ALLOW_SELF_SERVICE' => 'eventsextras_allow_self_service', 'ALLOW_SELF_SERVICE_DEFAULT' => 'eventsextras_allow_self_service_default', 'ALLOW_SELF_SERVICE_DEFAULT_TIME_LIMIT' => 'eventsextras_allow_self_service_default_time_limit', 'REGISTER_MULTIPLE_PARTICIPANTS' => 'eventsextras_register_multiple_participants', - 'REGISTER_MULTIPLE_PARTICIPANTS_DEFULT' => 'eventsextras_register_multiple_participants_default', + 'REGISTER_MULTIPLE_PARTICIPANTS_DEFAULT' => 'eventsextras_register_multiple_participants_default', 'REGISTER_MULTIPLE_PARTICIPANTS_DEFAULT_MAXIMUM_PARTICIPANT' => 'eventsextras_register_multiple_participants_default_maximum_participant', ]; diff --git a/eventsextras.php b/eventsextras.php index c125121..407e188 100644 --- a/eventsextras.php +++ b/eventsextras.php @@ -206,4 +206,4 @@ function eventsextras_civicrm_navigationMenu(&$menu) { 'separator' => 0, )); _eventsextras_civix_navigationMenu($menu); -} +} diff --git a/settings/EventsExtrasDefault.setting.php b/settings/EventsExtrasDefault.setting.php index 4f9cf45..8561b57 100644 --- a/settings/EventsExtrasDefault.setting.php +++ b/settings/EventsExtrasDefault.setting.php @@ -258,7 +258,7 @@ 'help_text' => '', 'extra_attributes' => [ 'section' => SettingsManager::EVENT_REGISTRATION, - 'parent_setting' => SettingsManager::SETTING_FIELDS['ALLOW_SELF_SERIVCE'], + 'parent_setting' => SettingsManager::SETTING_FIELDS['ALLOW_SELF_SERVICE'], 'event_form_element_name' => 'allow_selfcancelxfer', ], ], @@ -277,7 +277,7 @@ 'help_text' => '', 'extra_attributes' => [ 'section' => SettingsManager::EVENT_REGISTRATION, - 'parent_setting' => SettingsManager::SETTING_FIELDS['ALLOW_SELF_SERIVCE'], + 'parent_setting' => SettingsManager::SETTING_FIELDS['ALLOW_SELF_SERVICE'], 'event_form_element_name' => 'selfcancelxfer_time', ], ], diff --git a/tests/phpunit/CRM/EventsExtras/SettingsManagerTest.php b/tests/phpunit/CRM/EventsExtras/SettingsManagerTest.php index d897fc8..2b420f6 100644 --- a/tests/phpunit/CRM/EventsExtras/SettingsManagerTest.php +++ b/tests/phpunit/CRM/EventsExtras/SettingsManagerTest.php @@ -20,7 +20,6 @@ public function testGetSettingValue() { $this->assertNotEmpty($locationTab); } - /** * Tests getSettingsValue */ @@ -32,7 +31,6 @@ public function testGetSettingsValue() { $this->assertArrayHasKey(SettingsManager::SETTING_FIELDS['PCP_TAB'], $settings); $this->assertArrayHasKey(SettingsManager::SETTING_FIELDS['ROLES'], $settings); $this->assertArrayHasKey(SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION_DEFAULT'], $settings); - } /** @@ -71,5 +69,4 @@ public function testGetConfigFields() { $this->assertEquals(8, count($configFields)); } - } From 3c89fd88d64503fc4c4527d313a07afb70f181d7 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Mon, 6 Jul 2020 11:18:55 +0100 Subject: [PATCH 88/97] MAE-326: Add Setting Test Fabricator --- CRM/EventsExtras/Test/Fabricator/Setting.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 CRM/EventsExtras/Test/Fabricator/Setting.php diff --git a/CRM/EventsExtras/Test/Fabricator/Setting.php b/CRM/EventsExtras/Test/Fabricator/Setting.php new file mode 100644 index 0000000..fca379f --- /dev/null +++ b/CRM/EventsExtras/Test/Fabricator/Setting.php @@ -0,0 +1,17 @@ + $value) { + \Civi::settings()->set($key, $value); + } + } + +} From c9913460741ff0320ff98917bc3ef2dd5d1ce3d2 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Mon, 6 Jul 2020 11:23:51 +0100 Subject: [PATCH 89/97] MAE-326: Add ManageEvent Form Pre Hook Test --- .../EventsExtras/Hook/Pre/ManageEventTest.php | 124 ++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 tests/phpunit/CRM/EventsExtras/Hook/Pre/ManageEventTest.php diff --git a/tests/phpunit/CRM/EventsExtras/Hook/Pre/ManageEventTest.php b/tests/phpunit/CRM/EventsExtras/Hook/Pre/ManageEventTest.php new file mode 100644 index 0000000..02844a9 --- /dev/null +++ b/tests/phpunit/CRM/EventsExtras/Hook/Pre/ManageEventTest.php @@ -0,0 +1,124 @@ + 2, + 'is_public' => NULL, + 'is_map' => NULL, + 'participant_listing_id' => NULL, + ]; + + //Fabricate settings if user select field to hide and set default value + SettingFabricator::fabricate([ + SettingsManager::SETTING_FIELDS['INCLUDE_MAP_LOCATION_EVENT'] => 0, + SettingsManager::SETTING_FIELDS['INCLUDE_MAP_LOCATION_EVENT_DEFAULT'] => 1, + SettingsManager::SETTING_FIELDS['INCLUDE_MAP_PUBLIC_EVENT'] => 0, + SettingsManager::SETTING_FIELDS['INCLUDE_MAP_PUBLIC_EVENT_DEFAULT'] => 1, + ]); + + //Fabricate settings if user to show field and default value was set. + //In this case default should not be assigned to to the param; + SettingFabricator::fabricate([ + SettingsManager::SETTING_FIELDS['PARTICIPANT_LISTING'] => 1, + SettingsManager::SETTING_FIELDS['PARTICIPANT_LISTING_DEFAULT'] => 1, + ]); + + //make sure participant listing default is set + $participantListingDefault = SettingsManager::getSettingValue( SettingsManager::SETTING_FIELDS['PARTICIPANT_LISTING_DEFAULT']); + $this->assertEquals(1, $participantListingDefault[SettingsManager::SETTING_FIELDS['PARTICIPANT_LISTING_DEFAULT']]); + + $preManageEventHook = new CRM_EventsExtras_Hook_Pre_ManageEvent(); + $preManageEventHook->handle('create', 'Event', NULL, $params); + + $this->assertEquals(1, $params['is_public']); + $this->assertEquals(1, $params['is_map']); + + $this->assertNull(NULL); + + } + + public function testEventFee() { + + $params = [ + 'is_monetary' => 1, + 'payment_processor' => NULL, + 'currency' => NULL, + 'is_pay_later' => NULL, + 'pay_later_text' => NULL, + 'pay_later_receipt' => NULL, + 'is_billing_required' => NULL, + ]; + + SettingFabricator::fabricate([ + SettingsManager::SETTING_FIELDS['CURRENCY'] => 0, + SettingsManager::SETTING_FIELDS['CURRENCY_DEFAULT'] => 1, + SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION'] => 0, + SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION_DEFAULT'] => [7, 8], + SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION'] => 0, + SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION_DEFAULT'] => 1, + SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION_DEFAULT_LABEL'] => 'Test Label', + SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION_DEFAULT_LABEL_INSTRUCTION'] => 'Test Instruction', + SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION_DEFAULT_BILLING_ADDRESS'] => 1, + ]); + + $preManageEventHook = new CRM_EventsExtras_Hook_Pre_ManageEvent(); + $preManageEventHook->handle('edit', 'Event', '1', $params); + + $this->assertEquals(1, $params['currency']); + //payment processor should remain NULl as we are not set payment process on Pre Hook' + $this->assertNull($params['payment_processor']); + $this->assertEquals(1, $params['is_pay_later']); + $this->assertEquals('Test Label', $params['pay_later_text']); + $this->assertEquals('Test Instruction', $params['pay_later_receipt']); + $this->assertEquals(1, $params['is_billing_required']); + + } + + public function testEventOnlineRegistration() { + + $params = [ + 'is_online_registration'=> 1, + 'expiration_time' => NULL, + 'allow_selfcancelxfer' => NULL, + 'selfcancelxfer_time' => NULL, + 'is_multiple_registrations' => NULL, + 'max_additional_participants' => NULL, + ]; + + SettingFabricator::fabricate([ + SettingsManager::SETTING_FIELDS['PENDING_PARTICIPANT_EXPIRATION'] => 0, + SettingsManager::SETTING_FIELDS['PENDING_PARTICIPANT_EXPIRATION_DEFAULT'] => 24, + SettingsManager::SETTING_FIELDS['ALLOW_SELF_SERVICE'] => 0, + SettingsManager::SETTING_FIELDS['ALLOW_SELF_SERVICE_DEFAULT'] => 1, + SettingsManager::SETTING_FIELDS['ALLOW_SELF_SERVICE_DEFAULT_TIME_LIMIT'] => 48, + SettingsManager::SETTING_FIELDS['REGISTER_MULTIPLE_PARTICIPANTS'] => 0, + SettingsManager::SETTING_FIELDS['REGISTER_MULTIPLE_PARTICIPANTS_DEFAULT'] => 1, + SettingsManager::SETTING_FIELDS['REGISTER_MULTIPLE_PARTICIPANTS_DEFAULT_MAXIMUM_PARTICIPANT'] => 9, + ]); + + $preManageEventHook = new CRM_EventsExtras_Hook_Pre_ManageEvent(); + $preManageEventHook->handle('edit', 'Event', '1', $params); + + $this->assertEquals(24, $params['expiration_time']); + $this->assertEquals(1, $params['allow_selfcancelxfer']); + $this->assertEquals(48, $params['selfcancelxfer_time']); + $this->assertEquals(1, $params['is_multiple_registrations']); + $this->assertEquals(9, $params['max_additional_participants']); + + } +} From feeee3825c06ccc201808f26564649e8853ccadf Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Mon, 6 Jul 2020 11:24:18 +0100 Subject: [PATCH 90/97] MAE-326: Fix the values on event fee tab have not been saved on pre hook --- CRM/EventsExtras/Hook/Pre/ManageEvent.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CRM/EventsExtras/Hook/Pre/ManageEvent.php b/CRM/EventsExtras/Hook/Pre/ManageEvent.php index 061f8d6..a620ecd 100644 --- a/CRM/EventsExtras/Hook/Pre/ManageEvent.php +++ b/CRM/EventsExtras/Hook/Pre/ManageEvent.php @@ -82,7 +82,7 @@ private function preProcessData($section, &$params) { } } foreach ($fieldToProcess as $field => $value) { - if ($section != SettingsManager::EVENT_FEE && $field != 'payment_processor') { + if ($field != 'payment_processor') { $params[$field] = $value; } } From 47add733f7760091552a072f32ae9824709c92ce Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Mon, 6 Jul 2020 11:24:41 +0100 Subject: [PATCH 91/97] MAE-326: Add Event Fee BuildForm Hook Test --- .../Hook/BuildForm/EventFeeTest.php | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/phpunit/CRM/EventsExtras/Hook/BuildForm/EventFeeTest.php diff --git a/tests/phpunit/CRM/EventsExtras/Hook/BuildForm/EventFeeTest.php b/tests/phpunit/CRM/EventsExtras/Hook/BuildForm/EventFeeTest.php new file mode 100644 index 0000000..d93a3c4 --- /dev/null +++ b/tests/phpunit/CRM/EventsExtras/Hook/BuildForm/EventFeeTest.php @@ -0,0 +1,45 @@ +eventFeeForm = new CRM_Event_Form_ManageEvent_Fee(); + $this->eventFeeForm->controller = $formController; + $this->eventFeeForm->buildForm(); + } + + public function testSetDefault() { + $this->assertNull($this->eventFeeForm->getElementValue('payment_processor')[0]); + + SettingFabricator::fabricate([ + SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION'] => 0, + SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION_DEFAULT'] => [3, 5], + ]); + + $eventFeeFormHook = new CRM_EventsExtras_Hook_BuildForm_EventFee(); + $eventFeeFormHook->handle('CRM_Event_Form_ManageEvent_Fee', $this->eventFeeForm); + + $this->assertEquals( + [3, 5], + array_keys($this->eventFeeForm->_defaultValues['payment_processor']) + ); + } + +} From 5ba724f894d99fc738754832a4db84d3afd34070 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Mon, 6 Jul 2020 11:24:58 +0100 Subject: [PATCH 92/97] MAE-326: Add Event Info BuildForm Hook Test --- .../Hook/BuildForm/EventInfoTest.php | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/phpunit/CRM/EventsExtras/Hook/BuildForm/EventInfoTest.php diff --git a/tests/phpunit/CRM/EventsExtras/Hook/BuildForm/EventInfoTest.php b/tests/phpunit/CRM/EventsExtras/Hook/BuildForm/EventInfoTest.php new file mode 100644 index 0000000..7414c99 --- /dev/null +++ b/tests/phpunit/CRM/EventsExtras/Hook/BuildForm/EventInfoTest.php @@ -0,0 +1,45 @@ +eventInfoForm = new CRM_Event_Form_ManageEvent_EventInfo(); + $this->eventInfoForm->controller = $formController; + } + + public function testSetDefault() { + $formController = new CRM_Core_Controller(); + $eventInfoForm = new CRM_Event_Form_ManageEvent_EventInfo(); + $eventInfoForm->controller = $formController; + $eventInfoForm->buildForm(); + + $this->assertNull($eventInfoForm->getElementValue('default_role_id')[0]); + + SettingFabricator::fabricate([ + SettingsManager::SETTING_FIELDS['ROLES'] => 0, + SettingsManager::SETTING_FIELDS['ROLES_DEFAULT'] => 3, + ]); + + $eventInfoFormHook = new CRM_EventsExtras_Hook_BuildForm_EventInfo(); + $eventInfoFormHook->handle('CRM_Event_Form_ManageEvent_EventInfo', $eventInfoForm); + + $this->assertEquals(3, $eventInfoForm->getElementValue('default_role_id')[0]); + } + +} From 3ac086d9ec65f2ca19dfdb05fa70e8a5bc51f3a4 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Mon, 6 Jul 2020 11:31:59 +0100 Subject: [PATCH 93/97] MAE-326: Fix bad code on ManageEventTest --- tests/phpunit/CRM/EventsExtras/Hook/Pre/ManageEventTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/CRM/EventsExtras/Hook/Pre/ManageEventTest.php b/tests/phpunit/CRM/EventsExtras/Hook/Pre/ManageEventTest.php index 02844a9..8f1d431 100644 --- a/tests/phpunit/CRM/EventsExtras/Hook/Pre/ManageEventTest.php +++ b/tests/phpunit/CRM/EventsExtras/Hook/Pre/ManageEventTest.php @@ -12,7 +12,6 @@ */ class CRM_EventsExtras_Hook_Pre_ManageEventTest extends BaseHeadlessTest { - public function testEventInfo() { //fake params @@ -39,7 +38,7 @@ public function testEventInfo() { ]); //make sure participant listing default is set - $participantListingDefault = SettingsManager::getSettingValue( SettingsManager::SETTING_FIELDS['PARTICIPANT_LISTING_DEFAULT']); + $participantListingDefault = SettingsManager::getSettingValue(SettingsManager::SETTING_FIELDS['PARTICIPANT_LISTING_DEFAULT']); $this->assertEquals(1, $participantListingDefault[SettingsManager::SETTING_FIELDS['PARTICIPANT_LISTING_DEFAULT']]); $preManageEventHook = new CRM_EventsExtras_Hook_Pre_ManageEvent(); @@ -92,7 +91,7 @@ public function testEventFee() { public function testEventOnlineRegistration() { $params = [ - 'is_online_registration'=> 1, + 'is_online_registration' => 1, 'expiration_time' => NULL, 'allow_selfcancelxfer' => NULL, 'selfcancelxfer_time' => NULL, @@ -121,4 +120,5 @@ public function testEventOnlineRegistration() { $this->assertEquals(9, $params['max_additional_participants']); } + } From 337d3c670eeac4251f1f8698d3cbbc0224b17fac Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Mon, 6 Jul 2020 17:43:32 +0100 Subject: [PATCH 94/97] MAE-326: Remove setup function on EventInfoTest and fix passing the actual value to assertion method --- .../CRM/EventsExtras/Hook/BuildForm/EventInfoTest.php | 6 ------ tests/phpunit/CRM/EventsExtras/Hook/Pre/ManageEventTest.php | 6 +++--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/tests/phpunit/CRM/EventsExtras/Hook/BuildForm/EventInfoTest.php b/tests/phpunit/CRM/EventsExtras/Hook/BuildForm/EventInfoTest.php index 7414c99..e472438 100644 --- a/tests/phpunit/CRM/EventsExtras/Hook/BuildForm/EventInfoTest.php +++ b/tests/phpunit/CRM/EventsExtras/Hook/BuildForm/EventInfoTest.php @@ -17,12 +17,6 @@ class CRM_EventsExtras_Hook_BuildForm_EventInfoTest extends BaseHeadlessTest { */ private $eventInfoForm; - public function setUp() { - $formController = new CRM_Core_Controller(); - $this->eventInfoForm = new CRM_Event_Form_ManageEvent_EventInfo(); - $this->eventInfoForm->controller = $formController; - } - public function testSetDefault() { $formController = new CRM_Core_Controller(); $eventInfoForm = new CRM_Event_Form_ManageEvent_EventInfo(); diff --git a/tests/phpunit/CRM/EventsExtras/Hook/Pre/ManageEventTest.php b/tests/phpunit/CRM/EventsExtras/Hook/Pre/ManageEventTest.php index 8f1d431..1cc53f8 100644 --- a/tests/phpunit/CRM/EventsExtras/Hook/Pre/ManageEventTest.php +++ b/tests/phpunit/CRM/EventsExtras/Hook/Pre/ManageEventTest.php @@ -30,8 +30,8 @@ public function testEventInfo() { SettingsManager::SETTING_FIELDS['INCLUDE_MAP_PUBLIC_EVENT_DEFAULT'] => 1, ]); - //Fabricate settings if user to show field and default value was set. - //In this case default should not be assigned to to the param; + //Fabricate settings if user select to show field and default value was set. + //In this case default should not be assigned to the param; SettingFabricator::fabricate([ SettingsManager::SETTING_FIELDS['PARTICIPANT_LISTING'] => 1, SettingsManager::SETTING_FIELDS['PARTICIPANT_LISTING_DEFAULT'] => 1, @@ -47,7 +47,7 @@ public function testEventInfo() { $this->assertEquals(1, $params['is_public']); $this->assertEquals(1, $params['is_map']); - $this->assertNull(NULL); + $this->assertNull($params['participant_listing_id']); } From a803c7a55cda64d4df38e7c6a47e8f138671d272 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Thu, 9 Jul 2020 12:31:45 +0100 Subject: [PATCH 95/97] MAE-324: Fix spelling --- settings/EventsExtras.setting.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/settings/EventsExtras.setting.php b/settings/EventsExtras.setting.php index 32a45b7..e4a7978 100644 --- a/settings/EventsExtras.setting.php +++ b/settings/EventsExtras.setting.php @@ -25,7 +25,7 @@ ], 'eventsextras_tell_friend_tab' => [ 'name' => 'eventsextras_tell_friend_tab', - 'title' => ts('Tell Friend Tab'), + 'title' => ts('Tell a Friend Tab'), 'type' => 'Boolean', 'quick_form_type' => 'YesNo', 'default' => TRUE, @@ -42,7 +42,7 @@ ], 'eventsextras_pcp_tab' => [ 'name' => 'eventsextras_pcp_tab', - 'title' => ts('Personal Compaings Tab'), + 'title' => ts('Personal Campaigns Tab'), 'type' => 'Boolean', 'quick_form_type' => 'YesNo', 'default' => TRUE, From 5b470fdbd2c497b45cfeaf1d34cf64ae973aa73b Mon Sep 17 00:00:00 2001 From: Omar abu hussein Date: Thu, 16 Jul 2020 19:38:40 +0100 Subject: [PATCH 96/97] MAE-324: Remove commented out code --- eventsextras.php | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/eventsextras.php b/eventsextras.php index 407e188..9ee6102 100644 --- a/eventsextras.php +++ b/eventsextras.php @@ -34,21 +34,6 @@ function eventsextras_civicrm_pre($op, $objectName, $id, &$params) { } } -/** - * Implements hook_civicrm_pre(). - * - * @link hhttps://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_tab/ - */ -function eventsextras_civicrm_tab(&$tabs, $contactID) { - /*$listeners = [ - new CRM_EventsExtras_Hook_Pre_ManageEvent(), - ]; - foreach ($listeners as $currentListener) { - $currentListener->handle((&$tabs, $contactID); - }*/ - -} - /** * Implements hook_civicrm_config(). * @@ -180,17 +165,6 @@ function eventsextras_civicrm_entityTypes(&$entityTypes) { _eventsextras_civix_civicrm_entityTypes($entityTypes); } -// --- Functions below this ship commented out. Uncomment as required. --- - -/** - * Implements hook_civicrm_preProcess(). - * - * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_preProcess - * - * function eventsextras_civicrm_preProcess($formName, &$form) { - * -} // */ - /** * Implements hook_civicrm_navigationMenu(). * From 097f6e921e6c15d91e9d872e10faabb8cb1f8e80 Mon Sep 17 00:00:00 2001 From: Omar abu hussein Date: Thu, 16 Jul 2020 19:38:56 +0100 Subject: [PATCH 97/97] MAE-324: bump version for 1.0.0 release --- info.xml | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/info.xml b/info.xml index 94c5b51..6d28528 100644 --- a/info.xml +++ b/info.xml @@ -5,21 +5,19 @@ This extensions allows CiviCRM admin to config generic Event pages AGPL-3.0 - Compucorp Ltd. - hello@compucorp.co.uk - - - https://github.com/compucorp/uk.co.compucorp.eventsextras - https://github.com/compucorp/uk.co.compucorp.eventsextras/blob/master/readme.md - http://FIXME - https://github.com/compucorp/uk.co.compucorp.eventsextras/blob/master/readme.md - - 2019-06-12 - 1.0.0-alpha1 - + Compucropt Ltd. + info@compucorp.co.uk + c + 2020-07-16 + 1.0.0 + stable - 5.8+ + 5.24 + + Supported CiviCRM versions : + - 5.24.6 + CRM/EventsExtras