Fixes to validation routine when bed allocation wasn't actually changing
This commit is contained in:
@@ -294,11 +294,6 @@ function booking_room_edit_form_validate($form, &$form_state) {
|
||||
|
||||
global $event;
|
||||
$values = $form_state['input'];
|
||||
$bed_inputs = array(
|
||||
1 => 'booking_room_singlebeds',
|
||||
2 => 'booking_room_doublebeds',
|
||||
3 => 'booking_room_queenbeds',
|
||||
);
|
||||
|
||||
//watchdog('booking', "<pre>Room Number Form State:\n@info</pre>", array('@info' => print_r( $form_state['values'], true)));
|
||||
|
||||
@@ -314,8 +309,16 @@ function booking_room_edit_form_validate($form, &$form_state) {
|
||||
$details = db_query("SELECT * FROM {booking_room_definition} WHERE booking_room_location_id = :lid AND booking_room_number = :num",
|
||||
array(':lid' => $values['booking_room_location_id'], ':num' => $values['booking_room_number']))->fetchObject();
|
||||
|
||||
|
||||
if (! _booking_room_capacity_check($details->rid, $values['booking_room_bedtype'], $details))
|
||||
//perform a check to see if this person is already allocated to this bed
|
||||
$check = db_query("SELECT * FROM {booking_room_mapping} WHERE booking_eventid = :eid AND booking_nodeid = :nid",
|
||||
array(':eid' => $event->eid, ':nid' => $values['personid']))->fetchObject();
|
||||
|
||||
if ($check && ($check->booking_roomid == $details->rid && $check->booking_room_bedtype == $values['booking_room_bedtype']))
|
||||
{
|
||||
drupal_set_message('Not validating room capacity because this person is already allocated this bed in this room.');
|
||||
}
|
||||
//there was no existing mapping for this person, so check that there's capacity in this room
|
||||
elseif (! _booking_room_capacity_check($details->rid, $values['booking_room_bedtype'], $details))
|
||||
{
|
||||
form_set_error('booking_room_number',
|
||||
t('Unfortunately there are no beds available of the type specified in the room.')
|
||||
@@ -356,6 +359,13 @@ function _booking_room_capacity_check($room_id, $room_bedtype, $room_definition_
|
||||
|
||||
$db_field = $bed_inputs[$room_bedtype];
|
||||
$max_beds = $details->$db_field;
|
||||
|
||||
//if the beds are dual occupency, pretend there's twice as many of them
|
||||
if ($room_bedtype == 2 || $room_bedtype == 3)
|
||||
{
|
||||
$max_beds = $max_beds * 2;
|
||||
}
|
||||
|
||||
//check that there is sufficient capacity to allocate another person to this room and bed type
|
||||
if ($mappings->num < $max_beds)
|
||||
{
|
||||
@@ -364,7 +374,13 @@ function _booking_room_capacity_check($room_id, $room_bedtype, $room_definition_
|
||||
'!type' => _booking_room_bedtype_lookup($room_bedtype), '!count' => $max_beds - $mappings->num));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
watchdog('booking',"Couldn't locate sufficient capacity in location !id, room !room, with bed type !type. !count beds remaining of this type",
|
||||
array('!id' => $details->booking_room_location_id, '!room' => $details->booking_room_number,
|
||||
'!type' => _booking_room_bedtype_lookup($room_bedtype), '!count' => $max_beds - $mappings->num));
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -1010,4 +1026,72 @@ function booking_rooms_allocate_form_submit($form, &$form_state) {
|
||||
function booking_rooms_view_form($node, &$form_state, $location_id) {
|
||||
global $event;
|
||||
|
||||
//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 "";
|
||||
}
|
||||
|
||||
$rows = array();
|
||||
|
||||
$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 = 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)
|
||||
{
|
||||
$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))),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
$prefix = t("<h2>Room Allocations for !room</h2>", array('!room' => _booking_room_location_lookup($location_id)));
|
||||
|
||||
$result = array (
|
||||
'first_para' => array (
|
||||
'#type' => 'markup',
|
||||
'#markup' => $prefix,
|
||||
),
|
||||
'table' => array (
|
||||
'#theme' => 'table',
|
||||
'#header' => $header,
|
||||
'#rows' => $rows,
|
||||
'#attributes' => array('id' => 'sort-table'),
|
||||
'#empty' => t('No room allocations found for this location.'),
|
||||
)
|
||||
);
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
Reference in New Issue
Block a user