Added db write to study group calcs
This commit is contained in:
@@ -140,7 +140,7 @@ function booking_update_7202() {
|
|||||||
* Add tables for study group calculations
|
* Add tables for study group calculations
|
||||||
*/
|
*/
|
||||||
function booking_update_7203() {
|
function booking_update_7203() {
|
||||||
//This lists all the study group sessions
|
//This lists all the study groups
|
||||||
$booking_studygroup_list = array(
|
$booking_studygroup_list = array(
|
||||||
'fields' => array(
|
'fields' => array(
|
||||||
'sid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
|
'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_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_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_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_leader' => array('type' => 'varchar', 'length' => '1', 'not null' => FALSE),
|
||||||
'booking_is_helper' => 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().
|
* Implementation of hook_install().
|
||||||
|
@@ -236,6 +236,8 @@ function booking_studygroups_calculate() {
|
|||||||
$person->processed = 0;
|
$person->processed = 0;
|
||||||
//field that indicates the session id the person is assigned to
|
//field that indicates the session id the person is assigned to
|
||||||
$person->session = 0;
|
$person->session = 0;
|
||||||
|
$person->is_leader = 0;
|
||||||
|
$person->is_helper = 0;
|
||||||
//convert NULLs into zero
|
//convert NULLs into zero
|
||||||
$person->booking_total_lead = $person->booking_total_lead === NULL ? '0' : $person->booking_total_lead;
|
$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;
|
$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
|
//assign leader to session and mark as processed in the temporary attendee list
|
||||||
$current->session = $session_id;
|
$current->session = $session_id;
|
||||||
$current->processed = 1;
|
$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
|
//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;
|
$attendees[$it->key()]->booking_available_lead = $attendees[$it->key()]->booking_available_lead - 1;
|
||||||
@@ -344,6 +347,7 @@ function booking_studygroups_calculate() {
|
|||||||
//assign leader to session and mark as processed in the temporary attendee list
|
//assign leader to session and mark as processed in the temporary attendee list
|
||||||
$current->session = $session_id;
|
$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
|
//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;
|
$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
|
//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
|
//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
|
} //finished processing study groups
|
||||||
|
|
||||||
//watchdog('booking', "Attendee list final version: @info", array('@info' => var_export($attendees, TRUE)));
|
//watchdog('booking', "Attendee list final version: @info", array('@info' => var_export($attendees, TRUE)));
|
||||||
|
Reference in New Issue
Block a user