Tweaks for study/reading groups
This commit is contained in:
@@ -5,6 +5,41 @@
|
||||
* Admin pages for defining study groups
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Function for listing the study groups and the ability to edit the group definitions
|
||||
*/
|
||||
function booking_studygroups_admin() {
|
||||
|
||||
global $event;
|
||||
$output = "";
|
||||
$header = array('Study Group', 'Session Count', 'Reading Group?', 'Edit Definition');
|
||||
$attributes = array('style' => 'max-width:60%');
|
||||
//$attributes = array();
|
||||
|
||||
//get study groups
|
||||
$query = db_select('booking_studygroup_list', 's')
|
||||
->fields('s')
|
||||
->condition('s.booking_eventid', $event->eid, '=');
|
||||
$result = $query->execute();
|
||||
|
||||
foreach ($result as $group) {
|
||||
$rows[] = array(
|
||||
$group->booking_studygroup_descrip,
|
||||
$group->booking_num_group_sessions,
|
||||
$group->booking_is_readinggroup == 'Y' ? 'Yes' : 'No',
|
||||
l(t('Edit Group Definition', array('!id' => $group->sid)), t('admin/config/booking/studygroups/!id/edit', array('!id' => $group->sid))),
|
||||
);
|
||||
}
|
||||
|
||||
//output everything
|
||||
$output .= t("<h3>!event Study Groups</h3>", array('!event' => $event->booking_eventname));
|
||||
$output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => $attributes));
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for listing the study groups and links to view each one
|
||||
*/
|
||||
@@ -12,7 +47,7 @@ function booking_studygroups_view_summary() {
|
||||
|
||||
global $event;
|
||||
$output = "";
|
||||
$header = array('Study Group', 'Session Count', 'View Membership', 'Compute Membership', 'Select Leaders', 'Edit Definition');
|
||||
$header = array('Study Group', 'Session Count', 'Reading Group?', 'View Membership', 'Compute Membership', 'Select Leaders');
|
||||
//$attributes = array('style' => 'max-width:50%');
|
||||
$attributes = array();
|
||||
|
||||
@@ -26,11 +61,10 @@ function booking_studygroups_view_summary() {
|
||||
$rows[] = array(
|
||||
$group->booking_studygroup_descrip,
|
||||
$group->booking_num_group_sessions,
|
||||
$group->booking_is_readinggroup == 'Y' ? 'Yes' : 'No',
|
||||
l(t('Current Membership', array('!id' => $group->sid)), t('admin/booking/studygroups/!id/view', array('!id' => $group->sid))),
|
||||
l(t('Compute Membership Update', array('!id' => $group->sid)), t('admin/booking/studygroups/!id/update', array('!id' => $group->sid))),
|
||||
l(t('Edit Leaders/Helpers', array('!id' => $group->sid)), t('admin/booking/studygroups/!id/selectleaders', array('!id' => $group->sid))),
|
||||
l(t('Edit Group Definition', array('!id' => $group->sid)), t('admin/booking/studygroups/!id/edit', array('!id' => $group->sid))),
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
@@ -62,7 +96,7 @@ function booking_studygroups_define_form($node, &$form_state, $create, $editid =
|
||||
//verify that $editid is a number
|
||||
if (! preg_match('/^[0-9]+$/', $editid)) {
|
||||
drupal_set_message("Error: Invalid study group ID supplied. Unable to edit study group definition.", 'error', FALSE);
|
||||
drupal_goto('admin/booking/studygroups');
|
||||
drupal_goto('admin/booking/config/studygroups');
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -105,7 +139,7 @@ function booking_studygroups_define_form($node, &$form_state, $create, $editid =
|
||||
'#title' => t('Reading group?'),
|
||||
'#description' => t('Select whether this study group definition is for a reading group. Leave as No unless you want team colours associated with this group'),
|
||||
'#options' => array (0 => t('No'), t('Yes')),
|
||||
'#default_value' => !empty($data->booking_is_readinggroup) ? $data->booking_is_readinggroup : NULL,
|
||||
'#default_value' => !empty($data->booking_is_readinggroup) ? ($data->booking_is_readinggroup == 'Y' ? 1 : 0) : 0,
|
||||
);
|
||||
|
||||
if ($create == true)
|
||||
@@ -150,7 +184,13 @@ function booking_studygroups_define_form_submit($form, &$form_state) {
|
||||
|
||||
global $event;
|
||||
$values = $form_state['input'];
|
||||
$redirect_path = array('admin/booking/studygroups');
|
||||
$redirect_path = array('admin/config/booking/studygroups');
|
||||
$new_count = 0;
|
||||
|
||||
//get the number of study groups before making this update
|
||||
$count = db_query("SELECT count(*) as num FROM {booking_studygroup_list} WHERE booking_eventid = :eid",
|
||||
array(':eid' => $event->eid))->fetchObject();
|
||||
|
||||
|
||||
//watchdog('booking', 'Checkboxes when setting buttons: @info', array ('@info' => var_export($checkboxes, TRUE)));
|
||||
if ($form_state['values']['op'] == 'Create Study Group')
|
||||
@@ -163,6 +203,8 @@ function booking_studygroups_define_form_submit($form, &$form_state) {
|
||||
'booking_is_readinggroup' => $values['booking_is_readinggroup'] == 1 ? 'Y' : 'N',
|
||||
))
|
||||
->execute();
|
||||
|
||||
$new_count = $count->num + 1;
|
||||
}
|
||||
//if we're deleting, add the confirmation to the form if it hasn't been defined yet
|
||||
elseif($form_state['values']['op'] == "Delete Study Group Definition" && (!isset($form_state['storage']['confirm'])))
|
||||
@@ -170,6 +212,8 @@ function booking_studygroups_define_form_submit($form, &$form_state) {
|
||||
watchdog('booking', "<pre>Studygroup deletion confirmation being set:\n@info</pre>", array('@info' => print_r( $form_state, true)));
|
||||
$form_state['storage']['confirm'] = TRUE;
|
||||
$form_state['rebuild'] = TRUE;
|
||||
|
||||
$new_count = $count->num;
|
||||
}
|
||||
elseif ($form_state['values']['op'] == 'Delete Study Group Definition')
|
||||
{
|
||||
@@ -184,7 +228,9 @@ function booking_studygroups_define_form_submit($form, &$form_state) {
|
||||
|
||||
$num_deleted = db_delete('booking_studygroup_list')
|
||||
->condition('sid', $values['booking_sid'])
|
||||
->execute();
|
||||
->execute();
|
||||
|
||||
$new_count = $count->num - 1;
|
||||
}
|
||||
elseif ($form_state['values']['op'] == 'Update Study Group')
|
||||
{
|
||||
@@ -204,8 +250,13 @@ function booking_studygroups_define_form_submit($form, &$form_state) {
|
||||
'booking_is_readinggroup' => $values['booking_is_readinggroup'] == 1 ? 'Y' : 'N',
|
||||
))
|
||||
->condition('sid', $values['booking_sid'])
|
||||
->execute();
|
||||
->execute();
|
||||
|
||||
$new_count = $count->num;
|
||||
}
|
||||
|
||||
|
||||
//update the number of study groups now defined
|
||||
variable_set('booking_studygroup_count', $new_count);
|
||||
|
||||
$form_state['redirect'] = $redirect_path;
|
||||
}
|
Reference in New Issue
Block a user