diff --git a/booking.studygroup_leaders.inc b/booking.studygroup_leaders.inc index 5dba411..1ae27e3 100644 --- a/booking.studygroup_leaders.inc +++ b/booking.studygroup_leaders.inc @@ -227,9 +227,6 @@ function booking_studygroup_leadhelp_edit_form($node, &$form_state, $group_id) { return ""; } - $prefix = t("

Study Group ‐ !descrip

Edit leaders and helpers for this group.

", - 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("

Edit Leaders/Helpers for Study Group ‐ !descrip

", + array('!descrip' => $studygroup->booking_studygroup_descrip)); + $prefix .= "

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.

"; + $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' => '
', @@ -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', "
Studygroup leader/helper test submission form :\n@info
", array('@info' => print_r( $form_state, true))); -} \ No newline at end of file + $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', "
Studygroup assignment checker for type !type in session !session:\n@info
", + 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; +}