From e690d5b8c85b66803a2bacb28b8f8c18da7231c7 Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Fri, 28 Feb 2014 17:58:15 +1100 Subject: [PATCH] Code refactoring --- booking.register.inc | 8 +++--- booking.travel.inc | 64 +++++++++++++++++++------------------------- 2 files changed, 32 insertions(+), 40 deletions(-) diff --git a/booking.register.inc b/booking.register.inc index 57e2c5b..7feeb34 100644 --- a/booking.register.inc +++ b/booking.register.inc @@ -1525,13 +1525,13 @@ function booking_view($node, $view_mode) { ); } + //TODO: Put study group info here too + $node->content['details'] = array( '#markup' => theme('table', array('header' => $header, 'rows' => $rows)), '#weight' => 1, ); - - - - return $node; + //all finished, let's render this mess + return $node; } diff --git a/booking.travel.inc b/booking.travel.inc index 3e6f16f..65d10b9 100644 --- a/booking.travel.inc +++ b/booking.travel.inc @@ -15,33 +15,25 @@ function booking_travel_page() { return ""; } - //fetch details about the person - /* - $person = db_query("SELECT * FROM {booking_person} " . - "WHERE booking_tempid = :tempid ", - array(':tempid' => arg(1))) - ->fetchObject(); - */ - $person = db_query("SELECT p.*, t.* from {booking_person} p " . - "left outer join {booking_travel} t on p.nid = t.booking_person_nid " . - "where p.booking_event_id = :eid AND p.booking_tempid = :tempid", - array(':tempid' => arg(1), ':eid' => $event->eid)) - ->fetchObject(); + //work out the node id from the session id + $query = db_select('booking_person', 'p'); + $query->condition('p.booking_tempid', arg(1), '=') + ->fields('p', array('nid')); + $person = $query->execute() + ->fetchObject(); + //if we found a matching person if ($person) { - $tokens = booking_define_personspecific_tokens($person); + //load this person's data + $node = node_load($person->nid); + + $tokens = booking_define_personspecific_tokens($node); //watchdog('booking', 'Checking for existing travel form for: @info', array('@info' => var_export($person, TRUE))); //check for an existing travel form - $travelform = db_query("SELECT tid " . - "FROM {booking_travel} " . - "WHERE booking_person_nid = :nid", - array(':nid' => $person->nid)) - ->fetchObject(); - - if ($travelform) + if (! empty( $node->tid )) { $output = token_replace(variable_get('booking_travelform_completed_page'), $tokens); $return_array[] = array('paragraph' => array('#type' => 'markup', '#markup' => $output)); @@ -50,7 +42,7 @@ function booking_travel_page() { else { //Output different text if this is for a married couple - if ((variable_get('booking_enable_combined_pricing', 0) == 1) && $person->booking_partner_id > 0) + if ((variable_get('booking_enable_combined_pricing', 0) == 1) && $node->booking_partner_id > 0) { $output = token_replace(variable_get('booking_travelform_married_page'), $tokens); } @@ -60,9 +52,11 @@ function booking_travel_page() { } $return_array[] = array('paragraph' => array('#type' => 'markup', '#markup' => $output)); - $return_array[] = array('form' => drupal_get_form('travel_form', true, $person->nid)); - } + $return_array[] = array('form' => drupal_get_form('travel_form', true, $node->nid)); + } + return $return_array; + //there was no person matching this session id } else { drupal_set_message("Unable to find matching session ID " . arg(1), 'error', FALSE); return ""; @@ -80,20 +74,24 @@ function travel_form($node, &$form_state, $inserting = FALSE, $nid = 0) $booking_bf_gf_nid = ''; $booking_roommate = ''; + $transport_type_options = array( + 'Driving' => 'Driving', + //'Train' => 'Train', + 'Flying' => 'Flying' + ); + + //there's already info in $node so use that if (!empty($node)) { - $data = $node; - //watchdog('booking', 'Travel form loading data from saved node: @info', array('@info' => var_export($node, TRUE))); - //check for existing booking_person data to use in the form - + $data = $node; } + //otherwise rely on the form state from the previous submission else { $data = $form_state['input']; - //check for existing booking_person data to use in the form - //watchdog('booking', 'Booking registration form loading data from form submission: @info', array('@info' => var_export($form_state, TRUE))); } + //get info about this person from the relevant node id $person = db_query("SELECT booking_dietary, booking_medical_conditions, booking_bf_gf_nid, booking_partner_id, booking_room_mate1 " . "FROM {booking_person} " . "WHERE nid = :nid ", @@ -109,12 +107,6 @@ function travel_form($node, &$form_state, $inserting = FALSE, $nid = 0) $booking_roommate = $person->booking_room_mate1; } - $transport_type_options = array( - 'Driving' => 'Driving', - //'Train' => 'Train', - 'Flying' => 'Flying' - ); - //form starts here //store the node id $form['personid'] = array( @@ -538,7 +530,7 @@ function travel_delete($node) $num_deleted = db_delete('booking_travel') ->condition('tid', $node->nid) ->execute(); - $message = t("Successfully deleted !num row(s), corresponding to person ID !id", + $message = t("Successfully deleted !num row(s) from the booking_travel table, corresponding to person ID !id", array('!num' => $num_deleted, '!id' => $person_id)); drupal_set_message($message, $type = 'status'); }