make session values dynamic

This commit is contained in:
Nathan Coad
2018-05-02 11:49:47 +10:00
parent c1957a6c83
commit 2c59c26cbd

View File

@@ -12,7 +12,6 @@ function booking_variety_regn_form($node, &$form_state)
global $event; global $event;
$form = array (); $form = array ();
$data = $node; $data = $node;
$timeslot_count = 0;
$query = db_query("SELECT * FROM {booking_variety_times} WHERE booking_eventid = :eid AND booking_variety_status = 1", $query = db_query("SELECT * FROM {booking_variety_times} WHERE booking_eventid = :eid AND booking_variety_status = 1",
array(':eid' => $event->eid)); array(':eid' => $event->eid));
@@ -58,19 +57,16 @@ function booking_variety_regn_form($node, &$form_state)
} }
//create the form element for this timeslot //create the form element for this timeslot
$form['select-variety-' . $timeslot_count] = array( $form['select-variety-' . $timeslot->tid] = array(
'#type' => 'select', '#type' => 'select',
'#title' => t('Variety Session: ' . $timeslot->booking_variety_time_descrip), '#title' => t('Variety Session: ' . $timeslot->booking_variety_time_descrip),
'#required' => TRUE, '#required' => TRUE,
'#default_value' => '', '#default_value' => '',
'#options' => $options, '#options' => _booking_get_variety_timeslot_options($timeslot->tid),
); );
$timeslot_count++;
} }
$form['submit'] = array $form['submit'] = array(
(
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Submit'), '#value' => t('Submit'),
); );
@@ -78,9 +74,30 @@ function booking_variety_regn_form($node, &$form_state)
return array ( return array (
'form' => $form, 'form' => $form,
); );
} }
/**
* Function to calculate available variety sessions for ajax enabled form booking_variety_regn_form()
* @param $timeslot_id - the timeslot ID to query
* @return array containing the variety sessions for specified timeslot that still have capacity
*/
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",
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;
}
}
watchdog('booking_debug', "<pre>Variety Session Options:\n@info</pre>", array('@info' => print_r( $session_options, true)));
return $session_options;
}
/** /**
* Callback function to verify if barcode was valid * Callback function to verify if barcode was valid