tidy up and variety validation work
This commit is contained in:
@@ -14,14 +14,14 @@ function booking_variety_regn_form($node, &$form_state)
|
||||
$data = $node;
|
||||
|
||||
// Query the variety timeslot table
|
||||
$timeslot_query = db_select('booking_variety_times', 'v');
|
||||
$timeslot_query = db_select('booking_variety_timeslots', 'v');
|
||||
$timeslot_query->condition('v.booking_eventid', $event->eid, '=')
|
||||
->fields('v')
|
||||
->orderBy('v.booking_variety_start');
|
||||
$result = $timeslot_query->execute();
|
||||
|
||||
$form['#prefix'] = '<div id="booking_variety_session_form_wrapper">';
|
||||
$form['#suffix'] = '</div>';
|
||||
//$form['#prefix'] = '<div id="booking_variety_session_form_wrapper">';
|
||||
//$form['#suffix'] = '</div>';
|
||||
|
||||
$form['identity'] = array(
|
||||
'#type' => 'fieldset',
|
||||
@@ -93,13 +93,14 @@ function _booking_get_variety_timeslot_options($timeslot_id) {
|
||||
$session_options = array();
|
||||
$session_options[] = "--";
|
||||
|
||||
$session_query = db_query("SELECT * FROM {booking_variety_options} WHERE booking_variety_timeslot_id = :tid AND booking_variety_status = 1",
|
||||
$session_query = db_query("SELECT * FROM {booking_variety_sessions} WHERE booking_variety_timeslot_id = :tid AND booking_variety_status = 1",
|
||||
array(':tid' => $timeslot_id));
|
||||
|
||||
// Only add sessions that aren't full to the return result
|
||||
foreach($session_query as $session) {
|
||||
if ($session->booking_variety_regncount < $session->booking_variety_maxsize) {
|
||||
$session_options[$session->vid] = $session->booking_variety_descrip;
|
||||
$available_spots = $session->booking_variety_maxsize - $session->booking_variety_regncount;
|
||||
if ($available_spots > 0) {
|
||||
$session_options[$session->vid] = $session->booking_variety_descrip . " [" . $available_spots . " spots]";
|
||||
}
|
||||
}
|
||||
//watchdog('booking_debug', "<pre>Variety Session Options:\n@info</pre>", array('@info' => print_r( $session_options, true)));
|
||||
@@ -124,8 +125,6 @@ function booking_variety_regn_form_validate($form, &$form_state) {
|
||||
$values = $form_state['input'];
|
||||
//watchdog('booking_debug', 'booking_variety_regn_form_submit: <pre>@info</pre>', array('@info' => print_r( $form_state, true)));
|
||||
|
||||
//TODO : Check that the booking number is valid for this event
|
||||
|
||||
//verify that user-entered data is a number
|
||||
if (! preg_match('/^[0-9]+$/', $values['booking_nid'])) {
|
||||
form_set_error('booking_nid', t('You have entered an invalid booking reference number.'));
|
||||
@@ -146,6 +145,29 @@ function booking_variety_regn_form_validate($form, &$form_state) {
|
||||
if (! $person) {
|
||||
form_set_error('booking_nid', t('You have entered an invalid booking reference number.'));
|
||||
}
|
||||
|
||||
// --- Check there is still space available in the selected variety sessions ---
|
||||
|
||||
//get a list of timeslot IDs from matching form values
|
||||
$variety_timeslot_ids = preg_filter('/^select-variety-(\d+)/', '$1', array_keys( $values ));
|
||||
|
||||
//query the sessions table
|
||||
$sessions_query = db_query("SELECT * FROM {booking_variety_sessions} WHERE booking_eventid = :eid",
|
||||
array(':eid' => $event->eid));
|
||||
$sessions = $sessions_query->fetchAllAssoc('vid');
|
||||
|
||||
watchdog('booking_debug', 'booking_variety_regn_form_validate sessions query: <pre>@info</pre>', array('@info' => print_r( $sessions, true)));
|
||||
|
||||
//check there is still room
|
||||
foreach ($variety_timeslot_ids as $id) {
|
||||
$selected_session_id = $values['select-variety-' . $id];
|
||||
|
||||
if ($sessions[$selected_session_id]->booking_variety_regncount < $sessions[$selected_session_id]->booking_variety_maxsize) {
|
||||
watchdog('booking_debug', 'Still room in session ' . $selected_session_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,4 +177,7 @@ function booking_variety_regn_form_submit($form, &$form_state) {
|
||||
global $event;
|
||||
$values = $form_state['input'];
|
||||
watchdog('booking_debug', 'booking_variety_regn_form_submit: <pre>@info</pre>', array('@info' => print_r( $form_state, true)));
|
||||
|
||||
//use an update query for the regncount field
|
||||
//based on update booking_variety_sessions set booking_variety_regncount = booking_variety_regncount+1 where vid = 1;
|
||||
}
|
Reference in New Issue
Block a user