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)
|
||||
{
|
||||
|
@@ -433,10 +433,12 @@ function booking_csv_report() {
|
||||
->fields('pr', array('booking_price', 'booking_price_descrip'));
|
||||
$result = $query->execute()->fetchAll();
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
//pivot table based on http://anothermysqldba.blogspot.de/2013/06/pivot-tables-example-in-mysql.html
|
||||
$query = db_query("select distinct p.*, s1.booking_session_id as session1, s1.booking_is_leader as session1_leader, s1.booking_is_reserveleader as session1_reserveleader, s1.booking_is_helper as session1_helper, s2.booking_session_id as session2, s2.booking_is_leader as session2_leader, s2.booking_is_reserveleader as session2_reserveleader, s2.booking_is_helper as session2_helper, s3.booking_session_id as session3, s3.booking_is_leader as session3_leader, s3.booking_is_reserveleader as session3_reserveleader, s3.booking_is_helper as session3_helper, s4.booking_session_id as session4, s4.booking_is_leader as session4_leader, s4.booking_is_reserveleader as session4_reserveleader, s4.booking_is_helper as session4_helper, s5.booking_session_id as session5, s5.booking_is_leader as session5_leader, s5.booking_is_reserveleader as session5_reserveleader, s5.booking_is_helper as session5_helper, s6.booking_session_id as session6, s6.booking_is_leader as session6_leader, s6.booking_is_reserveleader as session6_reserveleader, s6.booking_is_helper as session6_helper, s7.booking_session_id as readinggroup, s7.booking_is_leader as readinggroup_leader, s7.booking_is_reserveleader as readinggroup_reserveleader, s7.booking_is_helper as readinggroup_helper, pr.booking_price, pr.booking_price_descrip from {booking_person} p
|
||||
$query = db_query("select distinct p.*, s1.booking_session_id as session1, s1.booking_is_leader as session1_leader, s1.booking_is_reserveleader as session1_reserveleader, s1.booking_is_helper as session1_helper, s2.booking_session_id as session2, s2.booking_is_leader as session2_leader, s2.booking_is_reserveleader as session2_reserveleader, s2.booking_is_helper as session2_helper, s3.booking_session_id as session3, s3.booking_is_leader as session3_leader, s3.booking_is_reserveleader as session3_reserveleader, s3.booking_is_helper as session3_helper, s4.booking_session_id as session4, s4.booking_is_leader as session4_leader, s4.booking_is_reserveleader as session4_reserveleader, s4.booking_is_helper as session4_helper, s5.booking_session_id as session5, s5.booking_is_leader as session5_leader, s5.booking_is_reserveleader as session5_reserveleader, s5.booking_is_helper as session5_helper, s6.booking_session_id as session6, s6.booking_is_leader as session6_leader, s6.booking_is_reserveleader as session6_reserveleader, s6.booking_is_helper as session6_helper, s7.booking_session_id as readinggroup, s7.booking_is_leader as readinggroup_leader, s7.booking_is_reserveleader as readinggroup_reserveleader, s7.booking_is_helper as readinggroup_helper, pr.booking_price, pr.booking_price_descrip, t.* from {booking_person} p
|
||||
inner join {booking_price} pr on p.booking_payment_id = pr.pid
|
||||
left outer join {booking_travel} t on p.nid = t.booking_person_nid
|
||||
left outer join {booking_studygroup_mapping} s1 on p.nid = s1.booking_node_id and s1.booking_studygroup_id = 1
|
||||
left outer join {booking_studygroup_mapping} s2 on p.nid = s2.booking_node_id and s2.booking_studygroup_id = 2
|
||||
left outer join {booking_studygroup_mapping} s3 on p.nid = s3.booking_node_id and s3.booking_studygroup_id = 3
|
||||
@@ -447,6 +449,9 @@ function booking_csv_report() {
|
||||
where p.booking_event_id = :eid ORDER BY p.nid", array('eid' => $event->eid));
|
||||
|
||||
$result = $query->fetchAllAssoc('nid');
|
||||
*/
|
||||
|
||||
$result = booking_load_query(NULL, TRUE);
|
||||
|
||||
//watchdog('booking', "CSV raw data: @info", array('@info' => var_export($result, TRUE)));
|
||||
|
||||
|
@@ -986,10 +986,13 @@ function booking_studygroups_printview_form($node, &$form_state, $group_id) {
|
||||
$rows = array();
|
||||
$last_session = "";
|
||||
|
||||
/*
|
||||
//attach the custom css
|
||||
$form['#attached']['css'] = array(
|
||||
drupal_get_path('module', 'booking') . '/booking.css',
|
||||
);
|
||||
*/
|
||||
|
||||
|
||||
//verify that $group_id is a number
|
||||
if (! preg_match('/^[0-9]+$/', $group_id)) {
|
||||
@@ -1011,11 +1014,10 @@ function booking_studygroups_printview_form($node, &$form_state, $group_id) {
|
||||
}
|
||||
|
||||
$header = array(
|
||||
'booking_session_id' => array('data' => t('Study Group Session'), 'field' => 'm.booking_session_id', 'sort' => 'asc'),
|
||||
'booking_name' => array('data' => t('Name'), 'field' => 'p.booking_lastname'),
|
||||
'booking_is_leader' => array('data' => t('Leader?'), 'field' => 'm.booking_is_leader'),
|
||||
'booking_is_helper' => array('data' => t('Helper?'), 'field' => 'm.booking_is_helper'),
|
||||
'booking_is_reserveleader' => array('data' => t('Reserve Leader?'), 'field' => 'm.booking_is_reserveleader'),
|
||||
'booking_session_id' => array('data' => t('Study Group Session'), 'field' => 'm.booking_session_id'),
|
||||
'booking_name' => array('data' => t('Name'), 'field' => 'p.booking_lastname', 'sort' => 'asc'),
|
||||
'booking_mobilenum' => array('data' => t('Mobile Number'), 'field' => 'p.booking_mobile'),
|
||||
'booking_studygroup_role' => array('data' => t('Role')),
|
||||
);
|
||||
|
||||
$query = db_select('booking_person', 'p');
|
||||
@@ -1024,22 +1026,35 @@ function booking_studygroups_printview_form($node, &$form_state, $group_id) {
|
||||
$db_and->condition('p.booking_event_id', $event->eid, '=');
|
||||
$db_and->condition('m.booking_studygroup_id', $group_id, '=');
|
||||
$query->condition($db_and);
|
||||
$query->fields('p')->fields('m')->orderBy('p.booking_lastname', 'ASC');
|
||||
$result = $query->execute();
|
||||
$query->fields('p')->fields('m');
|
||||
$table_sort = $query->extend('TableSort')->orderbyHeader($header);
|
||||
$result = $table_sort->execute();
|
||||
|
||||
//$result = $query->execute();
|
||||
|
||||
//watchdog('booking', 'Study groups raw data: @info', array ('@info' => var_export($result, TRUE)));
|
||||
|
||||
foreach($result as $data)
|
||||
{
|
||||
$class = "";
|
||||
$role = "";
|
||||
|
||||
//apply theme as required
|
||||
if ($data->booking_is_leader == 'Y')
|
||||
{
|
||||
$class = "leader-row";
|
||||
$role = "Leader";
|
||||
}
|
||||
elseif ($data->booking_is_helper == 'Y')
|
||||
{
|
||||
$class = "helper-row";
|
||||
$role = "Helper";
|
||||
}
|
||||
elseif ($data->booking_is_reserveleader == 'Y')
|
||||
$class = "helper-row";
|
||||
{
|
||||
$class = "helper-row";
|
||||
$role = "Reserve Leader";
|
||||
}
|
||||
else
|
||||
$class = "normal-row";
|
||||
|
||||
@@ -1047,12 +1062,10 @@ function booking_studygroups_printview_form($node, &$form_state, $group_id) {
|
||||
'data' => array(
|
||||
$data->booking_session_id,
|
||||
$data->booking_firstname . " " . $data->booking_lastname,
|
||||
$data->booking_is_leader == 'Y' ? 'Yes' : 'No',
|
||||
$data->booking_is_helper == 'Y' ? 'Yes' : 'No',
|
||||
$data->booking_is_reserveleader == 'Y' ? 'Yes' : 'No',
|
||||
$data->booking_mobile,
|
||||
$role,
|
||||
),
|
||||
'class' => $class,
|
||||
'no_striping' => TRUE,
|
||||
'class' => array($class),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1066,7 +1079,7 @@ function booking_studygroups_printview_form($node, &$form_state, $group_id) {
|
||||
//'#attributes' => array('id' => 'sort-table'),
|
||||
);
|
||||
*/
|
||||
return array (
|
||||
$result = array (
|
||||
'first_para' => array (
|
||||
'#type' => 'markup',
|
||||
'#markup' => $prefix,
|
||||
@@ -1075,10 +1088,13 @@ function booking_studygroups_printview_form($node, &$form_state, $group_id) {
|
||||
'#theme' => 'table',
|
||||
'#header' => $header,
|
||||
'#rows' => $rows,
|
||||
'#sticky' => FALSE,
|
||||
'#attributes' => array('id' => 'sort-table'),
|
||||
//'#sticky' => FALSE,
|
||||
)
|
||||
);
|
||||
|
||||
watchdog('booking', "<pre>Group printable format:\n@info</pre>", array('@info' => print_r( $result, true)));
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user