more progress on room allocation pages

This commit is contained in:
2014-05-27 15:58:50 +10:00
parent 773ba5a101
commit 2a3d29aa3b
5 changed files with 177 additions and 78 deletions

View File

@@ -5,10 +5,45 @@
* Functions to handle room allocation and administration for the booking module
*/
/**
* Function for listing the room locations links to view each one and assign people to rooms
*/
function booking_room_view_summary() {
global $event;
$output = "";
$header = array('Location', 'Assign Attendees', 'View Rooms For Location');
$attributes = array('style' => 'max-width:30%');
$rows = array();
//get room definitions
$room_definitions = _booking_room_location_lookup();
//ditch the first element which is empty
array_shift($room_definitions);
$i = 1;
foreach ($room_definitions as $room) {
$rows[] = array(
$room,
l(t('Allocate Rooms'), t('admin/booking/rooms/!id/assign', array('!id' => $i))),
l(t('View Rooms'), t('admin/booking/rooms/!id/view', array('!id' => $i))),
);
$i++;
}
//output everything
$output .= t("<h3>!event Room Locations</h3>", array('!event' => $event->booking_eventname));
$output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => $attributes));
return $output;
}
/**
* Function to define the form for configuring room definitions and also display existing room definitions
*/
function booking_rooms_define_form() {
function booking_rooms_define_form($node, &$form_state, $location_id) {
global $event;
$form = array();
$bedcount_options = array();
@@ -17,6 +52,9 @@ function booking_rooms_define_form() {
for ($i = 0; $i <= 15; $i++)
$bedcount_options[$i] = $i;
//query for room definitions
$result = db_query("SELECT * from {booking_room_definition}");
//define the form for adding to the room definitions
$form[] = array (
@@ -84,8 +122,6 @@ function booking_rooms_define_form() {
'booking_room_ensuite' => t('Ensuite?'),
);
$result = db_query("SELECT * from {booking_room_definition}");
foreach($result as $data)
{
$options[$data->rid] = array
@@ -144,31 +180,44 @@ function booking_rooms_define_form_submit($form, &$form_state) {
/**
* Function for allocating rooms
*/
function booking_rooms_allocate_form($node, &$form_state) {
function booking_rooms_allocate_form($node, &$form_state, $location_id) {
global $event;
$form = array();
$attendee_select = array();
$options = array();
$counter = 0;
//verify that $location_id is a number
if (! preg_match('/^[0-9]+$/', $location_id)) {
drupal_set_message("Error: Invalid room location ID '" . $location_id . "' supplied. Unable to allocate rooms.", 'error', FALSE);
drupal_goto('admin/booking/rooms');
return "";
}
//make a list of all attendees
$attendee_select[] = '';
$query = db_query("SELECT nid, booking_firstname, booking_lastname, booking_gender FROM {booking_person} " .
$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));
foreach($query as $row)
$attendee_select[$row->nid] = $row->booking_firstname . ' ' . $row->booking_lastname . ' ['. $row->booking_gender . ']';
{
$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;
}
//query for room definitions
$room_query = db_query("SELECT * FROM {booking_room_definition}");
$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', "<pre>Loading existing room allocations:\n@info</pre>", array('@info' => print_r( $room_mapping, true)));
//watchdog('booking', "<pre>Loading existing room allocations:\n@info</pre>", array('@info' => print_r( $room_mapping, true)));
//attach the custom css
$form['#attached']['css'] = array(
@@ -203,6 +252,8 @@ function booking_rooms_allocate_form($node, &$form_state) {
{
foreach ($room_mapping as $mapping)
{
//check that the room id in the mapping table matches the room that we're currently adding to the table
//and also the bed type matches the first dimension in the array
if ($mapping->booking_roomid == $data->rid && $mapping->booking_room_bedtype == $i)
{
$existing_beds[$i][] = $mapping->booking_nodeid;
@@ -210,8 +261,7 @@ function booking_rooms_allocate_form($node, &$form_state) {
}
}
watchdog('booking', "<pre>Existing bed mappings:\n@info</pre>", array('@info' => print_r( $existing_beds, true)));
//watchdog('booking', "<pre>Existing bed mappings:\n@info</pre>", array('@info' => print_r( $existing_beds, true)));
//create a row that contains just the room location and number
$row = _booking_clone_array($default_row);
@@ -284,15 +334,15 @@ function booking_rooms_allocate_form($node, &$form_state) {
'#type' => 'tableselect',
'#header' => $header,
'#options' => $options,
'#empty' => t('No attendees found.'),
'#empty' => t('No rooms found for this room location id.'),
);
//so we can access the dropdown elements
$form['booking_room_singlebed'] = array( '#type' => 'value', );
$form['booking_room_queenbed_p1'] = array( '#type' => 'value', );
$form['booking_room_queenbed_p2'] = array( '#type' => 'value', );
$form['booking_room_doublebed_p1'] = array( '#type' => 'value', );
$form['booking_room_doublebed_p2'] = array( '#type' => 'value', );
$form['booking_room_singlebed'] = array( '#type' => 'value' );
$form['booking_room_queenbed_p1'] = array( '#type' => 'value' );
$form['booking_room_queenbed_p2'] = array( '#type' => 'value' );
$form['booking_room_doublebed_p1'] = array( '#type' => 'value' );
$form['booking_room_doublebed_p2'] = array( '#type' => 'value' );
$form['submit'] = array (
'#type' => 'submit',
@@ -310,10 +360,10 @@ function booking_rooms_allocate_form($node, &$form_state) {
*/
function booking_rooms_allocate_form_submit($form, &$form_state) {
global $event;
$counter = 0;
$checkboxes = $form_state['values']['table'];
//$singlebed_ids = $form_state['values']['booking_room_singlebed'];
$values = $form_state['input'];
//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->fetchAllAssoc('booking_nodeid');
$bed_inputs = array(
'booking_room_singlebed' => 1,
@@ -336,7 +386,7 @@ function booking_rooms_allocate_form_submit($form, &$form_state) {
continue;
//go through each room
foreach($form_state['values'][$type] as $key => $value)
foreach($form_state['values'][$type] as $room => $value)
{
//go through each bed
foreach ($value as $index => $nid)
@@ -344,23 +394,44 @@ function booking_rooms_allocate_form_submit($form, &$form_state) {
//if this is actually a person to process
if ($nid > 0)
{
drupal_set_message(t('Assigning person id !id to a !type bed in room id !room.',
array('!id' => $nid, '!room' => $key, '!type' => $type_id)));
//TODO: Check there isn't already a mapping for this person
$result = db_insert('booking_room_mapping')
->fields(array(
'booking_roomid' => $key,
'booking_eventid' => $event->eid,
'booking_nodeid' => $nid,
'booking_room_bedtype' => $type_id,
))
->execute();
if (empty($room_mapping[$nid]))
{
drupal_set_message(t('Assigning person id !id to a type !type bed in room id !room.',
array('!id' => $nid, '!room' => $room, '!type' => $type_id)));
$result = db_insert('booking_room_mapping')
->fields(array(
'booking_roomid' => $room,
'booking_eventid' => $event->eid,
'booking_nodeid' => $nid,
'booking_room_bedtype' => $type_id,
))
->execute();
}
elseif ((!empty($room_mapping[$nid])) && $room_mapping[$nid]->booking_roomid != $room)
{
drupal_set_message(t('Changing person id !id from old room !oldroom to new room !room with type !type bed.',
array('!id' => $nid, '!room' => $room, '!type' => $type_id, '!oldroom' => $room_mapping[$nid]->booking_roomid)));
db_update('booking_room_mapping')
->fields(array(
'booking_roomid' => $room,
'booking_room_bedtype' => $type_id,
))
->condition('booking_eventid', $event->eid)
->condition('booking_nodeid', $nid)
->execute();
}
else
{
//drupal_set_message(t('Person id !id already has some other room allocation.',
// array('!id' => $nid, '!room' => $room, '!type' => $type_id)));
}
}
} //each bed
} //each room
} //each bed type
} //valid node id check
} //each bed
} //each room
} //each bed type
}