This commit is contained in:
Nathan Coad
2018-05-02 13:30:42 +10:00
parent 3c8ed7f1e3
commit f244562358

View File

@@ -9,15 +9,15 @@
function booking_variety_regn_form($node, &$form_state) function booking_variety_regn_form($node, &$form_state)
{ {
global $event; global $event;
$form = array (); $form = array ();
$data = $node; $data = $node;
//$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));
// Query the variety timeslot table // Query the variety timeslot table
$timeslot_query = db_select('booking_variety_times', 'v'); $timeslot_query = db_select('booking_variety_times', 'v');
$timeslot_query->condition('v.booking_eventid', $event->eid, '=') $timeslot_query->condition('v.booking_eventid', $event->eid, '=')
->fields('v') ->fields('v')
->orderBy('v.booking_variety_start'); ->orderBy('v.booking_variety_start');
@@ -29,7 +29,7 @@ function booking_variety_regn_form($node, &$form_state)
$form['booking_nid'] = array( $form['booking_nid'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Booking ID'), '#title' => t('Booking ID'),
'#size' => 60, '#size' => 60,
'#required' => TRUE, '#required' => TRUE,
'#default_value' => !empty($data->booking_nid) ? $data->booking_nid : '', '#default_value' => !empty($data->booking_nid) ? $data->booking_nid : '',
'#ajax' => array( '#ajax' => array(
@@ -45,71 +45,68 @@ function booking_variety_regn_form($node, &$form_state)
$form['variety-sessions'] = array( $form['variety-sessions'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => 'Select Variety Sessions', '#title' => 'Select Variety Sessions',
'#prefix' => '<div id="booking_variety_session_wrapper">', //'#prefix' => '<div id="booking_variety_session_wrapper">',
'#suffix' => '</div>', //'#suffix' => '</div>',
); );
//for each entry in the variety timeslot table, create a new form select item //for each entry in the variety timeslot table, create a new form select item
foreach($result as $timeslot) { foreach($result as $timeslot) {
//create the form element for this timeslot //create the form element for this timeslot
$form['variety-sessions']['select-variety-' . $timeslot->tid] = array( $form['variety-sessions']['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' => _booking_get_variety_timeslot_options($timeslot->tid), '#options' => _booking_get_variety_timeslot_options($timeslot->tid),
'#prefix' => '<div id="booking_variety_session_' . $timeslot->tid . 'wrapper">', '#prefix' => '<div id="booking_variety_session_' . $timeslot->tid . 'wrapper">',
'#suffix' => '</div>', '#suffix' => '</div>',
); );
} }
$form['submit'] = array( $form['submit'] = array(
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Submit'), '#value' => t('Submit'),
); );
return array ( return array (
'form' => $form, 'form' => $form,
); );
} }
function booking_variety_session_callback($form, &$form_state) { function booking_variety_session_callback($form, &$form_state) {
global $event; global $event;
$commands = array();
//$node = $form_state['values']['form_id']; //$node = $form_state['values']['form_id'];
$data = $form_state['input']; $data = $form_state['input'];
watchdog('booking_debug', 'booking_variety_session_callback:<br /><pre>@info</pre>', array('@info' => print_r( $data, true))); //watchdog('booking_debug', 'booking_variety_session_callback:<br /><pre>@info</pre>', array('@info' => print_r( $data, true)));
$commands = array();
// TODO : Update the wrapper for booking ID validity
// Query the variety timeslot table // Query the variety timeslot table
$timeslot_query = db_select('booking_variety_times', 'v'); $timeslot_query = db_select('booking_variety_times', 'v');
$timeslot_query->condition('v.booking_eventid', $event->eid, '=') $timeslot_query->condition('v.booking_eventid', $event->eid, '=')
->fields('v') ->fields('v')
->orderBy('v.booking_variety_start'); ->orderBy('v.booking_variety_start');
$result = $timeslot_query->execute(); $result = $timeslot_query->execute();
//for each entry in the variety timeslot table, create a new form select item //for each entry in the variety timeslot table, create a new form select item
foreach($result as $timeslot) { foreach($result as $timeslot) {
$fieldname = 'select-variety-' . $timeslot->tid; $fieldname = 'select-variety-' . $timeslot->tid;
//re-create the form element for this timeslot //re-create the form element for this timeslot
$form['variety-sessions'][$fieldname] = array( $form['variety-sessions'][$fieldname] = 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' => '', '#options' => _booking_get_variety_timeslot_options($timeslot->tid),
//'#options' => _booking_get_variety_timeslot_options($timeslot->tid),
'#prefix' => '<div id="booking_variety_session_' . $timeslot->tid . 'wrapper">', '#prefix' => '<div id="booking_variety_session_' . $timeslot->tid . 'wrapper">',
'#suffix' => '</div>', '#suffix' => '</div>',
'#default_value' => isset($form_state['values'][$fieldname]) ? $form_state['values'][$fieldname] : '--',
'#options' => array('--'),
'#default_value' => '--',
//isset($form_state['values'][$fieldname]) ? $form_state['values'][$fieldname] : '--',
); );
// Tell drupal to update the wrapper for this field
$commands[] = ajax_command_replace('#booking_variety_session_' . $timeslot->tid . 'wrapper', drupal_render($form['variety-sessions'][$fieldname])); $commands[] = ajax_command_replace('#booking_variety_session_' . $timeslot->tid . 'wrapper', drupal_render($form['variety-sessions'][$fieldname]));
} }
$form_state['rebuild'] = TRUE; $form_state['rebuild'] = TRUE;
@@ -124,20 +121,20 @@ function booking_variety_session_callback($form, &$form_state) {
*/ */
function _booking_get_variety_timeslot_options($timeslot_id) { function _booking_get_variety_timeslot_options($timeslot_id) {
$session_options = array(); $session_options = array();
$session_options[] = "--"; $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_options} WHERE booking_variety_timeslot_id = :tid AND booking_variety_status = 1",
array(':tid' => $timeslot_id)); array(':tid' => $timeslot_id));
// Only add sessions that aren't full to the return result // Only add sessions that aren't full to the return result
foreach($session_query as $session) { foreach($session_query as $session) {
if ($session->booking_variety_regncount < $session->booking_variety_maxsize) { if ($session->booking_variety_regncount < $session->booking_variety_maxsize) {
$session_options[$session->vid] = $session->booking_variety_descrip; $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))); watchdog('booking_debug', "<pre>Variety Session Options:\n@info</pre>", array('@info' => print_r( $session_options, true)));
return $session_options; return $session_options;
} }
/** /**
@@ -149,24 +146,24 @@ function booking_variety_regn_callback($form, &$form_state) {
$data = $form_state['input']; $data = $form_state['input'];
watchdog('booking', '<pre>booking_variety_regn_callback validation:\n@info</pre>', array('@info' => print_r( $data, true))); watchdog('booking', '<pre>booking_variety_regn_callback validation:\n@info</pre>', array('@info' => print_r( $data, true)));
//verify that user-entered data is a number //verify that user-entered data is a number
if (! preg_match('/^[0-9]+$/', $data['booking_nid'])) { if (! preg_match('/^[0-9]+$/', $data['booking_nid'])) {
watchdog('booking_debug', "<pre>booking_variety_regn_callback non-numerical input</pre>"); watchdog('booking_debug', "<pre>booking_variety_regn_callback non-numerical input</pre>");
return '<div id="booking_variety_regn_feedback_wrapper" class="form-item"><span style="color:#8c2e0b;font-weight: bold;">' . return '<div id="booking_variety_regn_feedback_wrapper" class="form-item"><span style="color:#8c2e0b;font-weight: bold;">' .
'You have not entered a valid booking reference number.</span></div>'; 'You have not entered a valid booking reference number.</span></div>';
} }
// Perform lookup on barcode to make sure it matches someone attending the current event // Perform lookup on barcode to make sure it matches someone attending the current event
$db_and = db_and(); $db_and = db_and();
$db_and->condition('p.booking_eventid', $event->eid, '='); $db_and->condition('p.booking_eventid', $event->eid, '=');
$db_and->condition('p.booking_status', 1, '='); $db_and->condition('p.booking_status', 1, '=');
$db_and->condition('p.nid', $data['booking_nid'], '='); $db_and->condition('p.nid', $data['booking_nid'], '=');
$query = db_select('booking_person', 'p'); $query = db_select('booking_person', 'p');
$query->condition($db_and) $query->condition($db_and)
->fields('p'); ->fields('p');
$person = $query->execute() $person = $query->execute()
->fetchObject(); ->fetchObject();
if ($person) { if ($person) {
watchdog('booking_debug', "<pre>booking_variety_regn_callback found valid attendee</pre>"); watchdog('booking_debug', "<pre>booking_variety_regn_callback found valid attendee</pre>");