Make node_load more generalised
This commit is contained in:
@@ -1024,14 +1024,16 @@ function booking_form_submit($form, &$form_state) {
|
||||
$form_state['redirect'] = array('confirm/' . $tempid);
|
||||
}
|
||||
|
||||
function booking_load($nodes) {
|
||||
/**
|
||||
* Function to query the database for the complete object representing a registration
|
||||
*
|
||||
* @param $node_ids - a list of node IDs to query for
|
||||
* @return list of objects
|
||||
*/
|
||||
function booking_load_query($node_ids = NULL, $fetchAssoc = FALSE)
|
||||
{
|
||||
global $event;
|
||||
//watchdog('booking', 'Loading node with params: @info', array('@info' => var_export($nodes, TRUE)));
|
||||
|
||||
// note that $nodes is an array of object references, keyed by nid
|
||||
// grab the data from our module tables
|
||||
// without an array of field names, 'SELECT * FROM table_alias_name' is assumed
|
||||
|
||||
$query = db_select('booking_person', 'p');
|
||||
//perform an inner join
|
||||
$query->join('booking_price', 'pr', 'p.booking_payment_id = pr.pid');
|
||||
@@ -1050,9 +1052,18 @@ function booking_load($nodes) {
|
||||
'p.nid = s' . $i . '.booking_node_id and s' . $i . '.booking_studygroup_id = ' . $i);
|
||||
}
|
||||
|
||||
//filter the results and select the appropriate fields
|
||||
$query->condition('p.nid', array_keys($nodes), 'IN')
|
||||
->fields('p')
|
||||
//filter the results either by specific nodes if passed as a parameter or by all nodes matching the event id
|
||||
if (! is_null($node_ids))
|
||||
{
|
||||
$query->condition('p.nid', $node_ids, 'IN');
|
||||
}
|
||||
else
|
||||
{
|
||||
$query->condition('p.booking_event_id', $event->eid, '=');
|
||||
}
|
||||
|
||||
//add the fields we want
|
||||
$query->fields('p')
|
||||
->fields('t')
|
||||
->fields('pr', array('booking_price', 'booking_price_descrip','booking_late_price'));
|
||||
|
||||
@@ -1068,19 +1079,42 @@ function booking_load($nodes) {
|
||||
//not looking after study groups so don't add all the extra fields
|
||||
else
|
||||
{
|
||||
//filter the results and select the appropriate fields
|
||||
$query->condition('p.nid', array_keys($nodes), 'IN')
|
||||
->fields('p')
|
||||
//filter the results either by specific nodes if passed as a parameter or by all nodes matching the event id
|
||||
if (! is_null($node_ids))
|
||||
{
|
||||
$query->condition('p.nid', $node_ids, 'IN');
|
||||
}
|
||||
else
|
||||
{
|
||||
$query->condition('p.booking_event_id', $event->eid, '=');
|
||||
}
|
||||
|
||||
//add the fields we want
|
||||
$query->fields('p')
|
||||
->fields('t')
|
||||
->fields('pr', array('booking_price', 'booking_price_descrip','booking_late_price'));
|
||||
->fields('pr', array('booking_price', 'booking_price_descrip','booking_late_price'));
|
||||
}
|
||||
|
||||
|
||||
//get the query result
|
||||
$result = $query->execute();
|
||||
|
||||
//watchdog('booking', 'Loading node via query: @info', array('@info' => $query->__toString()));
|
||||
if ($fetchAssoc == TRUE)
|
||||
{
|
||||
$result = $query->execute()->fetchAllAssoc('nid');
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $query->execute();
|
||||
}
|
||||
|
||||
watchdog('booking', "<pre>Loading node query output:\n@info</pre>", array('@info' => print_r( $result, true)));
|
||||
return $result;
|
||||
}
|
||||
|
||||
function booking_load($nodes) {
|
||||
global $event;
|
||||
|
||||
$result = booking_load_query(array_keys($nodes));
|
||||
|
||||
//add that data to the array of node references
|
||||
foreach ($result as $record)
|
||||
{
|
||||
|
Reference in New Issue
Block a user