use mysql view for loading nodes

This commit is contained in:
2016-05-27 15:28:18 +10:00
parent c707f90c97
commit 7336f4d351

View File

@@ -92,6 +92,17 @@ function _booking_node_create_mysqlview()
watchdog('booking_debug', "<pre>Booking Person View creation result:\n@info</pre>", array('@info' => print_r($viewquery, true)));
}
/**
* Function to add single quote marks around a string
* @see booking_load_query
*
* @param $input - string to add quote marks around
* @return quoted string
*/
function _booking_quote_string($input) {
return sprintf("'%s'", $input);
}
/**
* Function to query the database for the complete object representing a registration
*
@@ -100,33 +111,17 @@ function _booking_node_create_mysqlview()
*/
function booking_load_query($node_ids = NULL, $fetchAssoc = FALSE)
{
global $event;
//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 = db_query("SELECT * FROM booking_person_view WHERE nid IN :nid", array(':nid' => $node_ids));
$query = db_query("SELECT * FROM booking_person_view WHERE nid IN (:nid)", array(':nid' => implode(',', $node_ids)));
//$query->condition('p.nid', $node_ids, 'IN');
if (! is_null($node_ids)) {
$nid_string = implode(',', array_map('_booking_quote_string', $node_ids));
$query_string = "SELECT * FROM {booking_person_view} WHERE nid IN ( " . $nid_string . " )";
//watchdog('booking_debug', "<pre>Loading node query:\n@info</pre>", array('@info' => print_r($query_string, true)));
$result = db_query($query_string)->fetchAllAssoc('nid');
}
else
{
$query = db_query("SELECT * FROM booking_person_view");
//$query->condition('p.booking_eventid', $event->eid, '=');
else {
$result = db_query("SELECT * FROM {booking_person_view}")->fetchAllAssoc('nid');
}
watchdog('booking_debug', "<pre>Loading node query:\n@info</pre>", array('@info' => print_r( (string)$query, true)));
//get the query result as either an associative array
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;
}