Code refactoring

This commit is contained in:
2014-02-28 17:58:15 +11:00
parent 481c8251e5
commit e690d5b8c8
2 changed files with 32 additions and 40 deletions

View File

@@ -1525,13 +1525,13 @@ function booking_view($node, $view_mode) {
); );
} }
//TODO: Put study group info here too
$node->content['details'] = array( $node->content['details'] = array(
'#markup' => theme('table', array('header' => $header, 'rows' => $rows)), '#markup' => theme('table', array('header' => $header, 'rows' => $rows)),
'#weight' => 1, '#weight' => 1,
); );
return $node;
//all finished, let's render this mess
return $node;
} }

View File

@@ -15,33 +15,25 @@ function booking_travel_page() {
return ""; return "";
} }
//fetch details about the person //work out the node id from the session id
/* $query = db_select('booking_person', 'p');
$person = db_query("SELECT * FROM {booking_person} " . $query->condition('p.booking_tempid', arg(1), '=')
"WHERE booking_tempid = :tempid ", ->fields('p', array('nid'));
array(':tempid' => arg(1))) $person = $query->execute()
->fetchObject(); ->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();
//if we found a matching person
if ($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))); //watchdog('booking', 'Checking for existing travel form for: @info', array('@info' => var_export($person, TRUE)));
//check for an existing travel form //check for an existing travel form
$travelform = db_query("SELECT tid " . if (! empty( $node->tid ))
"FROM {booking_travel} " .
"WHERE booking_person_nid = :nid",
array(':nid' => $person->nid))
->fetchObject();
if ($travelform)
{ {
$output = token_replace(variable_get('booking_travelform_completed_page'), $tokens); $output = token_replace(variable_get('booking_travelform_completed_page'), $tokens);
$return_array[] = array('paragraph' => array('#type' => 'markup', '#markup' => $output)); $return_array[] = array('paragraph' => array('#type' => 'markup', '#markup' => $output));
@@ -50,7 +42,7 @@ function booking_travel_page() {
else else
{ {
//Output different text if this is for a married couple //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); $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('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; return $return_array;
//there was no person matching this session id
} else { } else {
drupal_set_message("Unable to find matching session ID " . arg(1), 'error', FALSE); drupal_set_message("Unable to find matching session ID " . arg(1), 'error', FALSE);
return ""; return "";
@@ -80,20 +74,24 @@ function travel_form($node, &$form_state, $inserting = FALSE, $nid = 0)
$booking_bf_gf_nid = ''; $booking_bf_gf_nid = '';
$booking_roommate = ''; $booking_roommate = '';
$transport_type_options = array(
'Driving' => 'Driving',
//'Train' => 'Train',
'Flying' => 'Flying'
);
//there's already info in $node so use that
if (!empty($node)) if (!empty($node))
{ {
$data = $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
} }
//otherwise rely on the form state from the previous submission
else else
{ {
$data = $form_state['input']; $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 " . $person = db_query("SELECT booking_dietary, booking_medical_conditions, booking_bf_gf_nid, booking_partner_id, booking_room_mate1 " .
"FROM {booking_person} " . "FROM {booking_person} " .
"WHERE nid = :nid ", "WHERE nid = :nid ",
@@ -109,12 +107,6 @@ function travel_form($node, &$form_state, $inserting = FALSE, $nid = 0)
$booking_roommate = $person->booking_room_mate1; $booking_roommate = $person->booking_room_mate1;
} }
$transport_type_options = array(
'Driving' => 'Driving',
//'Train' => 'Train',
'Flying' => 'Flying'
);
//form starts here //form starts here
//store the node id //store the node id
$form['personid'] = array( $form['personid'] = array(
@@ -538,7 +530,7 @@ function travel_delete($node)
$num_deleted = db_delete('booking_travel') $num_deleted = db_delete('booking_travel')
->condition('tid', $node->nid) ->condition('tid', $node->nid)
->execute(); ->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)); array('!num' => $num_deleted, '!id' => $person_id));
drupal_set_message($message, $type = 'status'); drupal_set_message($message, $type = 'status');
} }