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

@@ -111,6 +111,12 @@ function booking_permission() {
'edit study groups' => array(
'title' => t('Edit study groups'),
),
'view room allocations' => array(
'title' => t('View Room Allocations'),
),
'edit room allocations' => array(
'title' => t('Edit Room Allocations'),
),
'create_travel_forms' => array(
'title' => t('Create a new travel form entry'),
),
@@ -385,13 +391,23 @@ function booking_menu() {
}
//configure rooms
$items['admin/booking/rooms/assign'] = array(
$items['admin/booking/rooms'] = array(
'title' => 'View Rooms',
'description' => 'View Room Locations',
'page callback' => 'booking_room_view_summary',
'access arguments' => array("view room allocations"),
'type' => MENU_NORMAL_ITEM,
);
$items['admin/booking/rooms/%/assign'] = array(
'title' => 'Assign Rooms',
'description' => 'Assign attendees to rooms',
'page callback' => 'drupal_get_form',
'page arguments' => array('booking_rooms_allocate_form'),
'access arguments' => array('edit bookings'),
'type' => MENU_NORMAL_ITEM,
'page arguments' => array('booking_rooms_allocate_form', 3),
//'page arguments' => array('booking_rooms_allocate_form'),
'access arguments' => array('edit room allocations'),
//'type' => MENU_NORMAL_ITEM,
);

View File

@@ -1093,8 +1093,8 @@ function booking_load_query($node_ids = NULL, $fetchAssoc = FALSE)
$query->fields('p')
->fields('t')
->fields('pr', array('booking_price', 'booking_price_descrip','booking_late_price'))
->fields('rm', array('booking_roomid', 'booking_room_bedtype'))
->fields('r', array('rid','booking_room_location_id', 'booking_room_number'));
->fields('rm', array('booking_room_bedtype'))
->fields('r', array('booking_room_location_id', 'booking_room_number'));
//now add the study group fields if applicable
if (variable_get('booking_enable_studygroups', 0) == 1)

View File

@@ -561,6 +561,18 @@ function booking_csv_report() {
continue;
}
//room location
if ($key == 'booking_room_location_id') {
$output[] = _booking_room_location_lookup($value);
continue;
}
//room bed type
if ($key == 'booking_room_bedtype') {
$output[] = _booking_room_bedtype_lookup($value);
continue;
}
//add in the amount owing using the nid as the key
if ($key == 'nid')
{

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,21 +394,42 @@ 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
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' => $key,
'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)));
}
} //valid node id check
} //each bed
} //each room
} //each bed type

View File

@@ -5,6 +5,39 @@
* Admin pages for calculating study group session membership
*/
/**
* Function for listing the study groups and links to view each one
*/
function booking_studygroups_view_summary() {
global $event;
$output = "";
$header = array('Link','Study Group', 'Session Count', 'Select Leaders');
$attributes = array('style' => 'max-width:30%');
//get study groups
$query = db_select('booking_studygroup_list', 's')
->fields('s')
->condition('s.booking_eventid', $event->eid, '=');
$result = $query->execute();
foreach ($result as $group) {
$rows[] = array(
l(t('View', array('!id' => $group->sid)), t('admin/booking/studygroups/!id/view', array('!id' => $group->sid))),
$group->booking_studygroup_descrip,
$group->booking_num_group_sessions,
l(t('Edit Leaders/Helpers', array('!id' => $group->sid)), t('admin/booking/studygroups/!id/selectleaders', array('!id' => $group->sid))),
);
}
//output everything
$output .= t("<h3>!event Study Groups</h3>", array('!event' => $event->booking_eventname));
$output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => $attributes));
return $output;
}
/**
* Function for selecting who is available to lead or help sessions
*/
@@ -911,39 +944,6 @@ function booking_studygroups_calculate() {
//watchdog('booking', "Attendee list final version: @info", array('@info' => var_export($attendees, TRUE)));
}
/**
* Function for listing the study groups and links to view each one
*/
function booking_studygroups_view_summary() {
global $event;
$output = "";
$header = array('Link','Study Group', 'Session Count', 'Select Leaders');
$attributes = array('style' => 'max-width:30%');
//get study groups
$query = db_select('booking_studygroup_list', 's')
->fields('s')
->condition('s.booking_eventid', $event->eid, '=');
$result = $query->execute();
foreach ($result as $group) {
$rows[] = array(
l(t('View', array('!id' => $group->sid)), t('admin/booking/studygroups/!id/view', array('!id' => $group->sid))),
$group->booking_studygroup_descrip,
$group->booking_num_group_sessions,
l(t('Edit Leaders/Helpers', array('!id' => $group->sid)), t('admin/booking/studygroups/!id/selectleaders', array('!id' => $group->sid))),
);
}
//output everything
$output .= t("<h3>!event Study Groups</h3>", array('!event' => $event->booking_eventname));
$output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => $attributes));
return $output;
}
/**
* Function for viewing a printable format of who belongs to which study group