From 57b9b065df1033956e289c020590a339c142b53b Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Thu, 26 Jun 2014 23:44:53 +1000 Subject: [PATCH] quick tidy up --- booking.studygroups.inc | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/booking.studygroups.inc b/booking.studygroups.inc index d720e4b..215ef57 100644 --- a/booking.studygroups.inc +++ b/booking.studygroups.inc @@ -1300,20 +1300,17 @@ function booking_studygroups_update_form($node, &$form_state, $sid) { //now calculate the updates for the database foreach($working_list as $person) - { - //watchdog('booking', "
Working list role person:\n@info
", array('@info' => print_r( $person, true))); - - //check to update existing records rather than inserting new one - // if already in $group_mapping then just run an update query here - + { $found = FALSE; $message = ""; + //iterate all the groups for each person foreach ($group_mapping as $mapping) { //check if we can find a study group session already for this user and this study group (eg Monday Tuesday or Wednesday) if ($person->nid == $mapping->booking_node_id && $group->sid == $mapping->booking_studygroup_id) { + //keep track of our success to avoid doing an insert $found = TRUE; //if the existing session is not the same as our newly calculated session, run an update query @@ -1329,18 +1326,7 @@ function booking_studygroups_update_form($node, &$form_state, $sid) { ); $updates_to_confirm[] = array('sid' => $mapping->sid, 'fields' => $update); - - //update the entry - /* - db_update('booking_studygroup_mapping') - ->fields(array( - 'booking_session_id' => $person->session, - 'booking_studygroup_role' => $person->booking_studygroup_role, - )) - ->condition('sid', $mapping->sid) - ->execute(); - */ - + } elseif ($mapping->booking_session_id !== $person->session && $group->sid == $reading_group_id) { @@ -1356,7 +1342,7 @@ function booking_studygroups_update_form($node, &$form_state, $sid) { $updates_to_confirm[] = array('sid' => $mapping->sid, 'fields' => $update); } - //stop looping through the list + //stop looping through the list since we found a match break; } //end checking for existing group session @@ -1475,7 +1461,7 @@ function booking_studygroups_update_form_submit($form, &$form_state) { //watchdog('booking', "Updated sid !sid affecting !rows rows.", array('!sid' => $update['sid'], '!rows' => $rows)); } - //handle the database inserts using the multi-insert query type at https://drupal.org/node/310079 + //process the inserts using 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_studygroup_role'));