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

@@ -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]);
}
/**
* 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
*/
@@ -369,6 +406,9 @@ function _booking_get_age_years($dob_ts)
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) {
$start = _booking_split_date($date_start);
$end = _booking_split_date($date_end);