Added table view of individual study group members
This commit is contained in:
@@ -95,6 +95,9 @@ function booking_event_admin_submit($form, &$form_state) {
|
||||
->execute();
|
||||
|
||||
//update menus
|
||||
variable_set('menu_rebuild_needed', TRUE);
|
||||
menu_router_build(TRUE);
|
||||
menu_cache_clear_all();
|
||||
menu_rebuild();
|
||||
|
||||
}
|
||||
|
@@ -303,10 +303,19 @@ function booking_menu() {
|
||||
);
|
||||
|
||||
$items['admin/config/booking/studygroups/view'] = array(
|
||||
'title' => 'View Study Groups',
|
||||
'title' => 'View All Study Groups',
|
||||
'description' => 'View Study Group memberships',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('booking_studygroups_view'),
|
||||
'page arguments' => array('booking_studygroups_view_form', false),
|
||||
'access arguments' => array('access administration pages'),
|
||||
//'type' => MENU_NORMAL_ITEM,
|
||||
);
|
||||
|
||||
$items['admin/config/booking/studygroups/%/view'] = array(
|
||||
'title' => 'View Study Group',
|
||||
'description' => 'View Study Group memberships',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('booking_studygroups_view_form', true, 4),
|
||||
'access arguments' => array('access administration pages'),
|
||||
//'type' => MENU_NORMAL_ITEM,
|
||||
);
|
||||
|
@@ -383,6 +383,7 @@ function booking_csv_report() {
|
||||
$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_helper as session1_helper, s2.booking_session_id as session2, s2.booking_is_leader as session2_leader, s2.booking_is_helper as session2_helper, s3.booking_session_id as session3, s3.booking_is_leader as session3_leader, s3.booking_is_helper as session3_helper, s4.booking_session_id as session4, s4.booking_is_leader as session4_leader, s4.booking_is_helper as session4_helper, s5.booking_session_id as session5, s5.booking_is_leader as session5_leader, s5.booking_is_helper as session5_helper, s6.booking_session_id as session6, s6.booking_is_leader as session6_leader, s6.booking_is_helper as session6_helper from {booking_person} p
|
||||
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
|
||||
@@ -394,7 +395,7 @@ function booking_csv_report() {
|
||||
|
||||
$result = $query->fetchAllAssoc('nid');
|
||||
|
||||
watchdog('booking', "CSV raw data: @info", array('@info' => var_export($result, TRUE)));
|
||||
//watchdog('booking', "CSV raw data: @info", array('@info' => var_export($result, TRUE)));
|
||||
|
||||
//open the filehandle
|
||||
$handle = @fopen($filename, 'w');
|
||||
|
@@ -466,7 +466,107 @@ function booking_studygroups_calculate() {
|
||||
/**
|
||||
* Function for viewing who belongs to which study group
|
||||
*/
|
||||
function booking_studygroups_view() {
|
||||
function booking_studygroups_view_form($node, &$form_state, $single_view, $group_id = -1) {
|
||||
global $event;
|
||||
|
||||
$form = array();
|
||||
$options = array();
|
||||
|
||||
//attach the custom css
|
||||
$form['#attached']['css'] = array(
|
||||
drupal_get_path('module', 'booking') . '/booking.css',
|
||||
);
|
||||
|
||||
if ($single_view == true)
|
||||
{
|
||||
//verify that $group_id is a number
|
||||
if (! preg_match('/^[0-9]+$/', $group_id)) {
|
||||
drupal_set_message("Error: Invalid study group ID supplied. Unable to view group membership.", 'error', FALSE);
|
||||
drupal_goto('admin/config/booking');
|
||||
return "";
|
||||
}
|
||||
|
||||
//collect information on the study group
|
||||
$group = db_query("SELECT * FROM {booking_studygroup_list} WHERE booking_eventid = :eid and sid = :sid",
|
||||
array(':eid' => $event->eid, ':sid' => $group_id))
|
||||
->fetchObject();
|
||||
|
||||
if (! $group)
|
||||
{
|
||||
drupal_set_message("Error: Could not find matching study group ID. Unable to view group membership.", 'error', FALSE);
|
||||
drupal_goto('admin/config/booking');
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
drupal_set_message("Page not yet implemented.", 'error', FALSE);
|
||||
drupal_goto('admin/config/booking');
|
||||
return "";
|
||||
}
|
||||
|
||||
$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', 'sort' => 'asc'),
|
||||
'booking_is_leader' => array('data' => t('Leader?'), 'field' => 'm.booking_is_leader', 'sort' => 'asc'),
|
||||
'booking_is_helper' => array('data' => t('Helper?'), 'field' => 'm.booking_is_helper', 'sort' => 'asc'),
|
||||
);
|
||||
|
||||
$query = db_select('booking_person', 'p');
|
||||
$query->leftJoin('booking_studygroup_mapping', 'm', 'm.booking_node_id = p.nid');
|
||||
|
||||
$db_and = db_and();
|
||||
$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');
|
||||
|
||||
$table_sort = $query->extend('TableSort')->orderbyHeader($header);
|
||||
$result = $table_sort->execute();
|
||||
|
||||
//watchdog('booking', 'Study groups raw data: @info', array ('@info' => var_export($result, TRUE)));
|
||||
|
||||
foreach($result as $data)
|
||||
{
|
||||
//watchdog('booking', 'Study groups raw data: @info', array ('@info' => var_export($data, TRUE)));
|
||||
|
||||
//apply theme as required
|
||||
if ($data->booking_is_leader == 1)
|
||||
$class = "leader-row";
|
||||
elseif ($data->booking_is_helper == 1)
|
||||
$class = "helper-row";
|
||||
else
|
||||
$class = "normal-row";
|
||||
|
||||
$options[$data->nid] = array (
|
||||
'booking_session_id' => $data->booking_session_id,
|
||||
'booking_name' => $data->booking_firstname . " " . $data->booking_lastname,
|
||||
'booking_is_leader' => $data->booking_is_leader == 1 ? 'Yes' : 'No',
|
||||
'booking_is_helper' => $data->booking_is_helper == 1 ? 'Yes' : 'No',
|
||||
'#attributes' => array('id' => array($class))
|
||||
);
|
||||
}
|
||||
|
||||
$prefix = t("<h2>Study Group !descrip</h2>", array('!descrip' => $group->booking_studygroup_descrip));
|
||||
|
||||
$form['table'] = array (
|
||||
'#type' => 'tableselect',
|
||||
'#header' => $header,
|
||||
'#options' => $options,
|
||||
//'#attributes' => array('id' => 'sort-table'),
|
||||
);
|
||||
|
||||
return array (
|
||||
'first_para' => array (
|
||||
'#type' => 'markup',
|
||||
'#markup' => $prefix,
|
||||
),
|
||||
'form' => $form,
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user