Completed autocomplete room allocation submit functions
This commit is contained in:
@@ -588,21 +588,21 @@ function booking_menu() {
|
|||||||
'type' => MENU_LOCAL_ACTION,
|
'type' => MENU_LOCAL_ACTION,
|
||||||
);
|
);
|
||||||
|
|
||||||
$items['admin/booking/rooms/%/assign'] = array(
|
$items['admin/booking/rooms/old/%/assign'] = array(
|
||||||
'title' => 'Assign Rooms',
|
'title' => 'Assign Rooms',
|
||||||
'description' => 'Assign attendees to rooms',
|
'description' => 'Assign attendees to rooms',
|
||||||
'page callback' => 'drupal_get_form',
|
'page callback' => 'drupal_get_form',
|
||||||
'page arguments' => array('booking_rooms_allocate_form', 3),
|
'page arguments' => array('booking_rooms_allocate_form', 4),
|
||||||
'access arguments' => array('edit room allocations'),
|
'access arguments' => array('edit room allocations'),
|
||||||
//'type' => MENU_NORMAL_ITEM,
|
//'type' => MENU_NORMAL_ITEM,
|
||||||
);
|
);
|
||||||
|
|
||||||
//use this for testing the autocomplete fields
|
//use this for testing the autocomplete fields
|
||||||
$items['admin/booking/rooms/test/%/assign'] = array(
|
$items['admin/booking/rooms/%/assign'] = array(
|
||||||
'title' => 'Assign Rooms',
|
'title' => 'Assign Attendees to Rooms',
|
||||||
'description' => 'Assign attendees to rooms',
|
'description' => 'Assign attendees to rooms via autocomplete fields',
|
||||||
'page callback' => 'drupal_get_form',
|
'page callback' => 'drupal_get_form',
|
||||||
'page arguments' => array('booking_rooms_allocate_test_form', 4),
|
'page arguments' => array('booking_rooms_allocate_test_form', 3),
|
||||||
'access arguments' => array('edit room allocations'),
|
'access arguments' => array('edit room allocations'),
|
||||||
//'type' => MENU_NORMAL_ITEM,
|
//'type' => MENU_NORMAL_ITEM,
|
||||||
);
|
);
|
||||||
|
@@ -178,26 +178,38 @@ function booking_rooms_allocate_test_form_submit($form, &$form_state) {
|
|||||||
//go through each bed
|
//go through each bed
|
||||||
foreach ($data as $bed_index => $person)
|
foreach ($data as $bed_index => $person)
|
||||||
{
|
{
|
||||||
if (! empty($person)) {
|
//check for previous value
|
||||||
|
$previous_nid = 0;
|
||||||
|
$previous_nid = _booking_rooms_allocate_get_previous_value(&$form, $type, $room, $type . '[' . $room . '][' . $bed_index . ']');
|
||||||
|
|
||||||
|
if (! empty($person)) {
|
||||||
//extract nid from $person using regex
|
//extract nid from $person using regex
|
||||||
if (preg_match('/[\s\w,]+\s\[(\d+)\]/i', $person, $matches)) {
|
if (preg_match('/[\s\w,]+\s\[(\d+)\]/i', $person, $matches)) {
|
||||||
//watchdog('booking_debug', "Processing room assignment for ID !id belonging to person !person ", array('!id' => $matches[1], '!person' => $person));
|
//watchdog('booking_debug', "Processing room assignment for ID !id belonging to person !person ", array('!id' => $matches[1], '!person' => $person));
|
||||||
$nid = $matches[1];
|
$nid = $matches[1];
|
||||||
|
|
||||||
//TODO:
|
//handle the insert/update/deletes required
|
||||||
//see if someone was previously assigned to this bed
|
_booking_rooms_allocate_test_form_submit_helper(&$room_mapping, $room, $type_id, $bed_index, $nid, $previous_nid);
|
||||||
//if someone was, then remove the mapping if it was a different person
|
|
||||||
|
|
||||||
//see if this person was already assigned to a different bed
|
|
||||||
//if true, then update their mapping to point to this bed
|
|
||||||
//otherwise, insert a new mapping for this person to this bed
|
|
||||||
_booking_rooms_allocate_test_form_submit_helper(&$room_mapping, $room, $type_id, $nid);
|
|
||||||
|
|
||||||
} //parsed node id successfully
|
} //parsed node id successfully
|
||||||
|
|
||||||
|
|
||||||
} //empty bed check
|
} //empty bed check
|
||||||
|
elseif (empty($person) && $previous_nid > 0)
|
||||||
|
{
|
||||||
|
$message = t('Removing person !person previously in room id !room with bed index !index and bed type !type.',
|
||||||
|
array('!room' => $room, '!index' => $bed_index, '!person' => $previous_nid, '!type' => $type_id));
|
||||||
|
watchdog('booking', $message);
|
||||||
|
drupal_set_message($message);
|
||||||
|
|
||||||
|
db_delete('booking_room_mapping')
|
||||||
|
->condition('booking_eventid', $event->eid)
|
||||||
|
->condition('booking_nodeid', $previous_nid)
|
||||||
|
->condition('booking_room_bedtype', $type_id)
|
||||||
|
->condition('booking_roomid', $room)
|
||||||
|
->execute();
|
||||||
|
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//TODO: Check if this bed used to have someone allocated
|
//TODO: Check if this bed used to have someone allocated
|
||||||
@@ -212,21 +224,53 @@ function booking_rooms_allocate_test_form_submit($form, &$form_state) {
|
|||||||
/**
|
/**
|
||||||
* look through the previous form data and return the matching element
|
* look through the previous form data and return the matching element
|
||||||
*/
|
*/
|
||||||
function _booking_rooms_allocate_get_previous_value(&$form, $element) {
|
function _booking_rooms_allocate_get_previous_value(&$form, $type, $room, $name) {
|
||||||
|
|
||||||
foreach($form['rooms']['#rows'] as $key => $value)
|
foreach($form['form']['rooms']['#rows'] as $key => $value)
|
||||||
{
|
{
|
||||||
if ((! empty($value['data'])) && $value['data']['#id'] == $element){
|
//watchdog('booking_debug', "<pre>Room assignment checker for type !type in room !room:\n@info</pre>", array('!room' => $room, '!type' => $type, '@info' => print_r( $value, true)));
|
||||||
return $value['data']['#value'];
|
//return;
|
||||||
|
if ((!empty($value[$type]['data']['#value'])) && ($value[$type]['data']['#name'] == $name)) {
|
||||||
|
//watchdog('booking_debug', "Found correct room with room number !num and type !type", array('!num' => $room, '!type' => $type));
|
||||||
|
|
||||||
|
//found the correct element, extract the node id
|
||||||
|
$person = $value[$type]['data']['#value'];
|
||||||
|
if (preg_match('/[\s\w,]+\s\[(\d+)\]/i', $person, $matches)) {
|
||||||
|
return $matches[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//in case there was no matching value, return an empty string
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _booking_rooms_allocate_test_form_submit_helper(&$room_mapping, $room, $type_id, $nid)
|
/**
|
||||||
|
* function to update person with correct bed allocation and remove any previous allocation if necessary
|
||||||
|
*/
|
||||||
|
function _booking_rooms_allocate_test_form_submit_helper(&$room_mapping, $room, $type_id, $bed_index, $nid, $previous_nid)
|
||||||
{
|
{
|
||||||
global $event;
|
global $event;
|
||||||
$message = "";
|
$message = "";
|
||||||
|
|
||||||
|
//remove any person previously defined for this bed that doesn't match what is now defined
|
||||||
|
if ($previous_nid > 0 && $nid != $previous_nid)
|
||||||
|
{
|
||||||
|
$message = t('Bed allocation for room !room and bed index !index has changed. Removing previous !person from this location.',
|
||||||
|
array('!room' => $room, '!index' => $bed_index, '!person' => $previous_nid));
|
||||||
|
watchdog('booking', $message);
|
||||||
|
drupal_set_message($message);
|
||||||
|
|
||||||
|
//look for an exact match,
|
||||||
|
//in case this person has moved to a different bed type during this form submission
|
||||||
|
db_delete('booking_room_mapping')
|
||||||
|
->condition('booking_eventid', $event->eid)
|
||||||
|
->condition('booking_nodeid', $previous_nid)
|
||||||
|
->condition('booking_room_bedtype', $type_id)
|
||||||
|
->condition('booking_roomid', $room)
|
||||||
|
->execute();
|
||||||
|
}
|
||||||
|
|
||||||
//if this person didn't previously have a room/bed mapping
|
//if this person didn't previously have a room/bed mapping
|
||||||
if (empty($room_mapping[$nid]))
|
if (empty($room_mapping[$nid]))
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user