fix errors generated with no attendees

This commit is contained in:
2014-11-18 17:58:34 +11:00
parent c42503523e
commit 7098d26756
3 changed files with 19 additions and 10 deletions

View File

@@ -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)