Added table view of individual study group members
This commit is contained in:
@@ -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