Renamed function _split_date, added average age calculation to summary report
This commit is contained in:
@@ -185,7 +185,7 @@ function _datetime_array_to_ts($date)
|
|||||||
|
|
||||||
|
|
||||||
function _date_to_ts($date) {
|
function _date_to_ts($date) {
|
||||||
$date_split = _split_date($date);
|
$date_split = _booking_split_date($date);
|
||||||
|
|
||||||
date_default_timezone_set(TIMEZONE);
|
date_default_timezone_set(TIMEZONE);
|
||||||
$tz = new DateTimeZone(TIMEZONE);
|
$tz = new DateTimeZone(TIMEZONE);
|
||||||
@@ -204,7 +204,7 @@ function _date_to_ts($date) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function _datetime_to_ts($date) {
|
function _datetime_to_ts($date) {
|
||||||
$date_split = _split_date($date);
|
$date_split = _booking_split_date($date);
|
||||||
|
|
||||||
date_default_timezone_set(TIMEZONE);
|
date_default_timezone_set(TIMEZONE);
|
||||||
$tz = new DateTimeZone(TIMEZONE);
|
$tz = new DateTimeZone(TIMEZONE);
|
||||||
@@ -228,7 +228,7 @@ function _datetime_to_ts($date) {
|
|||||||
* @param $date in format YYYY-MM-DD
|
* @param $date in format YYYY-MM-DD
|
||||||
* @return array containing Year, Month, Day
|
* @return array containing Year, Month, Day
|
||||||
*/
|
*/
|
||||||
function _split_date($date) {
|
function _booking_split_date($date) {
|
||||||
$pattern = '/^(\d{4})-(\d{2})-(\d{2})(\s(\d{2})\:(\d{2}))?/';
|
$pattern = '/^(\d{4})-(\d{2})-(\d{2})(\s(\d{2})\:(\d{2}))?/';
|
||||||
if (preg_match($pattern, $date, $matches)) {
|
if (preg_match($pattern, $date, $matches)) {
|
||||||
return $matches;
|
return $matches;
|
||||||
@@ -267,9 +267,20 @@ function _booking_convert_ts($timestamp)
|
|||||||
return $date;
|
return $date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to ensure timestamp is converted to correct local time
|
||||||
|
*/
|
||||||
|
function _booking_max_dob_ts()
|
||||||
|
{
|
||||||
|
//calculate DOB limit as defined by configuration
|
||||||
|
$max_dob_matches = _booking_split_date(variable_get('booking_max_dob','0'));
|
||||||
|
return mktime(12, 0, 0, $max_dob_matches[2], $max_dob_matches[3], $max_dob_matches[1]);
|
||||||
|
}
|
||||||
|
|
||||||
function _date_range_to_string($date_start, $date_end) {
|
function _date_range_to_string($date_start, $date_end) {
|
||||||
$start = _split_date($date_start);
|
$start = _booking_split_date($date_start);
|
||||||
$end = _split_date($date_end);
|
$end = _booking_split_date($date_end);
|
||||||
$final_string = '';
|
$final_string = '';
|
||||||
|
|
||||||
//check for correctly formatted dates
|
//check for correctly formatted dates
|
||||||
|
@@ -796,12 +796,8 @@ function _booking_validate($node, &$form_state) {
|
|||||||
if (strlen(trim($email)) > 0 && !_valid_email_address($email))
|
if (strlen(trim($email)) > 0 && !_valid_email_address($email))
|
||||||
form_set_error('booking_email', t('You must enter a valid e-mail address. Please ensure you typed your email address correctly.'));
|
form_set_error('booking_email', t('You must enter a valid e-mail address. Please ensure you typed your email address correctly.'));
|
||||||
|
|
||||||
//calculate DOB limit as defined by configuration
|
|
||||||
$max_dob_matches = _split_date(variable_get('booking_max_dob','0'));
|
|
||||||
|
|
||||||
$max_dob_check= mktime(12, 0, 0, $max_dob_matches[2], $max_dob_matches[3], $max_dob_matches[1]);
|
|
||||||
//if DOB on form is more recent than DOB limit, display validation error
|
//if DOB on form is more recent than DOB limit, display validation error
|
||||||
if ($dob_check > $max_dob_check)
|
if ($dob_check > _booking_max_dob_ts())
|
||||||
form_set_error('booking_dob', t('Unfortunately you are too young to attend !event.',
|
form_set_error('booking_dob', t('Unfortunately you are too young to attend !event.',
|
||||||
array('!event' => variable_get('booking_event_name','this event'))));
|
array('!event' => variable_get('booking_event_name','this event'))));
|
||||||
|
|
||||||
|
@@ -6,8 +6,9 @@
|
|||||||
*/
|
*/
|
||||||
function booking_report_summary() {
|
function booking_report_summary() {
|
||||||
global $event;
|
global $event;
|
||||||
$text = "";
|
//$text = "";
|
||||||
$output = "";
|
$output = "";
|
||||||
|
$non_australia_count = 0;
|
||||||
$bookedin_counter = 0;
|
$bookedin_counter = 0;
|
||||||
$notpaid_counter = 0;
|
$notpaid_counter = 0;
|
||||||
$waiting_counter = 0;
|
$waiting_counter = 0;
|
||||||
@@ -16,19 +17,22 @@ function booking_report_summary() {
|
|||||||
$baptised_count = 0;
|
$baptised_count = 0;
|
||||||
$married_count = 0;
|
$married_count = 0;
|
||||||
$total_paid = 0;
|
$total_paid = 0;
|
||||||
|
$dob_total = 0;
|
||||||
|
$person_count = 0;
|
||||||
|
$average = 0;
|
||||||
|
$average_age = "";
|
||||||
|
//$year = 60 * 60 * 24 * 365.25;
|
||||||
$stats_attributes = array('style' => 'max-width:30%');
|
$stats_attributes = array('style' => 'max-width:30%');
|
||||||
|
|
||||||
$header = array('Id', 'Name', 'Email', 'Payment To Date', 'Total Payment Required');
|
$header = array('Id', 'Name', 'Email', 'Payment To Date', 'Total Payment Required');
|
||||||
$rows = array();
|
$rows = array();
|
||||||
|
$state_header = array('State', 'Count');
|
||||||
$result = db_query("SELECT * FROM {booking_person} p WHERE p.booking_event_id = :eid",
|
$state_rows = array();
|
||||||
array(':eid' => $event->eid));
|
$ecclesia_heaeder = array('State','Ecclesia', 'Count');
|
||||||
|
$ecclesia_rows = array();
|
||||||
|
|
||||||
//do some analysis about the people booked in
|
//do some analysis about the people booked in
|
||||||
//first the summary of states
|
//first the summary of states
|
||||||
$state_header = array('State', 'Count');
|
|
||||||
$state_rows = array();
|
|
||||||
$non_australia_count = 0;
|
|
||||||
$query = db_select('booking_person', 'p')
|
$query = db_select('booking_person', 'p')
|
||||||
->fields('p', array('booking_state', 'booking_country'))
|
->fields('p', array('booking_state', 'booking_country'))
|
||||||
->condition('p.booking_event_id', $event->eid, '=');
|
->condition('p.booking_event_id', $event->eid, '=');
|
||||||
@@ -47,12 +51,15 @@ function booking_report_summary() {
|
|||||||
|
|
||||||
//general stats
|
//general stats
|
||||||
$query = db_select('booking_person', 'p')
|
$query = db_select('booking_person', 'p')
|
||||||
->fields('p', array('booking_baptised', 'booking_married', 'booking_gender'))
|
->fields('p', array('booking_baptised', 'booking_married', 'booking_gender', 'booking_dob'))
|
||||||
->condition('p.booking_event_id', $event->eid, '=');
|
->condition('p.booking_event_id', $event->eid, '=');
|
||||||
$general_stats = $query->execute();
|
$general_stats = $query->execute();
|
||||||
|
|
||||||
foreach ($general_stats as $person)
|
foreach ($general_stats as $person)
|
||||||
{
|
{
|
||||||
|
$dob_total += $person->booking_dob;
|
||||||
|
$person_count++;
|
||||||
|
|
||||||
if ($person->booking_gender == 'M')
|
if ($person->booking_gender == 'M')
|
||||||
$male_count++;
|
$male_count++;
|
||||||
else
|
else
|
||||||
@@ -65,9 +72,12 @@ function booking_report_summary() {
|
|||||||
$married_count++;
|
$married_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//calculate the average age timestamp
|
||||||
|
$average = $dob_total / $person_count;
|
||||||
|
//convert that to years
|
||||||
|
$average_age = floor((time() - $average) / (60 * 60 * 24 * 365.25));
|
||||||
|
|
||||||
//bookings by ecclesia
|
//bookings by ecclesia
|
||||||
$ecclesia_heaeder = array('State','Ecclesia', 'Count');
|
|
||||||
$ecclesia_rows = array();
|
|
||||||
$query = db_select('booking_person', 'p')
|
$query = db_select('booking_person', 'p')
|
||||||
->fields('p', array('booking_ecclesia','booking_state'))
|
->fields('p', array('booking_ecclesia','booking_state'))
|
||||||
->condition('p.booking_event_id', $event->eid, '=');
|
->condition('p.booking_event_id', $event->eid, '=');
|
||||||
@@ -82,6 +92,8 @@ function booking_report_summary() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//more detailed summary
|
//more detailed summary
|
||||||
|
$result = db_query("SELECT * FROM {booking_person} p WHERE p.booking_event_id = :eid",
|
||||||
|
array(':eid' => $event->eid));
|
||||||
foreach ($result as $person) {
|
foreach ($result as $person) {
|
||||||
$rows[] = array(
|
$rows[] = array(
|
||||||
l(t('!id', array('!id' => $person->nid)), t('node/!id', array('!id' => $person->nid))),
|
l(t('!id', array('!id' => $person->nid)), t('node/!id', array('!id' => $person->nid))),
|
||||||
@@ -101,17 +113,19 @@ function booking_report_summary() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//output everything
|
//output everything
|
||||||
$output .= t("<p>There are !boys males and !girls females registered. Of these, !baptised are baptised and !married are married.</p>",
|
$output .= t("<p>There are !boys males and !girls females registered. Of these, !baptised are baptised and !married are married. The average age is !average years.",
|
||||||
array('!boys' => $male_count, '!girls' => $female_count, '!baptised' => $baptised_count, '!married' => $married_count));
|
array('!boys' => $male_count, '!girls' => $female_count, '!baptised' => $baptised_count, '!married' => $married_count
|
||||||
$output .= t("<p>Bookings by state</p>");
|
'!average' => $average_age));
|
||||||
$output .= theme('table', array('header' => $state_header, 'rows' => $state_rows, 'attributes' => $stats_attributes));
|
$output .= t("Total of !bookedin registrations currently booked in, !waiting on waiting list, and !notpaid haven't paid.<br />",
|
||||||
$output .= t("<p>Bookings by ecclesia</p>");
|
|
||||||
$output .= theme('table', array('header' => $ecclesia_heaeder, 'rows' => $ecclesia_rows, 'attributes' => $stats_attributes));
|
|
||||||
$output .= t("<p>The following table presents a summary of payments that have been made for !event.</p>", array('!event' => $event->booking_eventname));
|
|
||||||
$output .= theme('table', array('header' => $header, 'rows' => $rows));
|
|
||||||
$output .= t("<p>Total of !bookedin registrations currently booked in, !waiting on waiting list, and !notpaid haven't paid.</p>",
|
|
||||||
array('!bookedin' => $bookedin_counter, '!waiting' => $waiting_counter, '!notpaid' => $notpaid_counter));
|
array('!bookedin' => $bookedin_counter, '!waiting' => $waiting_counter, '!notpaid' => $notpaid_counter));
|
||||||
$output .= t("<p>Total amount paid: $!paid</p>", array('!paid' => $total_paid));
|
$output .= t("Total amount paid: $!paid</p>", array('!paid' => $total_paid));
|
||||||
|
$output .= t("<h3>Bookings by state</h3>");
|
||||||
|
$output .= theme('table', array('header' => $state_header, 'rows' => $state_rows, 'attributes' => $stats_attributes));
|
||||||
|
$output .= t("<h3>Bookings by ecclesia</h3>");
|
||||||
|
$output .= theme('table', array('header' => $ecclesia_heaeder, 'rows' => $ecclesia_rows, 'attributes' => $stats_attributes));
|
||||||
|
$output .= t("<h3>Summary of attendees for !event.</h3>", array('!event' => $event->booking_eventname));
|
||||||
|
$output .= theme('table', array('header' => $header, 'rows' => $rows));
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user