study group bugfixes

This commit is contained in:
2014-04-29 19:14:04 +10:00
parent 0ff5b531eb
commit eb3fa7e7bf
4 changed files with 47 additions and 22 deletions

View File

@@ -601,6 +601,13 @@ function booking_shuffle_assoc($list) {
*/
function booking_assign_attendee_group($nid, $session_id, $gender, $age, &$attendee_list, &$session_count)
{
if (empty($nid))
{
drupal_set_message(t('Attempting to process a non-existent node id.'));
return;
}
//mark this person as processed in the working list
$attendee_list[$nid]->processed = 1;
$attendee_list[$nid]->session = $session_id;
@@ -646,7 +653,7 @@ function booking_studygroups_calculate() {
$firstgroup = reset($studygroups);
$limit = variable_get('booking_regn_limit','500');
//add an extra one to the maximum size, to cater for some larger groups when the number of people doesn't divide evenly
$max_people = (int) ($limit / $firstgroup->booking_num_group_sessions) + 1;
$max_people = (int) ($limit / $firstgroup->booking_num_group_sessions) + 2;
//select all the attendees booked in
$query = db_query("SELECT * FROM {booking_person} WHERE booking_event_id = :eid",
@@ -693,6 +700,8 @@ function booking_studygroups_calculate() {
$person->is_reserveleader = 'N';
}
//watchdog('booking', "<pre>Attendee list:\n@info</pre>", array('@info' => print_r( $attendees, true)));
//watchdog('booking', "Attendee list: @info", array('@info' => var_export($attendees, TRUE)));
//process each study group (eg Monday Tuesday Wednesday etc)
@@ -762,11 +771,11 @@ function booking_studygroups_calculate() {
_booking_get_age_years($working_list[$bf_gf_id]->booking_dob), $working_list, $session_count);
}
}
}
} //end searching for leaders and helpers
//watchdog('booking', "Attendee list working copy after leader/helper spouse processing: @info", array('@info' => var_export($working_list, TRUE)));
//watchdog('booking', "Attendee list session count after leader/helper spouse processing: @info", array('@info' => var_export($session_count, TRUE)));
//return;
//return;
//reset the iterator to starting position
$it->rewind();
@@ -817,13 +826,13 @@ function booking_studygroups_calculate() {
$age_type = 'over25';
//make sure this person is going to fit in with our calculated gender ratios
_booking_loop_carefully($session_count, $gender, $i, $maximums[$gender], $group->booking_num_group_sessions, 2);
_booking_loop_carefully($session_count, $gender, $i, $maximums[$gender], $group->booking_num_group_sessions, 3);
//make sure this person is going to fit in with our calculated age ratios
_booking_loop_carefully($session_count, $age_type, $i, $maximums[$age_type], $group->booking_num_group_sessions, 2);
_booking_loop_carefully($session_count, $age_type, $i, $maximums[$age_type], $group->booking_num_group_sessions, 3);
//check for maximum group size
_booking_loop_carefully($session_count, 'total', $i, $max_people, $group->booking_num_group_sessions, 2);
_booking_loop_carefully($session_count, 'total', $i, $max_people, $group->booking_num_group_sessions, 3);
//assign this attendee to this session if unprocessed so far
if ($current->processed == 0)
@@ -855,18 +864,19 @@ function booking_studygroups_calculate() {
drupal_set_message(t('Assigning bf/gf (id !spouse) of id !id to session !session (currently with !num people).',
array('!id' => $it->key(), '!session' => $i, '!spouse' => $current->booking_bf_gf_nid, '!num' => $session_count[$i]['total'])));
booking_assign_attendee_group($partner_id, $i, $working_list[$bf_gf_id]->booking_gender == 'M' ? 'male' : 'female',
booking_assign_attendee_group($bf_gf_id, $i, $working_list[$bf_gf_id]->booking_gender == 'M' ? 'male' : 'female',
_booking_get_age_years($working_list[$bf_gf_id]->booking_dob), $working_list, $session_count);
}
}
//move to the next unprocessed attendee in the list
while ($it->valid() && $it->current()->processed == 1)
{
//drupal_set_message(t("Skipping attendee ID !id, already processed.", array('!id' => $it->key())));
$it->next();
}
//move to the next session
$i++;
} //finished looping through attendees for this study group
@@ -875,11 +885,11 @@ function booking_studygroups_calculate() {
//iterate over the attendee list and write to the database the session they're assigned to
//use the multi-insert query type at https://drupal.org/node/310079
$insert_query = db_insert('booking_studygroup_mapping')->fields(array('booking_eventid', 'booking_node_id',
'booking_studygroup_id', 'booking_session_id', 'booking_is_leader', 'booking_is_helper'));
'booking_studygroup_id', 'booking_session_id', 'booking_is_leader', 'booking_is_helper', 'booking_is_reserveleader'));
foreach($working_list as $person)
{
//watchdog('booking', "<pre>Working list person:\n@info</pre>", array('@info' => print_r( $person, true)));
watchdog('booking', "<pre>Working list person:\n@info</pre>", array('@info' => print_r( $person, true)));
//TODO: a check to update existing records rather than inserting new one
// if already in $group_mapping then just run an update query here
@@ -916,7 +926,6 @@ function booking_studygroups_calculate() {
//drupal_set_message(t('Found no existing study group session for user id !id. Adding to list of inserts.',
// array('!id' => $person->nid, '!sid' => $mapping->sid, '!session' => $person->session)));
$record = array(
'booking_eventid' => $event->eid,
'booking_node_id' => $person->nid,
@@ -930,14 +939,17 @@ function booking_studygroups_calculate() {
}
}
//$insert_query->execute();
$insert_query->execute();
watchdog('booking', "<pre>Attendee list:\n@info</pre>", array('@info' => print_r( $session_count, true)));
watchdog('booking', "<pre>Session statistics list:\n@info</pre>", array('@info' => print_r( $session_count, true)));
//clear the arrays we've been using for this iteration
unset($session_count);
unset($working_list);
drupal_set_message(t('Finished processing study group !group.', array('!group' => $group->booking_studygroup_descrip)));
} //finished processing study groups
//watchdog('booking', "Attendee list final version: @info", array('@info' => var_export($attendees, TRUE)));