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

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

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)

View File

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