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
|
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',
|
form_set_error('booking_room_number',
|
||||||
t('Unfortunately there are no beds available of the type specified in the room.')
|
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
|
* Validate there is available capacity for the specified room and bed type
|
||||||
* @return TRUE if there is sufficient capacity, otherwise FALSE
|
* @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;
|
global $event;
|
||||||
|
|
||||||
$bed_inputs = array(
|
$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
|
//make sure the value exists before validating it
|
||||||
if (!empty($room_bedtype))
|
if (!empty($room_bedtype))
|
||||||
{
|
{
|
||||||
//get the specific room definition from the database
|
//if we already have the object available, don't query for it again
|
||||||
$details = db_query("SELECT * FROM {booking_room_definition} WHERE booking_room_location_id = :lid AND booking_room_number = :num",
|
if ($room_definition_object == NULL)
|
||||||
array(':lid' => $room_location_id, ':num' => $room_number))->fetchObject();
|
{
|
||||||
|
$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
|
//get all person-to-room mappings relating to this room and bed type
|
||||||
$mappings = db_query("SELECT count(*) as num FROM {booking_room_mapping} " .
|
$mappings = db_query("SELECT count(*) as num FROM {booking_room_mapping} " .
|
||||||
"WHERE booking_eventid = :eid AND booking_roomid = :rid AND booking_room_bedtype = :type",
|
"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];
|
$db_field = $bed_inputs[$room_bedtype];
|
||||||
$max_beds = $details->$db_field;
|
$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)
|
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',
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -810,7 +821,7 @@ function booking_rooms_allocate_form_submit($form, &$form_state) {
|
|||||||
'booking_room_queenbed_p2' => 3,
|
'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)));
|
//watchdog('booking', "<pre>Room assignment submission:\n@info</pre>", array('@info' => print_r( $singlebed_ids, true)));
|
||||||
|
|
||||||
@@ -835,6 +846,10 @@ function booking_rooms_allocate_form_submit($form, &$form_state) {
|
|||||||
{
|
{
|
||||||
//this person didn't previously have a room/bed mapping
|
//this person didn't previously have a room/bed mapping
|
||||||
if (empty($room_mapping[$nid]))
|
if (empty($room_mapping[$nid]))
|
||||||
|
{
|
||||||
|
|
||||||
|
//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.',
|
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)));
|
array('!id' => $nid, '!room' => $room, '!type' => $type_id)));
|
||||||
@@ -847,6 +862,18 @@ function booking_rooms_allocate_form_submit($form, &$form_state) {
|
|||||||
'booking_room_bedtype' => $type_id,
|
'booking_room_bedtype' => $type_id,
|
||||||
))
|
))
|
||||||
->execute();
|
->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
|
//this person previously had a room mapping but to a different room
|
||||||
elseif ((!empty($room_mapping[$nid])) && $room_mapping[$nid]->booking_roomid != $room)
|
elseif ((!empty($room_mapping[$nid])) && $room_mapping[$nid]->booking_roomid != $room)
|
||||||
|
Reference in New Issue
Block a user