From 7098d26756a08c4628825b5aa7fcea8a2de9a817 Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Tue, 18 Nov 2014 17:58:34 +1100 Subject: [PATCH] fix errors generated with no attendees --- booking.helper.inc | 9 ++------- booking.studygroups.inc | 19 ++++++++++++++++--- booking.studygroups_admin.inc | 1 + 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/booking.helper.inc b/booking.helper.inc index 2ed213e..8033c79 100644 --- a/booking.helper.inc +++ b/booking.helper.inc @@ -628,16 +628,12 @@ function _booking_rooms_cleanup($nid) /** * Function for cleaning up study groups by removing people that have withdrawn their registration - * @param $sid - the study group id to clean up + * @param nothing - processes all defined study groups for the current event * @return nothing */ -function _booking_studygroup_cleanup($sid) +function _booking_studygroup_cleanup() { global $event; - - //select any entries already in the mapping table - $group_mapping_query = db_query("SELECT * FROM {booking_studygroup_mapping} WHERE booking_eventid = :eid AND booking_studygroup_id = :sid", array(':eid' => $event->eid, ':sid' => $sid)); - $group_mapping = $group_mapping_query->fetchAllAssoc('sid'); //search for entries already in the mapping table that have a booking_status of 3 (not coming) $to_remove_query = db_query("SELECT m.* FROM {booking_studygroup_mapping} m @@ -668,7 +664,6 @@ function _booking_person_studygroups_cleanup($nid) { global $event; - //first of all make sure we need to do anything if (variable_get('booking_enable_studygroups', 0) == 1) { diff --git a/booking.studygroups.inc b/booking.studygroups.inc index e1a5e85..f1414c4 100644 --- a/booking.studygroups.inc +++ b/booking.studygroups.inc @@ -990,6 +990,10 @@ function booking_studygroups_update_form($node, &$form_state, $sid) { $studygroups_query = db_query("SELECT * FROM {booking_studygroup_list} WHERE sid = :sid", array(':sid' => $sid)); $studygroups = $studygroups_query->fetchAllAssoc('sid'); + //select any entries already in the mapping table + $group_mapping_query = db_query("SELECT * FROM {booking_studygroup_mapping} WHERE booking_eventid = :eid AND booking_studygroup_id = :sid", array(':eid' => $event->eid, ':sid' => $sid)); + $group_mapping = $group_mapping_query->fetchAllAssoc('sid'); + //throw an error if we got no groups if (! $studygroups) { @@ -1013,7 +1017,16 @@ function booking_studygroups_update_form($node, &$form_state, $sid) { //TODO: Move statistics generation to separate function //calculate the ratios of males to females, and various age groups $statistics = _booking_generate_statistics($attendees); - $gender_ratio = ($statistics['males'] / $statistics['females']) * ($max_people / 2); + + if ($statistics['males'] == 0 || $statistics['females'] == 0 || $max_people == 0) + { + $gender_ratio = 1; + } + else + { + $gender_ratio = ($statistics['males'] / $statistics['females']) * ($max_people / 2); + } + //really stretch the tolerances for placement by setting this to zero $fudge_factor = 0; //store our final maximums as an array for easy access later @@ -1025,8 +1038,8 @@ function booking_studygroups_update_form($node, &$form_state, $sid) { 'over25' => ceil(($statistics['over25'] / $limit) * ($max_people - $fudge_factor)), ); - //remove the mappings for these people no longer coming - _booking_studygroup_cleanup($sid); + //remove the mappings for people no longer coming + _booking_studygroup_cleanup(); //iterate over the attendee associative array and add some fields foreach ($attendees as $person) diff --git a/booking.studygroups_admin.inc b/booking.studygroups_admin.inc index 994d7f2..739128c 100644 --- a/booking.studygroups_admin.inc +++ b/booking.studygroups_admin.inc @@ -14,6 +14,7 @@ function booking_studygroups_admin() { global $event; $output = ""; $header = array('Study Group', 'Session Count', 'Reading Group?', 'Edit Definition'); + $rows = array(); $attributes = array('style' => 'max-width:60%'); //$attributes = array();