Add maximum age restriction to registration form

This commit is contained in:
2015-03-18 11:53:52 +11:00
parent 034785d70c
commit 5aa285e9dc
4 changed files with 88 additions and 23 deletions

View File

@@ -74,12 +74,22 @@ function booking_admin() {
$form['attendee']['booking_max_dob'] = array ( $form['attendee']['booking_max_dob'] = array (
'#type' => 'date_select', '#type' => 'date_select',
'#title' => t('Maximum Date of Birth'), '#title' => t('Maximum Date of Birth'),
'#description' => t("The most recent date of birth you wish to allow into the event."), '#description' => t("The youngest date of birth you wish to allow into the event."),
'#default_value' => variable_get('booking_max_dob','1995-04-15 00:00:00'), '#default_value' => variable_get('booking_max_dob','1995-04-15 00:00:00'),
'#date_format' => 'd/m/Y', '#date_format' => 'd/m/Y',
'#date_label_position' => 'within', '#date_label_position' => 'within',
'#date_year_range' => '-60:-10' '#date_year_range' => '-60:-10'
); );
$form['attendee']['booking_min_dob'] = array (
'#type' => 'date_select',
'#title' => t('Minimum Date of Birth'),
'#description' => t("The oldest date of birth you wish to allow into the event."),
'#default_value' => variable_get('booking_min_dob','1995-04-15 00:00:00'),
'#date_format' => 'd/m/Y',
'#date_label_position' => 'within',
'#date_year_range' => '-60:-10'
);
$form['attendee']['booking_regn_limit'] = array ( $form['attendee']['booking_regn_limit'] = array (
'#type' => 'textfield', '#type' => 'textfield',

View File

@@ -336,6 +336,43 @@ function _booking_max_dob_ts()
return mktime(12, 0, 0, $max_dob_matches[2], $max_dob_matches[3], $max_dob_matches[1]); return mktime(12, 0, 0, $max_dob_matches[2], $max_dob_matches[3], $max_dob_matches[1]);
} }
/**
* Helper function to calculate the year offset between the start of event and a
*
* @param $datetime Date to compare from date_select field
* @return integer containing difference in years
*/
function _booking_year_offset($datetime)
{
global $event;
//set the time zone
date_default_timezone_set(date_default_timezone(FALSE));
$tz = new DateTimeZone(date_default_timezone(FALSE));
//try to load the date
try {
//$date = new DateTime(variable_get('booking_min_dob','1970-01-01 00:00:00'));
$date = new DateTime($datetime);
} catch (Exception $e) {
$date = new DateTime('1970-01-01 00:00:00');
}
//set the timezone for the date
$date->setTimezone($tz);
//watchdog('booking', '<pre>DateTime of minimum DOB:\n @info </pre>', array('@info' => print_r( $date, true)));
$reference_date = _booking_convert_ts($event->booking_event_start);
$difference = $date->diff($reference_date);
//watchdog('booking', '<pre>DateTime of difference in minimum DOB to start of event:\n @info </pre>', array('@info' => print_r( $difference, true)));
return $difference->y;
}
/** /**
* Helper function to calculate the average age in days, months and years at the start of the event * Helper function to calculate the average age in days, months and years at the start of the event
*/ */
@@ -369,6 +406,9 @@ function _booking_get_age_years($dob_ts)
return $dob->diff($reference_ts)->y; return $dob->diff($reference_ts)->y;
} }
/**
* Helper function to create a string describing a date range
*/
function _date_range_to_string($date_start, $date_end) { function _date_range_to_string($date_start, $date_end) {
$start = _booking_split_date($date_start); $start = _booking_split_date($date_start);
$end = _booking_split_date($date_end); $end = _booking_split_date($date_end);

View File

@@ -49,26 +49,6 @@ function booking_register_page() {
return $return_array; return $return_array;
} }
/**
* Landing page after returning from paypal
*/
function booking_payment_completed_page() {
//get some configuration information
global $event;
$output = "";
$return_array = array();
//set the page title
$bookingTitle = !empty($event->booking_eventname) ? $event->booking_eventname : 'Event';
drupal_set_title($bookingTitle . ' Registration Completed');
$output = token_replace(variable_get('booking_regn_completed_page'), booking_define_tokens());
$return_array[] = array('paragraph' => array('#type' => 'markup', '#markup' => $output));
return $return_array;
}
function booking_form($node, &$form_state, $inserting = FALSE) { function booking_form($node, &$form_state, $inserting = FALSE) {
global $event; global $event;
@@ -77,6 +57,12 @@ function booking_form($node, &$form_state, $inserting = FALSE) {
$partner_options = array(); $partner_options = array();
date_default_timezone_set(date_default_timezone(FALSE)); date_default_timezone_set(date_default_timezone(FALSE));
//calculate what years to show in the date of birth field
$min_dob_years = _booking_year_offset(variable_get('booking_min_dob','1970-01-01 00:00:00'));
$max_dob_years = _booking_year_offset(variable_get('booking_max_dob','1970-01-01 00:00:00'));
$date_year_range = "-" . $min_dob_years . ':-' . $max_dob_years;
//determine whether loading saved node or form submission
if (!empty($node)) if (!empty($node))
{ {
$data = $node; $data = $node;
@@ -93,11 +79,13 @@ function booking_form($node, &$form_state, $inserting = FALSE) {
'legal_guardian' => 'Legal Guardian', 'legal_guardian' => 'Legal Guardian',
'relative' => 'Close Relative'); 'relative' => 'Close Relative');
/*
$status_options[0] = t('Not Paid'); $status_options[0] = t('Not Paid');
$status_options[1] = t('Booked In'); $status_options[1] = t('Booked In');
$status_options[2] = t('Waiting List'); $status_options[2] = t('Waiting List');
$status_options[3] = t('No Longer Coming'); $status_options[3] = t('No Longer Coming');
*/
//figure out if we're in the earlybird rate section //figure out if we're in the earlybird rate section
$early = db_query("SELECT booking_earlybird_close FROM {booking_event} where eid = :eid", array( $early = db_query("SELECT booking_earlybird_close FROM {booking_event} where eid = :eid", array(
':eid' => $event->eid)) ':eid' => $event->eid))
@@ -158,8 +146,14 @@ function booking_form($node, &$form_state, $inserting = FALSE) {
'#date_format' => 'd/m/Y', '#date_format' => 'd/m/Y',
'#date_label_position' => 'within', '#date_label_position' => 'within',
'#date_year_range' => '-50:-13' '#date_year_range' => '-50:-13'
//'#date_year_range' => $date_year_range,
); );
//override our generous date year range if this is a new form submission
if ($inserting == TRUE) {
$form['your-details']['booking_dob']['#date_year_range'] = $date_year_range;
}
$form['your-details']['booking_payment_id'] = array( $form['your-details']['booking_payment_id'] = array(
'#type' => 'select', '#type' => 'select',
'#title' => t('Choose your payment type'), '#title' => t('Choose your payment type'),
@@ -1265,3 +1259,24 @@ function _booking_form_submit_post_triggers($node) {
} }
} }
/**
* Landing page after returning from paypal
*/
function booking_payment_completed_page() {
//get some configuration information
global $event;
$output = "";
$return_array = array();
//set the page title
$bookingTitle = !empty($event->booking_eventname) ? $event->booking_eventname : 'Event';
drupal_set_title($bookingTitle . ' Registration Completed');
$output = token_replace(variable_get('booking_regn_completed_page'), booking_define_tokens());
$return_array[] = array('paragraph' => array('#type' => 'markup', '#markup' => $output));
return $return_array;
}

View File

@@ -114,7 +114,7 @@ function booking_load($nodes) {
} }
} }
//watchdog('booking', 'Final loaded node: @info', array('@info' => var_export($nodes, TRUE))); watchdog('booking', 'Final loaded node: @info', array('@info' => var_export($nodes, TRUE)));
// no return necessary since $nodes array members reference objects global to this function // no return necessary since $nodes array members reference objects global to this function
} }