Fix the way study group sessions were queried

This commit is contained in:
2015-07-23 20:04:29 +10:00
parent 35d41db948
commit fa24cb3350
4 changed files with 79 additions and 22 deletions

View File

@@ -21,7 +21,8 @@ function booking_node_presave($node) {
function booking_load_query($node_ids = NULL, $fetchAssoc = FALSE)
{
global $event;
$studygroup_count = variable_get('booking_studygroup_count','0');
//$studygroup_count = variable_get('booking_studygroup_count','0');
$studygroups = array();
$query = db_select('booking_person', 'p');
//add price info
@@ -40,11 +41,26 @@ function booking_load_query($node_ids = NULL, $fetchAssoc = FALSE)
//add the joins to flatten out study groups into columns
if (variable_get('booking_enable_studygroups', 0) == 1)
{
//get details of the study groups defined for this event
//but when this function gets called we don't have the global $event variable populated, so do the join here ourselves
//TODO: Fix up all the other places where we stupidly hard coded study group numbers 1 to n instead of using the ids from the database (see commented out for loop below for an example)
$studygroups_query = db_query("SELECT * FROM {booking_studygroup_list} l INNER JOIN {booking_event} e ON l.booking_eventid = e.eid WHERE e.booking_event_active=1");
$studygroups = $studygroups_query->fetchAllAssoc('sid');
foreach ($studygroups as $studygroup)
{
$id = $studygroup->sid;
$query->leftJoin('booking_studygroup_mapping', 's' . $id, 'p.nid = s' . $id . '.booking_node_id and s' . $id . '.booking_studygroup_id = ' . $id);
}
/*
for ($i = 1; $i <= $studygroup_count; $i++)
{
$query->leftJoin('booking_studygroup_mapping', 's' . $i,
'p.nid = s' . $i . '.booking_node_id and s' . $i . '.booking_studygroup_id = ' . $i);
}
*/
}
//filter the results either by specific nodes if passed as a parameter or by all nodes matching the event id
@@ -72,6 +88,14 @@ function booking_load_query($node_ids = NULL, $fetchAssoc = FALSE)
//now add the study group fields if applicable
if (variable_get('booking_enable_studygroups', 0) == 1)
{
foreach ($studygroups as $studygroup)
{
$id = $studygroup->sid;
$query->addField('s' . $id, 'booking_session_id', 'session' . $id);
$query->addField('s' . $id, 'booking_studygroup_role', 'session' . $id . '_role');
}
/*
for ($i = 1; $i <= $studygroup_count; $i++)
{
//$label = "Group_" . $studygroups[$i]->booking_studygroup_descrip;
@@ -82,6 +106,7 @@ function booking_load_query($node_ids = NULL, $fetchAssoc = FALSE)
//$query->addField('s' . $i, 'booking_is_reserveleader', 'session' . $i . '_reserveleader');
//$query->addField('s' . $i, 'booking_is_helper', 'session' . $i . '_helper');
}
*/
}
//get the query result as either an associative array
@@ -802,6 +827,7 @@ function booking_view($node, $view_mode) {
$studygroup_heading = t("<h2>Study Groups</h2><p>!link</p>",
array('!link' => l(t('Edit Groups'), t('admin/booking/!id/edit-studygroup-membership', array('!id' => $node->nid)))
));
$group_rows = array();
//look up the titles of the study groups
$studygroups_query = db_query("SELECT * FROM {booking_studygroup_list} WHERE booking_eventid = :eid",
@@ -810,6 +836,17 @@ function booking_view($node, $view_mode) {
//watchdog('booking', "<pre>Displaying node studygroups query output:\n@info</pre>", array('@info' => print_r( $studygroups, true)));
foreach ($studygroups as $studygroup)
{
//calculate the session references
$sessionid = "session" . $studygroup->sid;
$roleid = $sessionid . "_role";
$group_rows[] = array(t('<b>' . $studygroup->booking_studygroup_descrip . '</b> group number'), $node->$sessionid);
$group_rows[] = array(t('Role'), _booking_studygroup_role_lookup($node->$roleid));
}
/*
for ($i = 1; $i <= variable_get('booking_studygroup_count','0'); $i++)
{
//calculate the session references
@@ -819,16 +856,23 @@ function booking_view($node, $view_mode) {
$group_rows[] = array(t('<b>' . $studygroups[$i]->booking_studygroup_descrip . '</b> group number'), $node->$sessionid);
$group_rows[] = array(t('Role'), _booking_studygroup_role_lookup($node->$roleid));
}
*/
$node->content['group-heading'] = array(
'#markup' => $studygroup_heading,
'#weight' => 8,
);
//only add to the render array if there were some study groups found
if (count($group_rows) > 0)
{
$node->content['group-heading'] = array(
'#markup' => $studygroup_heading,
'#weight' => 8,
);
$node->content['group-details'] = array(
'#markup' => theme('table', array('header' => $header, 'rows' => $group_rows)),
'#weight' => 9,
);
$node->content['group-details'] = array(
'#markup' => theme('table', array('header' => $header, 'rows' => $group_rows)),
'#weight' => 9,
);
}
}
$node->content['details'] = array(