Further work on manual studygroup assignment
This commit is contained in:
@@ -378,7 +378,7 @@ function booking_studygroups_edit_form($node, &$form_state, $nid) {
|
||||
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));
|
||||
$prefix = t("<p>Manually assign/update study group sessions for !first !last.<br />If updating an existing session ID, this will also copy any role assigned (leader, helper, etc).</p><p><b>Note: Still under testing!</b></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",
|
||||
@@ -393,7 +393,11 @@ function booking_studygroups_edit_form($node, &$form_state, $nid) {
|
||||
$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;
|
||||
}
|
||||
|
||||
$session_options['Remove'] = 'Remove';
|
||||
|
||||
//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));
|
||||
@@ -473,7 +477,7 @@ function booking_studygroups_edit_form_submit($form, &$form_state) {
|
||||
global $event;
|
||||
$counter = 0;
|
||||
$checkboxes = $form_state['values']['table'];
|
||||
$studygroup_sessionids = $form_state['values']['booking_assign_sessionid'];
|
||||
$studygroup_ids = $form_state['values']['booking_assign_sessionid'];
|
||||
$values = $form_state['input'];
|
||||
|
||||
//check that $values['personid'] is a number
|
||||
@@ -491,12 +495,62 @@ function booking_studygroups_edit_form_submit($form, &$form_state) {
|
||||
array(':eid' => $event->eid, ':nid' => $nid));
|
||||
$person_groups = $person_groups_query->fetchAllAssoc('booking_studygroup_id');
|
||||
|
||||
//TODO:
|
||||
//
|
||||
//loop through $studygroup_sessionids
|
||||
//compare each value to $person_groups
|
||||
//if there is a difference, update the table
|
||||
//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();
|
||||
|
||||
//loop through array of study group IDs and compare against existing database entries
|
||||
foreach ($studygroup_ids as $key => $value)
|
||||
{
|
||||
//check if there is a valid value to process
|
||||
if ($value > 0 || $value == 'Remove')
|
||||
{
|
||||
|
||||
//watchdog('booking', "<pre>Study Group key:\n@key\nValue\n@value</pre>", array('@key' => print_r( $key, true), '@value' => print_r( $value, true)));
|
||||
|
||||
//check to see if we need to remove a study group mapping
|
||||
if (! empty($person_groups[$key]) && $value == 'Remove')
|
||||
{
|
||||
watchdog('booking', "Removing an existing Study Group session id: @id from group @group.\n<pre>@info</pre>", array('@id' => $value, '@group' => $key, '@info' => print_r( $person_groups[$key], true)));
|
||||
|
||||
$num_deleted = db_delete('booking_studygroup_mapping')
|
||||
->condition('sid', $person_groups[$key]->sid)
|
||||
->execute();
|
||||
}
|
||||
//check for an existing study group mapping to change
|
||||
elseif (! empty($person_groups[$key]) && $person_groups[$key]->booking_session_id != $value)
|
||||
{
|
||||
watchdog('booking', "Updating Study Group session from: @key to @value", array('@key' => $person_groups[$key]->booking_session_id, '@value' => $value));
|
||||
|
||||
db_update('booking_studygroup_mapping')
|
||||
->fields(array(
|
||||
'booking_session_id' => $value,
|
||||
'booking_is_leader' => $person_groups[$key]->booking_is_leader,
|
||||
'booking_is_helper' => $person_groups[$key]->booking_is_helper,
|
||||
'booking_is_reserveleader' => $person_groups[$key]->booking_is_reserveleader,
|
||||
))
|
||||
->condition('sid', $person_groups[$key]->sid)
|
||||
->execute();
|
||||
}
|
||||
//no previously defined value, so add a new entry to the mapping table
|
||||
else
|
||||
{
|
||||
watchdog('booking', "Adding Study Group session id: @id for group @group.", array('@id' => $value, '@group' => $key));
|
||||
|
||||
db_insert('booking_studygroup_mapping')
|
||||
->fields(array(
|
||||
'booking_eventid' => $event->eid,
|
||||
'booking_node_id' => $nid,
|
||||
'booking_studygroup_id' => $key,
|
||||
'booking_session_id' => $value,
|
||||
'booking_is_leader' => 'N',
|
||||
'booking_is_helper' => 'N',
|
||||
'booking_is_reserveleader' => 'N',
|
||||
))
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user