diff --git a/booking.install b/booking.install index 4ba54f0..af3e96c 100644 --- a/booking.install +++ b/booking.install @@ -140,7 +140,7 @@ function booking_update_7202() { * Add tables for study group calculations */ function booking_update_7203() { - //This lists all the study group sessions + //This lists all the study groups $booking_studygroup_list = array( 'fields' => array( 'sid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'), @@ -158,6 +158,7 @@ function booking_update_7203() { 'booking_eventid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'), 'booking_node_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'), 'booking_studygroup_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'), + 'booking_session_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'), 'booking_is_leader' => array('type' => 'varchar', 'length' => '1', 'not null' => FALSE), 'booking_is_helper' => array('type' => 'varchar', 'length' => '1', 'not null' => FALSE), ), @@ -239,6 +240,14 @@ function booking_update_7205() { } +/** +* Add another field to the booking_studygroup_mapping table +*/ +function booking_update_7206() { + $spec = array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10', 'default' => 0); + db_add_field( 'booking_studygroup_mapping', 'booking_session_id', $spec); +} + /** * Implementation of hook_install(). diff --git a/booking.studygroups.inc b/booking.studygroups.inc index af318ac..b167c90 100644 --- a/booking.studygroups.inc +++ b/booking.studygroups.inc @@ -236,6 +236,8 @@ function booking_studygroups_calculate() { $person->processed = 0; //field that indicates the session id the person is assigned to $person->session = 0; + $person->is_leader = 0; + $person->is_helper = 0; //convert NULLs into zero $person->booking_total_lead = $person->booking_total_lead === NULL ? '0' : $person->booking_total_lead; $person->booking_available_lead = $person->booking_available_lead === NULL ? '0' : $person->booking_available_lead; @@ -318,6 +320,7 @@ function booking_studygroups_calculate() { //assign leader to session and mark as processed in the temporary attendee list $current->session = $session_id; $current->processed = 1; + $current->is_leader = 1; //decrement the number of available leading positions for this user in our master copy of the attendee list $attendees[$it->key()]->booking_available_lead = $attendees[$it->key()]->booking_available_lead - 1; @@ -343,7 +346,8 @@ function booking_studygroups_calculate() { //assign leader to session and mark as processed in the temporary attendee list $current->session = $session_id; - $current->processed = 1; + $current->processed = 1; + $current->is_helper = 1; //decrement the number of available helping positions for this user in our master copy of the attendee list $attendees[$it->key()]->booking_available_help = $attendees[$it->key()]->booking_available_help - 1; @@ -432,6 +436,28 @@ 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 + + //TODO: a check to update existing records rather than inserting new ones + + $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')); + + foreach($working_list as $person) + { + $record = array( + 'booking_eventid' => $event->eid, + 'booking_node_id' => $person->nid, + 'booking_studygroup_id' => $group->sid, + 'booking_session_id' => $person->session, + 'booking_is_leader' => $person->is_leader, + 'booking_is_helper' => $person->is_helper, + ); + $query->values($record); + + } + $query->execute(); + + } //finished processing study groups //watchdog('booking', "Attendee list final version: @info", array('@info' => var_export($attendees, TRUE)));