Code to manually update studygroup sessions
This commit is contained in:
@@ -344,6 +344,112 @@ function booking_available_leadhelp_select_form_submit($form, &$form_state) {
|
||||
watchdog('booking', $message);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function for manually assigning study group sessions for a person
|
||||
*/
|
||||
function booking_studygroups_edit_form($node, &$form_state, $nid) {
|
||||
global $event;
|
||||
|
||||
//see http://www.jaypan.com/blog/themeing-drupal-7-forms-tables-checkboxes-or-radios
|
||||
$form = array ();
|
||||
$options = array ();
|
||||
$session_options = array();
|
||||
$session_options[0] = '';
|
||||
|
||||
//verify that $nid is a number
|
||||
if (! preg_match('/^[0-9]+$/', $nid)) {
|
||||
drupal_set_message("Error: Invalid registration ID '" . $nid . "' supplied. Unable to edit study group sessions.", 'error', FALSE);
|
||||
drupal_goto('admin/booking/studygroups');
|
||||
return "";
|
||||
}
|
||||
|
||||
//check that this person exists
|
||||
$person = db_query("SELECT person.nid, person.booking_firstname, person.booking_lastname " .
|
||||
"FROM {booking_person} person " .
|
||||
"WHERE nid = :nid",
|
||||
array(':nid' => $nid))
|
||||
->fetchObject();
|
||||
//throw an error if they don't exist
|
||||
if (! $person)
|
||||
{
|
||||
drupal_set_message("Error: Unable to find booking corresponding with registration ID '" . $nid . "'.", 'error', FALSE);
|
||||
drupal_goto('admin/booking/studygroups');
|
||||
return "";
|
||||
}
|
||||
|
||||
$prefix = t("<p>Manually assign/update study group sessions for !first !last. Note: Not yet functional!</p>", array('!first' => $person->booking_firstname, '!last' => $person->booking_lastname));
|
||||
|
||||
//select the groups this person is already assigned to, indexed by studygroup id
|
||||
$person_groups_query = db_query("SELECT * FROM {booking_studygroup_mapping} WHERE booking_eventid = :eid AND booking_node_id = :nid",
|
||||
array(':eid' => $event->eid, ':nid' => $nid));
|
||||
$person_groups = $person_groups_query->fetchAllAssoc('booking_studygroup_id');
|
||||
|
||||
//select all the study groups for this event id
|
||||
$studygroups_query = db_query("SELECT * FROM {booking_studygroup_list} WHERE booking_eventid = :eid", array(':eid' => $event->eid));
|
||||
$studygroups = $studygroups_query->fetchAll();
|
||||
|
||||
//retrieve the number of study group sessions, assume they all have the same number of sessions
|
||||
$num_sessions = reset($studygroups)->booking_num_group_sessions;
|
||||
//create the array for our html select fields
|
||||
for ($i = 1; $i <= $num_sessions; $i++)
|
||||
$session_options[$i] = $i;
|
||||
|
||||
//select any entries already in the mapping table
|
||||
$group_mapping_query = db_query("SELECT * FROM {booking_studygroup_mapping} WHERE booking_eventid = :eid", array(':eid' => $event->eid));
|
||||
$group_mapping = $group_mapping_query->fetchAllAssoc('sid');
|
||||
|
||||
//***form starts here***
|
||||
$header = array(
|
||||
'booking_studygroup_descrip' => array('data' => t('Study Group')),
|
||||
'booking_current_session_id' => array('data' => t('Current Session Number')),
|
||||
'booking_session_id' => array('data' => t('Select Session Number')),
|
||||
);
|
||||
|
||||
//create a new row for each group
|
||||
foreach ($studygroups as $group)
|
||||
{
|
||||
//retrieve the current session id for this group if defined already
|
||||
$default = empty($person_groups[$group->sid]) ? '' : $person_groups[$group->sid]->booking_session_id;
|
||||
|
||||
$options[] = array (
|
||||
'booking_studygroup_descrip' => $group->booking_studygroup_descrip,
|
||||
'booking_current_session_id' => $default,
|
||||
'booking_session_id' => array('data' => array(
|
||||
'#type' => 'select',
|
||||
'#options' => $session_options,
|
||||
'#value' => $default,
|
||||
'#name' => 'booking_assign_sessionid[' . $nid . ']',
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
//so we can access the dropdown elements
|
||||
$form['booking_assign_sessionid'] = array( '#type' => 'value', );
|
||||
|
||||
//generate the render array
|
||||
$form['table'] = array (
|
||||
'#type' => 'tableselect',
|
||||
'#header' => $header,
|
||||
'#options' => $options,
|
||||
);
|
||||
$form['submit'] = array (
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Submit'),
|
||||
);
|
||||
|
||||
return array (
|
||||
'first_para' => array (
|
||||
'#type' => 'markup',
|
||||
'#markup' => $prefix,
|
||||
),
|
||||
'form' => $form,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Function for defining the number of study group sessions
|
||||
* Note: This is hard-coded for now in the install file
|
||||
|
Reference in New Issue
Block a user