diff --git a/booking.module b/booking.module index ec49adc..7f7144c 100644 --- a/booking.module +++ b/booking.module @@ -389,7 +389,16 @@ function booking_menu() { 'page arguments' => array('booking_studygroups_update'), 'access arguments' => array('edit study groups'), 'type' => MENU_LOCAL_ACTION, - ); + ); + + $items['admin/booking/studygroups/colours'] = array( + 'title' => 'Process Reading Group Colours', + 'description' => 'Update the reading group colour based on the studygroup id', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('booking_studygroups_process_colours'), + 'access arguments' => array('edit study groups'), + 'type' => MENU_LOCAL_ACTION, + ); } //configure rooms diff --git a/booking.studygroups.inc b/booking.studygroups.inc index 3ca6a7c..067c546 100644 --- a/booking.studygroups.inc +++ b/booking.studygroups.inc @@ -13,7 +13,7 @@ function booking_studygroups_view_summary() { global $event; $output = ""; $header = array('Link','Study Group', 'Session Count', 'Select Leaders'); - $attributes = array('style' => 'max-width:30%'); + $attributes = array('style' => 'max-width:40%'); //get study groups $query = db_select('booking_studygroup_list', 's') @@ -1529,8 +1529,37 @@ function booking_studygroups_view_form($node, &$form_state, $group_id) { ), 'form' => $form, ); - - - - +} + + +/** + * Function for updating the reading group colour based on the id automatically generated for them + */ +function booking_studygroups_process_colours() { + global $event; + + //hard code this value for now - it's the id of the special study group that is actually the reading group + $readinggroup_studygroup_id = 7; + + //query for the mappings relating to $readinggroup_studygroup_id + $group_mapping_query = db_query("SELECT * FROM {booking_studygroup_mapping} WHERE booking_eventid = :eid AND booking_studygroup_id = :sid", + array(':eid' => $event->eid, ':sid' => $readinggroup_studygroup_id)); + $group_mapping = $group_mapping_query->fetchAll(); + + + foreach ($group_mapping as $mapping) + { + $colour = _booking_readinggroup_colour_lookup($mapping->booking_session_id); + + drupal_set_message(t('Updating user !id to be in team !colour.', + array('!id' => $mapping->booking_node_id, '!colour' => $colour))); + + //run an update query + db_update('booking_person') + ->fields(array ( + 'booking_readinggroup' => $colour, + )) + ->condition('nid', $mapping->booking_node_id) + ->execute(); + } }