Update room location report

This commit is contained in:
2014-06-10 12:15:33 +08:00
parent 01c24601c3
commit 18ce42a14f

View File

@@ -1022,64 +1022,138 @@ function booking_rooms_allocate_form_submit($form, &$form_state) {
}
/**
* Function for viewing room report
* Function for generating report of room allocations in a specific location
*/
function booking_rooms_view_form($node, &$form_state, $location_id) {
global $event;
$rows = array();
$form = array();
//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_set_message("Error: Invalid room location ID '" . $location_id . "' supplied. Unable to allocate rooms.",
'error', FALSE);
drupal_goto('admin/booking/rooms');
return "";
}
$rows = array();
$prefix = t("<h2>Room Allocations for !room</h2>", array('!room' => _booking_room_location_lookup($location_id)));
$header = array(
'booking_firstname' => array('data' => t('First Name'), 'field' => 'p.booking_firstname'),
'booking_lastname' => array('data' => t('Last Name'), 'field' => 'p.booking_lastname', 'sort' => 'asc'),
'booking_gender' => array('data' => t('Gender'), 'field' => 'p.booking_gender'),
'booking_age' => array('data' => t('Age'), 'field' => 'p.booking_dob'),
'booking_married' => array('data' => t('Married?'), 'field' => 'p.booking_married'),
//'booking_roomlocation' => array('data' => t('Room Location'), 'field' => 'r.booking_room_location_id'),
'booking_room_num' => array('data' => t('Room Number'), 'field' => 'r.booking_room_number'),
'booking_room_bedtype' => array('data' => t('Bed Type'), 'field' => 'm.booking_room_bedtype'),
'booking_room_edit' => array('data' => t('Edit')),
//query for room definitions
$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->fetchAllAssoc('booking_nodeid');
//query for attendees
$attendees = 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))->fetchAllAssoc('nid');
//define the header
$header = array (
'booking_room_number' => array('data' => t('Room Number')),
'booking_room_singlebed' => array('data' => t('Single Bed')),
'booking_room_doublebed_p1' => array('data' => t('Double Bed Person 1')),
'booking_room_doublebed_p2' => array('data' => t('Double Bed Person 2')),
'booking_room_queenbed_p1' => array('data' => t('Queen Bed Person 1')),
'booking_room_queenbed_p2' => array('data' => t('Queen Bed Person 2')),
);
$query = db_select('booking_person', 'p');
$query->leftJoin('booking_room_mapping', 'm', 'm.booking_nodeid = p.nid');
$query->leftJoin('booking_room_definition', 'r', 'r.rid = m.booking_roomid');
$db_and = db_and();
$db_and->condition('p.booking_event_id', $event->eid, '=');
$db_and->condition('p.booking_status', 1, '=');
$db_and->condition('r.booking_room_location_id', $location_id, '=');
$query->condition($db_and);
$query->fields('p')->fields('m')->fields('r');
$table_sort = $query->extend('TableSort')->orderbyHeader($header);
$result = $table_sort->execute();
foreach($result as $data)
foreach ($room_query as $data)
{
//load the existing bed mappings for this room
$existing_beds = array();
for ($i = 1; $i <= 3; $i++)
{
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;
}
}
}
//create a row that contains just the room location and number
$rows[] = array (
'data' => array(
$data->booking_firstname,
$data->booking_lastname,
$data->booking_gender == 'M' ? 'Male' : 'Female',
_booking_get_age_years($data->booking_dob),
$data->booking_married == 'Y' ? 'Yes' : 'No',
//_booking_room_location_lookup($data->booking_room_location_id),
$data->booking_room_number,
_booking_room_bedtype_lookup($data->booking_room_bedtype),
l(t('Edit'), t('admin/booking/!id/edit-room', array('!id' => $data->nid))),
"",
"",
"",
"",
"",
),
'id' => array("new-group-row"),
);
//create an additional row for each single bed
for ($i = 0; $i < $data->booking_room_singlebeds; $i++)
{
//retrieve the default value if one exists
$nid = (!empty($existing_beds[1][$i])) ? $existing_beds[1][$i] : 0;
$rows[] = array (
'data' => array(
"",
_booking_rooms_view_formatperson($attendees, $nid),
"",
"",
"",
"",
),
);
}
$prefix = t("<h2>Room Allocations for !room</h2>", array('!room' => _booking_room_location_lookup($location_id)));
//create an additional row for each double bed
//$j is our counter that increments twice as fast as $i to cater for both beds
$j = 0;
for ($i = 0; $i < $data->booking_room_doublebeds; $i++)
{
$rows[] = array (
'data' => array(
"",
"",
_booking_rooms_view_formatperson($attendees, (!empty($existing_beds[2][$j])) ? $existing_beds[2][$j++] : 0),
_booking_rooms_view_formatperson($attendees, (!empty($existing_beds[2][$j])) ? $existing_beds[2][$j++] : 0),
"",
"",
),
);
}
//create an additional row for each queen bed
//$j is our counter that increments twice as fast as $i to cater for both beds
$j = 0;
for ($i = 1; $i <= $data->booking_room_queenbeds; $i++)
{
$rows[] = array (
'data' => array(
"",
"",
"",
"",
_booking_rooms_view_formatperson($attendees, (!empty($existing_beds[3][$j])) ? $existing_beds[3][$j++] : 0),
_booking_rooms_view_formatperson($attendees, (!empty($existing_beds[3][$j])) ? $existing_beds[3][$j++] : 0),
),
);
}
}
//watchdog('booking', "<pre>Room assignment report rows:\n@info</pre>", array('@info' => print_r( $rows, true)));
$result = array (
'#attached' => array (
'css' => array(drupal_get_path('module', 'booking') . '/booking.css')
),
'first_para' => array (
'#type' => 'markup',
'#markup' => $prefix,
@@ -1096,3 +1170,21 @@ function booking_rooms_view_form($node, &$form_state, $location_id) {
return $result;
}
/**
* Function for generating a name relating to a node id
* @param $attendees - an associative array containing the possible attendees
* @param $nid - the node id of the person for which to return the formatted string
* @return string containing first name and last name relating to node id
*/
function _booking_rooms_view_formatperson(&$attendees, $nid) {
$output = "Empty";
if ($nid > 0 && !empty($attendees[$nid]))
{
$output = $attendees[$nid]->booking_firstname . " " . $attendees[$nid]->booking_lastname;
}
return $output;
}