update readings group colours if someone is indivually reassigned
This commit is contained in:
@@ -519,26 +519,23 @@ function booking_studygroups_edit_form_submit($form, &$form_state) {
|
|||||||
array(':eid' => $event->eid, ':nid' => $nid));
|
array(':eid' => $event->eid, ':nid' => $nid));
|
||||||
$person_groups = $person_groups_query->fetchAllAssoc('booking_studygroup_id');
|
$person_groups = $person_groups_query->fetchAllAssoc('booking_studygroup_id');
|
||||||
|
|
||||||
//select all the study groups for this event id
|
//select any readings groups so we know if we need to update colours
|
||||||
$studygroups_query = db_query("SELECT * FROM {booking_studygroup_list} WHERE booking_eventid = :eid", array(':eid' => $event->eid));
|
$reading_groups_query = db_query("SELECT * FROM {booking_studygroup_list} WHERE booking_eventid = :eid AND booking_is_readinggroup = 'Y'", array(':eid' => $event->eid));
|
||||||
$studygroups = $studygroups_query->fetchAll();
|
$reading_groups = $reading_groups_query->fetchAllAssoc('sid');
|
||||||
|
|
||||||
//loop through array of study group IDs and compare against existing database entries
|
//loop through array of study group IDs and compare against existing database entries
|
||||||
foreach ($studygroup_ids as $key => $value)
|
foreach ($studygroup_ids as $key => $value) {
|
||||||
{
|
|
||||||
//watchdog('booking', "<pre>Study Group key:\n@key\nValue\n@value</pre>", array('@key' => print_r( $key, true), '@value' => print_r( $value, true)));
|
//watchdog('booking', "<pre>Study Group key:\n@key\nValue\n@value</pre>", array('@key' => print_r( $key, true), '@value' => print_r( $value, true)));
|
||||||
|
|
||||||
//check if there is a valid value to process
|
//check if there is a valid value to process
|
||||||
if ($value > 0 || $value == 'Remove')
|
if ($value > 0 || $value == 'Remove') {
|
||||||
{
|
|
||||||
//if there was no previous mapping but Remove has been selected anyway, just skip to the next value to look at
|
//if there was no previous mapping but Remove has been selected anyway, just skip to the next value to look at
|
||||||
if (empty($person_groups[$key]) && $value == 'Remove')
|
if (empty($person_groups[$key]) && $value == 'Remove')
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//check to see if we need to remove a study group mapping
|
//check to see if we need to remove a study group mapping
|
||||||
if (! empty($person_groups[$key]) && $value == 'Remove')
|
if (! empty($person_groups[$key]) && $value == 'Remove') {
|
||||||
{
|
|
||||||
watchdog('booking', "Removing an existing Study Group session id: @id from group @group.\n<pre>@info</pre>",
|
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)));
|
array('@id' => $value, '@group' => $key, '@info' => print_r( $person_groups[$key], true)));
|
||||||
|
|
||||||
@@ -547,36 +544,32 @@ function booking_studygroups_edit_form_submit($form, &$form_state) {
|
|||||||
->execute();
|
->execute();
|
||||||
}
|
}
|
||||||
//check for an existing study group mapping to change
|
//check for an existing study group mapping to change
|
||||||
elseif ((!empty($person_groups[$key])) && $person_groups[$key]->booking_session_id != $value)
|
elseif ((!empty($person_groups[$key])) && $person_groups[$key]->booking_session_id != $value) {
|
||||||
{
|
|
||||||
watchdog('booking', "Updating Study Group session from: @key to @value for id @id",
|
watchdog('booking', "Updating Study Group session from: @key to @value for id @id",
|
||||||
array('@key' => $person_groups[$key]->booking_session_id, '@value' => $value, '@id' => $nid));
|
array('@key' => $person_groups[$key]->booking_session_id, '@value' => $value, '@id' => $nid));
|
||||||
|
|
||||||
db_update('booking_studygroup_mapping')
|
db_update('booking_studygroup_mapping')
|
||||||
->fields(array(
|
->fields(array(
|
||||||
'booking_session_id' => $value,
|
'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,
|
|
||||||
'booking_studygroup_role' => $person_groups[$key]->booking_studygroup_role,
|
'booking_studygroup_role' => $person_groups[$key]->booking_studygroup_role,
|
||||||
))
|
))
|
||||||
->condition('sid', $person_groups[$key]->sid)
|
->condition('sid', $person_groups[$key]->sid)
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
if ($key == 7)
|
//check if there is a readings group colour to update
|
||||||
{
|
foreach ($reading_groups as $group) {
|
||||||
booking_studygroups_process_colours();
|
if ($group->sid == $key) {
|
||||||
|
booking_studygroups_process_colours();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//found this entry already, so no change needed
|
//found this entry already, so no change needed
|
||||||
elseif ((!empty($person_groups[$key])) && $person_groups[$key]->booking_session_id == $value)
|
elseif ((!empty($person_groups[$key])) && $person_groups[$key]->booking_session_id == $value) {
|
||||||
{
|
|
||||||
watchdog('booking', "Study Group @group session already set to @session.",
|
watchdog('booking', "Study Group @group session already set to @session.",
|
||||||
array('@group' => $key, '@session' => $value));
|
array('@group' => $key, '@session' => $value));
|
||||||
}
|
}
|
||||||
//no previously defined value, so add a new entry to the mapping table
|
//no previously defined value, so add a new entry to the mapping table
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
watchdog('booking', "Adding Study Group session id: @id for group @group.", array('@id' => $value, '@group' => $key));
|
watchdog('booking', "Adding Study Group session id: @id for group @group.", array('@id' => $value, '@group' => $key));
|
||||||
|
|
||||||
db_insert('booking_studygroup_mapping')
|
db_insert('booking_studygroup_mapping')
|
||||||
@@ -585,20 +578,18 @@ function booking_studygroups_edit_form_submit($form, &$form_state) {
|
|||||||
'booking_node_id' => $nid,
|
'booking_node_id' => $nid,
|
||||||
'booking_studygroup_id' => $key,
|
'booking_studygroup_id' => $key,
|
||||||
'booking_session_id' => $value,
|
'booking_session_id' => $value,
|
||||||
//'booking_is_leader' => 'N',
|
|
||||||
//'booking_is_helper' => 'N',
|
|
||||||
//'booking_is_reserveleader' => 'N',
|
|
||||||
'booking_studygroup_role' => 0,
|
'booking_studygroup_role' => 0,
|
||||||
))
|
))
|
||||||
->execute();
|
->execute();
|
||||||
//@todo fix this - should be dynamic not hard coded
|
//check if there is a readings group colour to update
|
||||||
if ($key == 7)
|
foreach ($reading_groups as $group) {
|
||||||
{
|
if ($group->sid == $key) {
|
||||||
booking_studygroups_process_colours();
|
booking_studygroups_process_colours();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
} //end new value check
|
||||||
}
|
} //end valid data check
|
||||||
}
|
} //end checkbox loop
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user