Fixed logic in room allocation form

This commit is contained in:
2014-06-25 22:48:19 +10:00
parent d7b12517b5
commit d096b0d5ab
2 changed files with 130 additions and 77 deletions

View File

@@ -763,7 +763,7 @@ function booking_rooms_allocate_form($node, &$form_state, $location_id) {
} }
watchdog('booking', "<pre>Loading existing room allocations:\n@info</pre>", array('@info' => print_r( $room_mapping, true))); //watchdog('booking', "<pre>Loading existing room allocations:\n@info</pre>", array('@info' => print_r( $room_mapping, true)));
//attach the custom css //attach the custom css
$form['#attached']['css'] = array( $form['#attached']['css'] = array(
@@ -927,9 +927,7 @@ function booking_rooms_allocate_form_submit($form, &$form_state) {
'booking_room_queenbed_p2' => 3, 'booking_room_queenbed_p2' => 3,
); );
//watchdog('booking', "<pre>Room assignment submission form state:\n@info</pre>", array('@info' => print_r( $form_state, true)));
//watchdog('booking', "<pre>Room assignment submission:\n@info</pre>", array('@info' => print_r( $singlebed_ids, true)));
//go through the different bed types //go through the different bed types
foreach ($bed_inputs as $type => $type_id) foreach ($bed_inputs as $type => $type_id)
@@ -947,19 +945,61 @@ function booking_rooms_allocate_form_submit($form, &$form_state) {
//go through each bed //go through each bed
foreach ($value as $index => $nid) foreach ($value as $index => $nid)
{ {
//if this is actually a person to process //calculate the name of the field for the bed
$bed_lookup = $type . '[' . $room . '][' . $index . ']';
$previous_nid = 0;
$message = "";
//firstly check if there was a different nid here before
//iterate the option input-types in the form array that made up the original form
foreach ($form['form']['table']['#options'] as $option)
{
//if this one was defined and matches the bed we're looking at now
if (!empty($option[$type]) && $option[$type]['data']['#name'] == $bed_lookup)
{
$previous_nid = $option[$type]['data']['#value'];
break;
}
}
//if there is a person now selected for this bed
if ($nid > 0) if ($nid > 0)
{ {
//this person didn't previously have a room/bed mapping //remove any person previously defined here 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 !person from this location.',
array('!room' => $room, '!index' => $index, '!person' => $previous_nid));
watchdog('booking', $message);
drupal_set_message($message);
db_delete('booking_room_mapping')
->condition('booking_eventid', $event->eid)
->condition('booking_nodeid', $previous_nid)
->execute();
}
//if 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 //Validate that there is capacity for the person to be allocated to this room
if (_booking_room_capacity_check($room, $type_id)) 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.', $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));
//double check we haven't already allocated a bed during this submission
$check = db_query("SELECT * FROM {booking_room_mapping} " .
" WHERE booking_eventid = :eid AND booking_roomid = :rid " .
" AND booking_room_bedtype = :type AND booking_nodeid = :nid",
array(':eid' => $event->eid, ':rid' => $room, ':type' => $type_id,
':nid' => $nid,
))->fetchObject();
if (! $check)
{
$result = db_insert('booking_room_mapping') $result = db_insert('booking_room_mapping')
->fields(array( ->fields(array(
'booking_roomid' => $room, 'booking_roomid' => $room,
@@ -971,21 +1011,24 @@ function booking_rooms_allocate_form_submit($form, &$form_state) {
} }
else else
{ {
drupal_set_message( $message .= t(' Except this person already exists.');
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);
} }
}
//no capacity available in this room
else
{
$message = t('No capacity to assign person id !id to a type !type bed in room id !room.',
array('!id' => $nid, '!room' => $room, '!type' => $type_id)
);
}
} }
//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)
{ {
drupal_set_message(t('Changing person id !id from old room !oldroom to new room !room with type !type bed.', $message = t('Changing person id !id from old room !oldroom to new room !room with type !type bed.',
array('!id' => $nid, '!room' => $room, '!type' => $type_id, '!oldroom' => $room_mapping[$nid]->booking_roomid))); array('!id' => $nid, '!room' => $room, '!type' => $type_id,
'!oldroom' => $room_mapping[$nid]->booking_roomid));
db_update('booking_room_mapping') db_update('booking_room_mapping')
->fields(array( ->fields(array(
@@ -1000,8 +1043,9 @@ function booking_rooms_allocate_form_submit($form, &$form_state) {
//this person previously had a room mapping but to a different bed type in the same room //this person previously had a room mapping but to a different bed type in the same room
elseif ((!empty($room_mapping[$nid])) && $room_mapping[$nid]->booking_room_bedtype != $type_id) elseif ((!empty($room_mapping[$nid])) && $room_mapping[$nid]->booking_room_bedtype != $type_id)
{ {
drupal_set_message(t('Changing person id !id in room !room to new bed type type !type .', $message = t('Changing person id !id in room !room to new bed type type !type .',
array('!id' => $nid, '!room' => $room, '!type' => $type_id, '!oldroom' => $room_mapping[$nid]->booking_roomid))); array('!id' => $nid, '!room' => $room, '!type' => $type_id,
'!oldroom' => $room_mapping[$nid]->booking_roomid));
db_update('booking_room_mapping') db_update('booking_room_mapping')
->fields(array( ->fields(array(
@@ -1013,18 +1057,27 @@ function booking_rooms_allocate_form_submit($form, &$form_state) {
->execute(); ->execute();
} }
//log the result
else watchdog('booking', $message);
{ drupal_set_message($message);
//drupal_set_message(t('Person id !id already has some other room allocation.',
// array('!id' => $nid, '!room' => $room, '!type' => $type_id)));
} }
//this bed has no ID assigned now, but did it have something before?
elseif ($nid == 0 && $previous_nid > 0)
{
$message = t('Removing person !person previously in room id !room with bed index !index.',
array('!room' => $room, '!index' => $index, '!person' => $option[$type]['data']['#value']));
watchdog('booking', $message);
drupal_set_message($message);
} //valid node id check db_delete('booking_room_mapping')
->condition('booking_eventid', $event->eid)
->condition('booking_nodeid', $previous_nid)
->execute();
} //end node checking
} //each bed } //each bed
} //each room } //each room
} //each bed type } //each bed type
} }
/** /**

View File

@@ -323,7 +323,7 @@ $booking_registration_intro_text = variable_get('booking_registration_intro_text
/*Text for emails*/ /*Text for emails*/
$form['emails'] = array( $form['emails'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => 'Built-In Email Text Definitions', '#title' => 'Built-In Workflow Email Definitions',
'#collapsible' => TRUE, '#collapsible' => TRUE,
'#collapsed' => TRUE, '#collapsed' => TRUE,
); );
@@ -355,32 +355,6 @@ $booking_registration_intro_text = variable_get('booking_registration_intro_text
'#description' => t(''), '#description' => t(''),
'#default_value' => variable_get('booking_email_waitinglist_text', $booking_email_waitinglist_text), '#default_value' => variable_get('booking_email_waitinglist_text', $booking_email_waitinglist_text),
); );
$form['emails']['booking_email_travel_required_subject'] = array (
'#type' => 'textfield',
'#title' => t('Subject line for email requesting attendee to complete the travel form'),
'#size' => 150,
'#maxlength' => 300,
'#default_value' => variable_get('booking_email_travel_required_subject','[booking:eventname] Travel Details Required'),
);
$form['emails']['booking_email_travel_required_text'] = array(
'#title' => t('Email text requesting attendee to complete the travel form.'),
'#type' => 'textarea',
'#description' => t(''),
'#default_value' => variable_get('booking_email_travel_required_text', ''),
);
$form['emails']['booking_email_travel_complete_subject'] = array (
'#type' => 'textfield',
'#title' => t('Subject line for email indicating a person has completed the travel form'),
'#size' => 150,
'#maxlength' => 300,
'#default_value' => variable_get('booking_email_travel_complete_subject','[booking:eventname] Travel Details Received'),
);
$form['emails']['booking_email_travel_complete_text'] = array(
'#title' => t('Email text to indicate a person has completed the travel form.'),
'#type' => 'textarea',
'#description' => t(''),
'#default_value' => variable_get('booking_email_travel_complete_text', ''),
);
$form['emails']['booking_email_paymentoutstanding_text'] = array( $form['emails']['booking_email_paymentoutstanding_text'] = array(
'#title' => t('Email text to send a person reminding them of how much they owe'), '#title' => t('Email text to send a person reminding them of how much they owe'),
'#type' => 'textarea', '#type' => 'textarea',
@@ -428,6 +402,32 @@ $booking_registration_intro_text = variable_get('booking_registration_intro_text
'#description' => t(''), '#description' => t(''),
'#default_value' => variable_get('booking_email_missedpayment', ''), '#default_value' => variable_get('booking_email_missedpayment', ''),
); );
$form['emails']['booking_email_travel_required_subject'] = array (
'#type' => 'textfield',
'#title' => t('Subject line for email requesting attendee to complete the travel form'),
'#size' => 150,
'#maxlength' => 300,
'#default_value' => variable_get('booking_email_travel_required_subject','[booking:eventname] Travel Details Required'),
);
$form['emails']['booking_email_travel_required_text'] = array(
'#title' => t('Email text requesting attendee to complete the travel form.'),
'#description' => t('This email will be sent from the !email email address', array('!email' => variable_get('booking_logistics_email'))),
'#type' => 'textarea',
'#default_value' => variable_get('booking_email_travel_required_text', ''),
);
$form['emails']['booking_email_travel_complete_subject'] = array (
'#type' => 'textfield',
'#title' => t('Subject line for email indicating a person has completed the travel form'),
'#size' => 150,
'#maxlength' => 300,
'#default_value' => variable_get('booking_email_travel_complete_subject','[booking:eventname] Travel Details Received'),
);
$form['emails']['booking_email_travel_complete_text'] = array(
'#title' => t('Email text to indicate a person has completed the travel form.'),
'#description' => t('This email will be sent from the !email email address', array('!email' => variable_get('booking_logistics_email'))),
'#type' => 'textarea',
'#default_value' => variable_get('booking_email_travel_complete_text', ''),
);
/*Text for emails*/ /*Text for emails*/
$form['custom-emails'] = array( $form['custom-emails'] = array(