diff --git a/booking.admin.inc b/booking.admin.inc index 5e16506..afe1ab8 100644 --- a/booking.admin.inc +++ b/booking.admin.inc @@ -210,6 +210,13 @@ function booking_admin() { '#default_value' => variable_get('booking_dietary_text_definition', ''), '#description' => 'Text to use if attendee may not specify dietary requirements (as above).', ); + $form['misc']['booking_enable_roomallocations'] = array ( + '#type' => 'radios', + '#title' => t('Enable room allocations?'), + '#description' => t('Select whether to enable the management and allocation of rooms.'), + '#options' => array (0 => t('No'), t('Yes')), + '#default_value' => variable_get('booking_enable_roomallocations', 0), + ); $form['misc']['booking_enable_studygroups'] = array ( '#type' => 'radios', '#title' => t('Enable study group calculations?'), diff --git a/booking.helper.inc b/booking.helper.inc index ad94384..54cd5d0 100644 --- a/booking.helper.inc +++ b/booking.helper.inc @@ -422,6 +422,42 @@ function _booking_assign_attendee_group($nid, $session_id, $gender, $age, &$atte } +/** + * Function for cleaning up room allocations for people that have withdrawn their registration + * @param $nid - the node id for the person + * @return nothing + */ +function _booking_rooms_cleanup($nid) +{ + global $event; + + + //first of all make sure we need to do anything + if (variable_get('booking_enable_roomallocations', 0) == 1) + { + //should only be one room allocation per person, so no need to loop over the results + $room_mapping = db_query("SELECT * FROM {booking_room_mapping} WHERE booking_eventid = :eid AND booking_nodeid = :nid", + array(':eid' => $event->eid, ':nid' => $nid)) + ->fetchObject(); + + if ($room_mapping) + { + $message = t("Removing id !nid from room id !room.", + array('!nid' => $nid, '!room' => $room_mapping->booking_roomid) + ); + watchdog('booking', $message); + drupal_set_message($message, 'status', FALSE); + + db_delete('booking_room_mapping') + ->condition('booking_eventid', $event->eid) + ->condition('booking_nodeid', $nid) + ->execute(); + + + } //for each room + } //end check for room allocations enabled +} //end function + /** * Function for cleaning up study groups for people that have withdrawn their registration * @param $nid - the node id for the person who has withdrawn their registration @@ -472,10 +508,9 @@ function _booking_studygroups_cleanup($nid) ->condition('booking_node_id', $nid) ->condition('booking_studygroup_id', $group->booking_studygroup_id) ->execute(); - } - } - -} + } //for each group + } //end check for study groups enabled +} //end function /** * Function for calculating statistics of attendees diff --git a/booking.register.inc b/booking.register.inc index 5644194..c3a3e61 100644 --- a/booking.register.inc +++ b/booking.register.inc @@ -1379,6 +1379,9 @@ function _booking_update($node) { //Remove from any study groups _booking_studygroups_cleanup($node->nid); + //Remove from any rooms allocated + _booking_rooms_cleanup($node->nid); + //check if there is room on the booked-in list if (_booking_check_bookings_full() == False) { diff --git a/booking.rooms.inc b/booking.rooms.inc index 4e2324a..f75f970 100644 --- a/booking.rooms.inc +++ b/booking.rooms.inc @@ -194,18 +194,24 @@ function booking_rooms_allocate_form($node, &$form_state, $location_id) { return ""; } - //make a list of all attendees - $attendee_select[] = ''; + //query for existing room allocations + $room_mapping_query = db_query("SELECT * FROM {booking_room_mapping} WHERE booking_eventid = :eid", array(':eid' => $event->eid)); + //$room_mapping = $room_mapping_query->fetchAll(); + $room_mapping = $room_mapping_query->fetchAllAssoc('booking_nodeid'); $query = db_query("SELECT nid, booking_firstname, booking_lastname, booking_gender, booking_dob, booking_partner_id FROM {booking_person} " . "where booking_event_id = :eid and booking_status=1 order by booking_lastname, booking_firstname", array(':eid' => $event->eid)); + + //make a list of all attendees that are booked in + $attendee_select[] = ''; foreach($query as $row) { $married = $row->booking_partner_id > 0 ? ' *' : ''; $age = _booking_get_age_years($row->booking_dob); - $attendee_select[$row->nid] = $row->booking_firstname . ' ' . $row->booking_lastname . ' ['. $age . ' ' . $row->booking_gender . ']' . $married; + $assigned_flag = empty($room_mapping[$row->nid]) ? '' : ' - '; + $attendee_select[$row->nid] = $assigned_flag . $row->booking_firstname . ' ' . $row->booking_lastname . ' ['. $age . ' ' . $row->booking_gender . ']' . $married; } @@ -213,11 +219,9 @@ function booking_rooms_allocate_form($node, &$form_state, $location_id) { $room_query = db_query("SELECT * FROM {booking_room_definition} WHERE booking_room_location_id = :lid", array(':lid' => $location_id)); - //query for existing room allocations - $room_mapping_query = db_query("SELECT * FROM {booking_room_mapping} WHERE booking_eventid = :eid", array(':eid' => $event->eid)); - $room_mapping = $room_mapping_query->fetchAll(); + - //watchdog('booking', "
Loading existing room allocations:\n@info
", array('@info' => print_r( $room_mapping, true))); + watchdog('booking', "
Loading existing room allocations:\n@info
", array('@info' => print_r( $room_mapping, true))); //attach the custom css $form['#attached']['css'] = array(