variety registration submit function

This commit is contained in:
Nathan Coad
2018-05-03 09:38:33 +10:00
parent 2521a6fd96
commit 4d0d5b2979
2 changed files with 39 additions and 8 deletions

View File

@@ -797,6 +797,7 @@ function booking_update_7254() {
function booking_update_7255() {
$spec = array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10');
db_change_field('booking_variety_regn', 'booking_node_id', 'booking_person_nid', $spec);
_booking_node_create_mysqlview();
}
/**

View File

@@ -127,7 +127,7 @@ function booking_variety_regn_form_validate($form, &$form_state) {
// Don't run validation on ajax callback
if (isset($form_state['input']['_triggering_element_name'])) {
watchdog('booking_debug', 'booking_variety_regn_form_validate: skipping due to ajax callback');
//watchdog('booking_debug', 'booking_variety_regn_form_validate: skipping due to ajax callback');
return;
}
@@ -162,7 +162,7 @@ function booking_variety_regn_form_validate($form, &$form_state) {
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)));
//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) {
@@ -184,10 +184,7 @@ function booking_variety_regn_form_validate($form, &$form_state) {
$form_state['flag'] = 1;
drupal_set_message('You have selected a session that is now full. Please try again.', 'error', FALSE);
}
}
}
/**
@@ -197,9 +194,42 @@ 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)));
$booking_variety_ids = array();
//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;
//store the selected variety sessions as a json encoded array of IDs in field booking_variety_ids
//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');
foreach ($variety_timeslot_ids as $id) {
$selected_session_id = $values['select-variety-' . $id];
// Don't try and check availablity for a select element that is still on the default value
if ($selected_session_id == 0) {
continue;
}
//use an update query for the regncount field
//idea from https://api.drupal.org/comment/19374#comment-19374
db_update('booking_variety_sessions')
->expression('booking_variety_regncount', 'booking_variety_regncount + :count', array(':count' => 1))
->condition('vid', $selected_session_id)
->execute();
//store the selected variety sessions in an array of IDs
$booking_variety_ids[] = $selected_session_id;
}
//perform the insert to the booking_variety_regn table
db_insert('booking_variety_regn')
->fields(array(
'booking_variety_ids' => implode(",", $booking_variety_ids),
'booking_person_nid' => $values['booking_nid'],
))
->execute();
}