This commit is contained in:
Nathan Coad
2016-06-23 09:56:33 +10:00
parent bfb3ac9d48
commit af3660d974

View File

@@ -227,9 +227,6 @@ function booking_studygroup_leadhelp_edit_form($node, &$form_state, $group_id) {
return "";
}
$prefix = t("<h2>Study Group &dash; !descrip</h2><p>Edit leaders and helpers for this group.</p>",
array('!descrip' => $studygroup->booking_studygroup_descrip));
//define the table header
$header = array (
'sid' => array('data' => t('Study Group Session ID'), 'field' => 'sid'),
@@ -243,6 +240,21 @@ function booking_studygroup_leadhelp_edit_form($node, &$form_state, $group_id) {
drupal_get_path('module', 'booking') . '/booking.css',
);
$prefix = t("<h2>Edit Leaders/Helpers for Study Group &dash; !descrip</h2>",
array('!descrip' => $studygroup->booking_studygroup_descrip));
$prefix .= "<p>Enter part of a person's name in the text field and wait for the blue spinning circle to autocomplete with the person's details. " .
"Make sure you click on the person from the dropdown list that appears.</p>";
$form['first_para'] = array (
'#type' => 'markup',
'#markup' => $prefix,
);
//add this to the form in a hidden field so we can update the right studygroup
$form['booking_gid'] = array (
'#type' => 'hidden',
'#value' => $group_id,
);
//create the container element for the whole table
$form['studygroups'] = array(
'#prefix' => '<div id="studygroups">',
@@ -276,7 +288,6 @@ function booking_studygroup_leadhelp_edit_form($node, &$form_state, $group_id) {
//create the rows for the individual sessions (instances really) of this study group
for ($i = 1; $i <= $studygroup->booking_num_group_sessions; $i++) {
$leader = array (
'#id' => 'booking-studygroup-leader-' . $i,
'#type' => 'textfield',
@@ -348,7 +359,44 @@ function booking_studygroup_leadhelp_edit_form($node, &$form_state, $group_id) {
function booking_studygroup_leadhelp_edit_form_submit($form, &$form_state) {
global $event;
//$values = $form_state['input'];
$values = $form_state['input'];
watchdog('booking_debug', "<pre>Studygroup leader/helper test submission form :\n@info</pre>", array('@info' => print_r( $form_state, true)));
}
$role_types = array(
'booking_studygroup_leader' => 1,
'booking_studygroup_helper' => 2,
'booking_studygroup_reserveleader' => 3,
);
//iterate over the different role types
foreach ($role_types as $type => $type_id) {
//iterate over the sessions for that role type
foreach ($values[$type] as $session_id => $person) {
//get the previous value
$previous_value = _booking_studygroup_leadhelp_edit_get_previous_value($form, $type, $session_id);
//compare it against $person
//if $person is now empty, do a delete query
//if $person is now different, run an update query
}
}
}
/**
* look through the previous form data and return the matching element
*/
function _booking_studygroup_leadhelp_edit_get_previous_value(&$form, $type, $session_id) {
foreach($form['form']['studygroups']['#rows'] as $key => $value) {
watchdog('booking_debug', "<pre>Studygroup assignment checker for type !type in session !session:\n@info</pre>",
array('!session' => $session_id, '!type' => $type, '@info' => print_r( $value, true)));
return;
if ((!empty($value[$type]['data']['#value'])) && ($value[$type]['data']['#name'] == $name)) {
//found the correct element, extract the node id
$person = $value[$type]['data']['#value'];
if (preg_match('/[\s\w,]+\s\[(\d+)\]/i', $person, $matches)) {
return $matches[1];
}
}
}
//in case there was no matching value, return an empty string
return 0;
}