Tidy up studygroup definition form
This commit is contained in:
@@ -175,7 +175,7 @@ function booking_update_7203() {
|
||||
* Pre-populate the study group sessions table
|
||||
*/
|
||||
function booking_update_7204() {
|
||||
|
||||
/*
|
||||
$result = db_insert('booking_studygroup_list')
|
||||
->fields(array(
|
||||
'booking_eventid' => 2,
|
||||
@@ -456,6 +456,14 @@ function booking_update_7224() {
|
||||
db_add_field('booking_person', 'booking_rtrnflight_destination_ts', $date_spec);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add reading group flag to study group table
|
||||
*/
|
||||
function booking_update_7225() {
|
||||
$spec = array('type' => 'varchar', 'length' => '1', 'not null' => FALSE);
|
||||
db_add_field('booking_studygroup_list', 'booking_is_readinggroup', $spec);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of hook_install().
|
||||
|
@@ -363,14 +363,23 @@ function booking_menu() {
|
||||
);
|
||||
|
||||
$items['admin/booking/studygroups/add'] = array(
|
||||
'title' => 'Add Study Group',
|
||||
'description' => 'Add Study Group definition',
|
||||
'title' => 'Add Study Group Definition',
|
||||
'description' => 'Add Study Group Definition',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('booking_studygroups_define_form', true),
|
||||
'access arguments' => array("edit study groups"),
|
||||
'type' => MENU_LOCAL_ACTION,
|
||||
);
|
||||
|
||||
$items['admin/booking/studygroups/%/edit'] = array(
|
||||
'title' => 'Edit Study Group Definition',
|
||||
'description' => 'Edit Study Group Definition',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('booking_studygroups_define_form', false, 3),
|
||||
'access arguments' => array('edit study groups'),
|
||||
//'type' => MENU_NORMAL_ITEM,
|
||||
);
|
||||
|
||||
$items['admin/booking/studygroups/%/view'] = array(
|
||||
'title' => 'View Study Group',
|
||||
'description' => 'View Study Group memberships',
|
||||
@@ -380,15 +389,6 @@ function booking_menu() {
|
||||
//'type' => MENU_NORMAL_ITEM,
|
||||
);
|
||||
|
||||
$items['admin/booking/%/edit-studygroup'] = array(
|
||||
'title' => 'Edit Study Group Allocation',
|
||||
'description' => 'Manually Update Study Group memberships',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('booking_studygroups_edit_form', 2),
|
||||
'access arguments' => array('edit study groups'),
|
||||
'type' => MENU_CALLBACK,
|
||||
);
|
||||
|
||||
$items['admin/booking/studygroups/%/view/print'] = array(
|
||||
'title' => 'Print Study Group',
|
||||
'description' => 'Print Study Group memberships',
|
||||
@@ -433,6 +433,17 @@ function booking_menu() {
|
||||
'access arguments' => array('edit study groups'),
|
||||
'type' => MENU_LOCAL_ACTION,
|
||||
);
|
||||
|
||||
|
||||
$items['admin/booking/%/edit-studygroup-membership'] = array(
|
||||
'title' => 'Edit Study Group Allocation',
|
||||
'description' => 'Manually Update Study Group memberships',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('booking_studygroups_edit_form', 2),
|
||||
'access arguments' => array('edit study groups'),
|
||||
'type' => MENU_CALLBACK,
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
//configure rooms
|
||||
|
@@ -5,39 +5,6 @@
|
||||
* Admin pages for calculating study group session membership
|
||||
*/
|
||||
|
||||
/**
|
||||
* Function for listing the study groups and links to view each one
|
||||
*/
|
||||
function booking_studygroups_view_summary() {
|
||||
|
||||
global $event;
|
||||
$output = "";
|
||||
$header = array('Study Group', 'Session Count', 'View', 'Select Leaders', 'Auto-Update');
|
||||
$attributes = array('style' => 'max-width:50%');
|
||||
|
||||
//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,
|
||||
l(t('View', array('!id' => $group->sid)), t('admin/booking/studygroups/!id/view', 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('Auto Update', array('!id' => $group->sid)), t('admin/booking/studygroups/!id/update', 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 selecting who is available to lead or help sessions
|
||||
|
@@ -5,6 +5,43 @@
|
||||
* Admin pages for defining study groups
|
||||
*/
|
||||
|
||||
/**
|
||||
* Function for listing the study groups and links to view each one
|
||||
*/
|
||||
function booking_studygroups_view_summary() {
|
||||
|
||||
global $event;
|
||||
$output = "";
|
||||
$header = array('Study Group', 'Session Count', 'View Membership', 'Compute Membership', 'Select Leaders', 'Edit Definition');
|
||||
//$attributes = array('style' => 'max-width:50%');
|
||||
$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,
|
||||
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))),
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
//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;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Form to view or add a studygroup definition
|
||||
*/
|
||||
@@ -15,11 +52,13 @@ function booking_studygroups_define_form($node, &$form_state, $create, $editid =
|
||||
|
||||
if ($create == true)
|
||||
{
|
||||
drupal_set_title('Add Study Group');
|
||||
$data = $node;
|
||||
watchdog('booking', 'Creating new study group: @info', array ('@info' => var_export($node, TRUE)));
|
||||
}
|
||||
else
|
||||
{
|
||||
drupal_set_title('Edit Study Group');
|
||||
//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);
|
||||
@@ -28,7 +67,7 @@ function booking_studygroups_define_form($node, &$form_state, $create, $editid =
|
||||
}
|
||||
|
||||
$data = db_query("SELECT * FROM {booking_studygroup_list} WHERE sid = :id",
|
||||
array(':sid' => $editid))
|
||||
array(':id' => $editid))
|
||||
->fetchObject();
|
||||
$prefix = t("<p>Update the "!event " study group definition.</p>", array('!event' => $data->booking_studygroup_descrip));
|
||||
//add this to the form in a hidden field so we can update the right price
|
||||
@@ -40,6 +79,9 @@ function booking_studygroups_define_form($node, &$form_state, $create, $editid =
|
||||
array ('@info' => var_export($data, TRUE)));
|
||||
}
|
||||
|
||||
|
||||
if(!isset($form_state['storage']['confirm']))
|
||||
{
|
||||
$form['booking_studygroup_descrip'] = array (
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Description of this study group (eg Monday)'),
|
||||
@@ -71,18 +113,18 @@ function booking_studygroups_define_form($node, &$form_state, $create, $editid =
|
||||
$form['submit'] = array
|
||||
(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Create'),
|
||||
'#value' => t('Create Study Group'),
|
||||
);
|
||||
} else {
|
||||
$form['Update'] = array
|
||||
(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Update'),
|
||||
'#value' => t('Update Study Group'),
|
||||
);
|
||||
$form['Delete'] = array
|
||||
(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Delete'),
|
||||
'#value' => t("Delete Study Group Definition"),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -93,4 +135,77 @@ function booking_studygroups_define_form($node, &$form_state, $create, $editid =
|
||||
),
|
||||
'form' => $form,
|
||||
);
|
||||
}
|
||||
//confirm delete
|
||||
else
|
||||
{
|
||||
return confirm_form($form, "Are you sure you wish to delete studygroup definition with id " . $editid . "?",
|
||||
current_path(), NULL, "Delete Study Group Definition");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function booking_studygroups_define_form_submit($form, &$form_state) {
|
||||
|
||||
global $event;
|
||||
$values = $form_state['input'];
|
||||
$redirect_path = array('admin/booking/studygroups');
|
||||
|
||||
//watchdog('booking', 'Checkboxes when setting buttons: @info', array ('@info' => var_export($checkboxes, TRUE)));
|
||||
if ($form_state['values']['op'] == 'Create Study Group')
|
||||
{
|
||||
db_insert('booking_studygroup_list')
|
||||
->fields(array(
|
||||
'booking_eventid' => $event->eid,
|
||||
'booking_studygroup_descrip' => $values['booking_studygroup_descrip'],
|
||||
'booking_num_group_sessions' => $values['booking_num_group_sessions'],
|
||||
'booking_is_readinggroup' => $values['booking_is_readinggroup'] == 1 ? 'Y' : 'N',
|
||||
))
|
||||
->execute();
|
||||
}
|
||||
//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'])))
|
||||
{
|
||||
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;
|
||||
}
|
||||
elseif ($form_state['values']['op'] == 'Delete Study Group Definition')
|
||||
{
|
||||
//verify that booking_pid is a number
|
||||
if (! preg_match('/^[0-9]+$/', $values['booking_sid'])) {
|
||||
drupal_set_message("Error: Invalid studygroup ID supplied. Unable to delete entry.", 'error', FALSE);
|
||||
return "";
|
||||
}
|
||||
|
||||
//TODO: Confirmation
|
||||
//return confirm_form($form, "Really delete price?", 'admin/config/booking/prices');
|
||||
|
||||
$num_deleted = db_delete('booking_studygroup_list')
|
||||
->condition('sid', $values['booking_sid'])
|
||||
->execute();
|
||||
}
|
||||
elseif ($form_state['values']['op'] == 'Update Study Group')
|
||||
{
|
||||
|
||||
//verify that booking_sid is a number
|
||||
if (! preg_match('/^[0-9]+$/', $values['booking_sid'])) {
|
||||
drupal_set_message("Error: Invalid studygroup ID supplied. Unable to update study group.", 'error', FALSE);
|
||||
return "";
|
||||
}
|
||||
|
||||
//update the study group
|
||||
db_update('booking_studygroup_list')
|
||||
->fields(array (
|
||||
'booking_eventid' => $event->eid,
|
||||
'booking_studygroup_descrip' => $values['booking_studygroup_descrip'],
|
||||
'booking_num_group_sessions' => $values['booking_num_group_sessions'],
|
||||
'booking_is_readinggroup' => $values['booking_is_readinggroup'] == 1 ? 'Y' : 'N',
|
||||
))
|
||||
->condition('sid', $values['booking_sid'])
|
||||
->execute();
|
||||
}
|
||||
|
||||
$form_state['redirect'] = $redirect_path;
|
||||
}
|
Reference in New Issue
Block a user