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

Fet/add toggle display copy info option #1555

Merged
merged 6 commits into from
Sep 11, 2019
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,11 @@ protected function _reg_form_settings()
array($this, 'email_validation_settings_form'),
2
);
add_action(
'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template',
array($this, 'copy_attendee_info_settings_form'),
4
);
$this->_template_args = (array) apply_filters(
'FHEE__Extend_Registration_Form_Admin_Page___reg_form_settings___template_args',
$this->_template_args
Expand Down Expand Up @@ -1124,6 +1129,9 @@ protected function _update_reg_form_settings()
EE_Registry::instance()->CFG->registration = $this->update_email_validation_settings_form(
EE_Registry::instance()->CFG->registration
);
EE_Registry::instance()->CFG->registration = $this->update_copy_attendee_info_settings_form(
EE_Registry::instance()->CFG->registration
);
EE_Registry::instance()->CFG->registration = apply_filters(
'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration',
EE_Registry::instance()->CFG->registration
Expand All @@ -1144,6 +1152,112 @@ protected function _update_reg_form_settings()
}


/**
* @return void
* @throws EE_Error
* @throws InvalidArgumentException
* @throws InvalidDataTypeException
* @throws InvalidInterfaceException
*/
public function copy_attendee_info_settings_form()
{
echo $this->_copy_attendee_info_settings_form()->get_html();
}

/**
* _copy_attendee_info_settings_form
*
* @access protected
* @return EE_Form_Section_Proper
* @throws \EE_Error
*/
protected function _copy_attendee_info_settings_form()
{
return new EE_Form_Section_Proper(
array(
'name' => 'copy_attendee_info_settings',
'html_id' => 'copy_attendee_info_settings',
'layout_strategy' => new EE_Admin_Two_Column_Layout(),
'subsections' => apply_filters(
'FHEE__Extend_Registration_Form_Admin_Page___copy_attendee_info_settings_form__form_subsections',
array(
'copy_attendee_info_hdr' => new EE_Form_Section_HTML(
EEH_HTML::h2(esc_html__('Copy Attendee Info Settings', 'event_espresso'))
),
'copy_attendee_info' => new EE_Yes_No_Input(
array(
'html_label_text' => esc_html__(
'Allow copy #1 attendee info to extra attendees?',
'event_espresso'
),
'html_help_text' => esc_html__(
'Set to yes if you want to enable the copy of #1 attendee info to extra attendees at Registration Form.',
'event_espresso'
),
'default' => EE_Registry::instance()->CFG->registration->copyAttendeeInfo(),
'required' => false,
'display_html_label_text' => false,
)
),
)
),
)
);
}

/**
* @param EE_Registration_Config $EE_Registration_Config
* @return EE_Registration_Config
* @throws EE_Error
* @throws InvalidArgumentException
* @throws ReflectionException
* @throws InvalidDataTypeException
* @throws InvalidInterfaceException
*/
public function update_copy_attendee_info_settings_form(EE_Registration_Config $EE_Registration_Config)
{
$prev_copy_attendee_info = $EE_Registration_Config->copyAttendeeInfo();
try {
$copy_attendee_info_settings_form = $this->_copy_attendee_info_settings_form();
// if not displaying a form, then check for form submission
if ($copy_attendee_info_settings_form->was_submitted()) {
// capture form data
$copy_attendee_info_settings_form->receive_form_submission();
// validate form data
if ($copy_attendee_info_settings_form->is_valid()) {
// grab validated data from form
$valid_data = $copy_attendee_info_settings_form->valid_data();
if (isset($valid_data['copy_attendee_info'])) {
$EE_Registration_Config->setCopyAttendeeInfo($valid_data['copy_attendee_info']);
} else {
EE_Error::add_error(
esc_html__(
'Invalid or missing Copy Attendee Info settings. Please refresh the form and try again.',
'event_espresso'
),
__FILE__,
__FUNCTION__,
__LINE__
);
}
} else {
if ($copy_attendee_info_settings_form->submission_error_message() !== '') {
EE_Error::add_error(
$copy_attendee_info_settings_form->submission_error_message(),
__FILE__,
__FUNCTION__,
__LINE__
);
}
}
}
} catch (EE_Error $e) {
$e->get_error();
}
return $EE_Registration_Config;
}


/**
* @return void
* @throws EE_Error
Expand Down
28 changes: 28 additions & 0 deletions core/EE_Config.core.php
Original file line number Diff line number Diff line change
Expand Up @@ -2332,6 +2332,13 @@ class EE_Registration_Config extends EE_Config_Base
*/
public $gateway_log_lifespan = '1 week';

/**
* Enable copy attendee info at form
*
* @var boolean $enable_copy_attendee
*/
protected $copy_attendee_info = true;


/**
* class constructor
Expand Down Expand Up @@ -2362,6 +2369,7 @@ public function __construct()
$this->consent_checkbox_enabled = false;
$this->consent_checkbox_label_text = '';
$this->gateway_log_lifespan = '7 days';
$this->copy_attendee_info = true;
}


Expand Down Expand Up @@ -2460,6 +2468,26 @@ public function set_track_invalid_checkout_access($track_invalid_checkout_access
);
}

/**
* @return boolean
*/
public function copyAttendeeInfo()
{
return $this->copy_attendee_info;
}


/**
* @param boolean $copy_attendee_info
*/
public function setCopyAttendeeInfo($copy_attendee_info)
{
$this->copy_attendee_info = filter_var(
$copy_attendee_info,
FILTER_VALIDATE_BOOLEAN
);
}


/**
* Gets the options to make availalbe for the gateway log lifespan
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,12 @@ public function initialize_reg_step()
*/
public function generate_reg_form()
{
$this->_print_copy_info = false;
/**
* @var $reg_config EE_Registration_Config
*/
$reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config');

$this->_print_copy_info = $reg_config->copyAttendeeInfo();
$primary_registrant = null;
// autoload Line_Item_Display classes
EEH_Autoloader::register_line_item_display_autoloaders();
Expand All @@ -137,10 +142,6 @@ public function generate_reg_form()
'default_hidden_inputs' => $extra_inputs_section,
);

/**
* @var $reg_config EE_Registration_Config
*/
$reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config');
// if this isn't a revisit, and they have the privacy consent box enalbed, add it
if (! $this->checkout->revisit && $reg_config->isConsentCheckboxEnabled()) {
$extra_inputs_section->add_subsections(
Expand Down Expand Up @@ -212,10 +213,7 @@ public function generate_reg_form()
}
}
}
// print_copy_info ?
if ($primary_registrant && ! $this->checkout->admin_request && count($registrations) > 1) {
// TODO: add admin option for toggling copy attendee info,
// then use that value to change $this->_print_copy_info
$copy_options['spco_copy_attendee_chk'] = $this->_print_copy_info
? $this->_copy_attendee_info_form()
: $this->_auto_copy_attendee_info();
Expand Down Expand Up @@ -322,8 +320,14 @@ private function _registrations_reg_form(EE_Registration $registration)
$form_args['subsections']['additional_attendee_reg_info'] = $this->_additional_attendee_reg_info_input(
$registration
);

/**
* @var $reg_config EE_Registration_Config
*/
$reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config');

// if we have question groups for additional attendees, then display the copy options
$this->_print_copy_info = $attendee_nmbr > 1 ? true : $this->_print_copy_info;
$this->_print_copy_info = $attendee_nmbr > 1 ? $reg_config->copyAttendeeInfo() : false;
if ($registration->is_primary_registrant()) {
// generate hidden input
$form_args['subsections']['primary_registrant'] = $this->_additional_primary_registrant_inputs(
Expand Down