Extend capacity checking to mass room allocation form
This commit is contained in:
@@ -310,7 +310,12 @@ function booking_room_edit_form_validate($form, &$form_state) {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (! _booking_room_capacity_check($values['booking_room_location_id'], $values['booking_room_number'], $values['booking_room_bedtype']))
|
||||
//get the specific room definition from the database
|
||||
$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))
|
||||
{
|
||||
form_set_error('booking_room_number',
|
||||
t('Unfortunately there are no beds available of the type specified in the room.')
|
||||
@@ -349,7 +354,7 @@ function booking_room_edit_form_validate($form, &$form_state) {
|
||||
* Validate there is available capacity for the specified room and bed type
|
||||
* @return TRUE if there is sufficient capacity, otherwise FALSE
|
||||
*/
|
||||
function _booking_room_capacity_check($room_location_id, $room_number, $room_bedtype) {
|
||||
function _booking_room_capacity_check($room_id, $room_bedtype, $room_definition_object = NULL) {
|
||||
global $event;
|
||||
|
||||
$bed_inputs = array(
|
||||
@@ -361,14 +366,19 @@ function _booking_room_capacity_check($room_location_id, $room_number, $room_bed
|
||||
//make sure the value exists before validating it
|
||||
if (!empty($room_bedtype))
|
||||
{
|
||||
//get the specific room definition from the database
|
||||
$details = db_query("SELECT * FROM {booking_room_definition} WHERE booking_room_location_id = :lid AND booking_room_number = :num",
|
||||
array(':lid' => $room_location_id, ':num' => $room_number))->fetchObject();
|
||||
//if we already have the object available, don't query for it again
|
||||
if ($room_definition_object == NULL)
|
||||
{
|
||||
$details = db_query("SELECT * FROM {booking_room_definition} WHERE rid = :rid",
|
||||
array(':rid' => $room_id))->fetchObject();
|
||||
}
|
||||
else
|
||||
$details = $room_definition_object;
|
||||
|
||||
//get all person-to-room mappings relating to this room and bed type
|
||||
$mappings = db_query("SELECT count(*) as num FROM {booking_room_mapping} " .
|
||||
"WHERE booking_eventid = :eid AND booking_roomid = :rid AND booking_room_bedtype = :type",
|
||||
array(':eid' => $event->eid, ':rid' => $details->rid, ':type' => $room_bedtype))->fetchObject();
|
||||
array(':eid' => $event->eid, ':rid' => $room_id, ':type' => $room_bedtype))->fetchObject();
|
||||
|
||||
$db_field = $bed_inputs[$room_bedtype];
|
||||
$max_beds = $details->$db_field;
|
||||
@@ -376,7 +386,8 @@ function _booking_room_capacity_check($room_location_id, $room_number, $room_bed
|
||||
if ($mappings->num < $max_beds)
|
||||
{
|
||||
watchdog('booking','Sufficient capacity is available in location !id, room !room, with bed type !type. !count beds remaining of this type',
|
||||
array('!id' => $room_location_id, '!room' => $room_number, '!type' => $room_bedtype, '!count' => $max_beds - $mappings->num));
|
||||
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 true;
|
||||
}
|
||||
@@ -810,7 +821,7 @@ function booking_rooms_allocate_form_submit($form, &$form_state) {
|
||||
'booking_room_queenbed_p2' => 3,
|
||||
);
|
||||
|
||||
//TODO: Validate that there is capacioty for the person to be allocated to this room
|
||||
|
||||
|
||||
//watchdog('booking', "<pre>Room assignment submission:\n@info</pre>", array('@info' => print_r( $singlebed_ids, true)));
|
||||
|
||||
@@ -836,17 +847,33 @@ function booking_rooms_allocate_form_submit($form, &$form_state) {
|
||||
//this person didn't previously have a room/bed mapping
|
||||
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();
|
||||
//Validate that there is capacity for the person to be allocated to this room
|
||||
if (_booking_room_capacity_check($room, $type_id))
|
||||
{
|
||||
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();
|
||||
}
|
||||
else
|
||||
{
|
||||
drupal_set_message(
|
||||
t('Insufficient capacity to assign person id !id to a type !type bed in room id !room.',
|
||||
array('!id' => $nid, '!room' => $room, '!type' => $type_id)
|
||||
), 'error'
|
||||
);
|
||||
//, 'error', FALSE);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//this person previously had a room mapping but to a different room
|
||||
elseif ((!empty($room_mapping[$nid])) && $room_mapping[$nid]->booking_roomid != $room)
|
||||
|
Reference in New Issue
Block a user