Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAE-398: Make showing/hiding events "same email address?" setting configurable #21

Merged
merged 11 commits into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ jobs:
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
run: civibuild create drupal-clean --civi-ver 5.28.3 --cms-ver 7.75 --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
version: 5.28.3
path: site/web/sites/all/modules/civicrm

- uses: actions/checkout@v2
Expand Down
53 changes: 32 additions & 21 deletions CRM/EventsExtras/Hook/BuildForm/BaseEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ abstract class CRM_EventsExtras_Hook_BuildForm_BaseEvent {
*/
protected $eventTab;

/**
* Event tab and class map
* @var eventTabAndClassMap
*/
protected $eventTabAndClassMap = [
SettingsManager::EVENT_INFO => 'crm-event-manage-eventinfo',
SettingsManager::EVENT_FEE => 'crm-event-manage-fee',
SettingsManager::EVENT_REGISTRATION => 'crm-event-manage-registration',
];

/**
* Constractor for BuildForm class
*
Expand All @@ -22,7 +32,6 @@ abstract class CRM_EventsExtras_Hook_BuildForm_BaseEvent {
*/
protected function __construct($eventTab) {
$this->eventTab = $eventTab;
$this->addEventTabTemplate();
}

/**
Expand All @@ -49,32 +58,34 @@ protected function shouldHandle($formName, $formClass) {
}

/**
* fuction to hide fields based on settings
* Hide fields on the Event Forms
*
* @param array $form
* @param array $fieldIds
*
*/
protected function hideField(&$form) {
$configFields = SettingsManager::getConfigFields($this->eventTab);
$settingsValue = SettingsManager::getSettingsValue();
$hiddenFields = [];

foreach ($configFields as $config) {
$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'];
}
protected function hideFields($fieldIds) {
$selectors = [];
foreach ($fieldIds as $fieldId) {
$class = $this->eventTabAndClassMap[$this->eventTab] . '-form-block-' . $fieldId;
$selectors[] = "tr[class={$class}]";
}
$form->assign('hiddenCssClasses', $hiddenFields);
$selectors = implode(', ', $selectors);

$this->hideElementBySelector($selectors);
}

private function addEventTabTemplate() {
$templatePath = E::path() . '/templates/CRM/EventsExtras/Form/EventTabs.tpl';
CRM_Core_Region::instance('page-body')->add([
'template' => "{$templatePath}",
]);
/**
* Hide elements by CSS selector
*
* @param string $selector
*
*/
protected function hideElementBySelector($selector) {
CRM_Core_Resources::singleton()->addScript(
"CRM.$(function($) {
$('{$selector}').hide();
});
");
}

}
38 changes: 34 additions & 4 deletions CRM/EventsExtras/Hook/BuildForm/EventFee.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public function handle($formName, &$form) {
if (!$this->shouldHandle($formName, CRM_Event_Form_ManageEvent_Fee::class)) {
return;
}
$this->hideField($form);
$this->buildForm($formName, $form);
}

Expand All @@ -34,15 +33,46 @@ private function buildForm($formName, &$form) {

private function setDefaults(&$form) {
$defaults = [];
$paymentProcessor = SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION'];
$fieldIdsToHide = [];

$showPaymentProcessor = SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION'];
$paymentProcessorDefault = SettingsManager::SETTING_FIELDS['PAYMENT_PROCESSOR_SELECTION_DEFAULT'];
$settings = [$paymentProcessor, $paymentProcessorDefault];
$settings = [$showPaymentProcessor, $paymentProcessorDefault];
$settingValues = SettingsManager::getSettingsValue($settings);
if ($settingValues[$paymentProcessor] == 0) {
if ($settingValues[$showPaymentProcessor] == 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;
$fieldIdsToHide[] = 'payment_processor';
}

$showCurrency = SettingsManager::SETTING_FIELDS['CURRENCY'];
$currencyDefault = SettingsManager::SETTING_FIELDS['CURRENCY_DEFAULT'];
$settings = [$showCurrency, $currencyDefault];
$settingValues = SettingsManager::getSettingsValue($settings);
if ($settingValues[$showCurrency] == 0) {
$defaults['currency'] = $settingValues[$currencyDefault];
$fieldIdsToHide[] = 'currency';
}

$showPayLater = SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION'];
$payLaterDefault = SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION_DEFAULT'];
$payLaterLabel = SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION_DEFAULT_LABEL'];
$payLaterInstruction = SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION_DEFAULT_LABEL_INSTRUCTION'];
$payLaterBillingAddress = SettingsManager::SETTING_FIELDS['PAY_LATER_OPTION_DEFAULT_BILLING_ADDRESS'];
$settings = [$showPayLater, $payLaterDefault, $payLaterLabel, $payLaterInstruction, $payLaterBillingAddress];
$settingValues = SettingsManager::getSettingsValue($settings);
if ($settingValues[$showPayLater] == 0) {
$defaults['is_pay_later'] = $settingValues[$payLaterDefault];
$defaults['pay_later_text'] = $settingValues[$payLaterLabel];
$defaults['pay_later_receipt'] = $settingValues[$payLaterInstruction];
$defaults['is_billing_required'] = $settingValues[$payLaterBillingAddress];
$fieldIdsToHide[] = 'is_pay_later';

$this->hideElementBySelector('#payLaterOptions');
}

$this->hideFields($fieldIdsToHide);
$form->setDefaults($defaults);
}

Expand Down
39 changes: 35 additions & 4 deletions CRM/EventsExtras/Hook/BuildForm/EventInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public function handle($formName, &$form) {
if (!$this->shouldHandle($formName, CRM_Event_Form_ManageEvent_EventInfo::class)) {
return;
}
$this->hideField($form);
$this->buildForm($formName, $form);
}

Expand All @@ -40,13 +39,45 @@ private function buildForm($formName, &$form) {
*/
private function setDefaults(&$form) {
$defaults = [];
$role = SettingsManager::SETTING_FIELDS['ROLES'];
$fieldIdsToHide = [];

$showRoles = SettingsManager::SETTING_FIELDS['ROLES'];
$roleDefault = SettingsManager::SETTING_FIELDS['ROLES_DEFAULT'];
$settings = [$role, $roleDefault];
$settings = [$showRoles, $roleDefault];
$settingValues = SettingsManager::getSettingsValue($settings);
if ($settingValues[$role] == 0) {
if ($settingValues[$showRoles] == 0) {
$defaults['default_role_id'] = $settingValues[$roleDefault];
$fieldIdsToHide[] = 'default_role_id';
}

$showParticipantListing = SettingsManager::SETTING_FIELDS['PARTICIPANT_LISTING'];
$participantListingDefault = SettingsManager::SETTING_FIELDS['PARTICIPANT_LISTING_DEFAULT'];
$settings = [$showParticipantListing, $participantListingDefault];
$settingValues = SettingsManager::getSettingsValue($settings);
if ($settingValues[$showParticipantListing] == 0) {
$defaults['participant_listing_id'] = $settingValues[$participantListingDefault];
$fieldIdsToHide[] = 'participant_listing_id';
}

$showIncludeMap = SettingsManager::SETTING_FIELDS['INCLUDE_MAP_LOCATION_EVENT'];
$includeMapDefault = SettingsManager::SETTING_FIELDS['INCLUDE_MAP_LOCATION_EVENT_DEFAULT'];
$settings = [$showIncludeMap, $includeMapDefault];
$settingValues = SettingsManager::getSettingsValue($settings);
if ($settingValues[$showIncludeMap] == 0) {
$defaults['is_map'] = $settingValues[$includeMapDefault];
$fieldIdsToHide[] = 'is_map';
}

$showPublicEvent = SettingsManager::SETTING_FIELDS['INCLUDE_MAP_PUBLIC_EVENT'];
$publicEventDefault = SettingsManager::SETTING_FIELDS['INCLUDE_MAP_PUBLIC_EVENT_DEFAULT'];
$settings = [$showPublicEvent, $publicEventDefault];
$settingValues = SettingsManager::getSettingsValue($settings);
if ($settingValues[$showPublicEvent] == 0) {
$defaults['is_public'] = $settingValues[$publicEventDefault];
$fieldIdsToHide[] = 'is_public';
}

$this->hideFields($fieldIdsToHide);
$form->setDefaults($defaults);
}

Expand Down
56 changes: 55 additions & 1 deletion CRM/EventsExtras/Hook/BuildForm/EventRegistration.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,61 @@ public function handle($formName, &$form) {
if (!$this->shouldHandle($formName, CRM_Event_Form_ManageEvent_Registration::class)) {
return;
}
$this->hideField($form);
$this->buildForm($formName, $form);
}

private function buildForm($formName, &$form) {
$this->setDefaults($form);
}

private function setDefaults(&$form) {
$defaults = [];
$fieldIdsToHide = [];

$showPendingParticipantExpiration = SettingsManager::SETTING_FIELDS['PENDING_PARTICIPANT_EXPIRATION'];
$pendingParticipantExpirationDefault = SettingsManager::SETTING_FIELDS['PENDING_PARTICIPANT_EXPIRATION_DEFAULT'];
$settings = [$showPendingParticipantExpiration, $pendingParticipantExpirationDefault];
$settingValues = SettingsManager::getSettingsValue($settings);
if ($settingValues[$showPendingParticipantExpiration] == 0) {
$defaults['expiration_time'] = $settingValues[$pendingParticipantExpirationDefault];
$fieldIdsToHide[] = 'expiration_time';
}

$showAllowSelfServiceAction = SettingsManager::SETTING_FIELDS['ALLOW_SELF_SERVICE'];
$allowSelfServiceActionDefault = SettingsManager::SETTING_FIELDS['ALLOW_SELF_SERVICE_DEFAULT'];
$timeLimit = SettingsManager::SETTING_FIELDS['ALLOW_SELF_SERVICE_DEFAULT_TIME_LIMIT'];
$settings = [$showAllowSelfServiceAction, $allowSelfServiceActionDefault, $timeLimit];
$settingValues = SettingsManager::getSettingsValue($settings);
if ($settingValues[$showAllowSelfServiceAction] == 0) {
$defaults['allow_selfcancelxfer'] = $settingValues[$allowSelfServiceActionDefault];
$defaults['selfcancelxfer_time'] = $settingValues[$timeLimit];

// @note allow_selfcancelxfer's parent tr in civicrm/templates/CRM/Event/Form/ManageEvent/Registration.tpl
// has a missing 'allow' i.e. "crm-event-manage-registration-form-block-selfcancelxfer" (CiviCRM bug)
$fieldIdsToHide[] = 'selfcancelxfer';
$fieldIdsToHide[] = 'selfcancelxfer_time';
}

$showRegisterMultipleParticipants = SettingsManager::SETTING_FIELDS['REGISTER_MULTIPLE_PARTICIPANTS'];
$registerMultipleParticipantsDefault = SettingsManager::SETTING_FIELDS['REGISTER_MULTIPLE_PARTICIPANTS_DEFAULT'];
$maximumParticipant = SettingsManager::SETTING_FIELDS['REGISTER_MULTIPLE_PARTICIPANTS_DEFAULT_MAXIMUM_PARTICIPANT'];
$allowSameParticipantEmailsDefault = SettingsManager::SETTING_FIELDS['REGISTER_MULTIPLE_PARTICIPANTS_ALLOW_SAME_PARTICIPANT_EMAILS_DEFAULT'];
$settings = [$showRegisterMultipleParticipants, $registerMultipleParticipantsDefault, $maximumParticipant, $allowSameParticipantEmailsDefault];
$settingValues = SettingsManager::getSettingsValue($settings);
if ($settingValues[$showRegisterMultipleParticipants] == 0) {
$defaults['is_multiple_registrations'] = $settingValues[$registerMultipleParticipantsDefault];
$defaults['max_additional_participants'] = $settingValues[$maximumParticipant];
$defaults['allow_same_participant_emails'] = $settingValues[$allowSameParticipantEmailsDefault];
$fieldIdsToHide[] = 'is_multiple_registrations';

// @note max_additional_participants's parent tr in civicrm/templates/CRM/Event/Form/ManageEvent/Registration.tpl
// has a 'maximum' in its name instead of max i.e. "crm-event-manage-registration-form-block-maximum_additional_participants" (CiviCRM bug)
$fieldIdsToHide[] = 'maximum_additional_participants';
$fieldIdsToHide[] = 'allow_same_participant_emails';
}

$this->hideFields($fieldIdsToHide);
$form->setDefaults($defaults);
}

}
1 change: 1 addition & 0 deletions CRM/EventsExtras/SettingsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class CRM_EventsExtras_SettingsManager {
'REGISTER_MULTIPLE_PARTICIPANTS' => 'eventsextras_register_multiple_participants',
'REGISTER_MULTIPLE_PARTICIPANTS_DEFAULT' => 'eventsextras_register_multiple_participants_default',
'REGISTER_MULTIPLE_PARTICIPANTS_DEFAULT_MAXIMUM_PARTICIPANT' => 'eventsextras_register_multiple_participants_default_maximum_participant',
'REGISTER_MULTIPLE_PARTICIPANTS_ALLOW_SAME_PARTICIPANT_EMAILS_DEFAULT' => 'eventsextras_register_multiple_participants_allow_same_participant_emails_default',
];

/**
Expand Down
42 changes: 42 additions & 0 deletions CRM/EventsExtras/Test/Fabricator/Base.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/**
* Class CRM_EventsExtras_Test_Fabricator_Base.
*/
abstract class CRM_EventsExtras_Test_Fabricator_Base {

/**
* Name of the entity to be fabricated.
*
* @var string
*/
protected static $entityName;

/**
* List of default parameters to use on fabrication of entities.
*
* @var array
*/
protected static $defaultParams = [];

/**
* Fabricates an instance of the entity with the given parameters.
*
* @param array $params
*
* @return mixed
* @throws \CiviCRM_API3_Exception
* @throws \Exception
*/
public static function fabricate(array $params = []) {
if (empty(static::$entityName)) {
throw new \Exception('Entity name cannot be empty!');
}

$params = array_merge(static::$defaultParams, $params);
$result = civicrm_api3(static::$entityName, 'create', $params);

return array_shift($result['values']);
}

}
63 changes: 63 additions & 0 deletions CRM/EventsExtras/Test/Fabricator/Event.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
use CRM_EventsExtras_Test_Fabricator_Base as BaseFabricator;

/**
* Class CRM_EventsExtras_Test_Fabricator_Event.
*/
class CRM_EventsExtras_Test_Fabricator_Event extends BaseFabricator {

/**
* Entity's name.
*
* @var string
*/
protected static $entityName = 'Event';

/**
* Array if default parameters to be used to create an event.
*
* @var array
*/
protected static $defaultParams = [
'title' => 'Event Sample' ,
];

/**
* Fabricates an event with the given parameters.
*
* @param array $params
*
* @return array
* @throws \CiviCRM_API3_Exception
*/
public static function fabricate(array $params = []) {
$startDate = new DateTime();

$eventType = self::createEvenType();
$eventTypeId = $eventType['value'];

$defaultParams = array_merge(static::$defaultParams, [
'start_date' => $startDate->format('Ymd'),
'event_type_id' => $eventTypeId,
]);

$params = array_merge($defaultParams, $params);

return parent::fabricate($params);
}

private static function createEvenType() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo : createEvenType should be createEventType (missing T)

$result = civicrm_api3('OptionValue', 'create', [
'option_group_id' => 'event_type',
'name' => 'Conference',
'label' => 'Conference',
'weight' => 1,
'is_active' => 1,
'is_reserved' => 1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no neeed for this to be reserved

]);
$eventType = array_shift($result['values']);

return $eventType;
}

}
2 changes: 1 addition & 1 deletion CRM/EventsExtras/Test/Fabricator/Setting.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* Class CRM_MventsExtras_Test_Fabricator_Setting
* Class CRM_EventsExtras_Test_Fabricator_Setting
*/
class CRM_EventsExtras_Test_Fabricator_Setting {

Expand Down
Loading