diff --git a/booking.studygroups.inc b/booking.studygroups.inc index ebe2209..7c37be7 100644 --- a/booking.studygroups.inc +++ b/booking.studygroups.inc @@ -702,14 +702,9 @@ function booking_studygroups_calculate() { // $session_count[$i] = 0; //search for the leaders and helpers for this study group - foreach ($group_mapping as $person) - { - //if ($person->booking_studygroup_id == $group->sid && ($person->booking_is_leader == 'Y' || $person->booking_is_helper == 'Y' || - // $person->booking_is_reserveleader == 'Y')) - + foreach ($group_mapping as $person) { //if the study group id matches the group we're currently looking at, and they have a role defined - if ($person->booking_studygroup_id == $group->sid && $person->booking_studygroup_role > 0) - { + if ($person->booking_studygroup_id == $group->sid && $person->booking_studygroup_role > 0) { drupal_set_message(t('Leader/helper with id !id assigned to session !session (currently with !num people).', array('!id' => $person->booking_node_id, '!session' => $person->booking_session_id, '!num' => $session_count[$person->booking_session_id]['total']) @@ -723,8 +718,7 @@ function booking_studygroups_calculate() { $spouse_id = $working_list[$person->booking_node_id]->booking_partner_id; $bf_gf_id = $working_list[$person->booking_node_id]->booking_bf_gf_nid; - if ($spouse_id > 0) - { + if ($spouse_id > 0) { drupal_set_message(t('Spouse with id !id assigned to session !session (currently with !num people).', array('!id' => $spouse_id, '!session' => $person->booking_session_id, '!num' => $session_count[$person->booking_session_id]['total']) @@ -733,8 +727,7 @@ function booking_studygroups_calculate() { $age = _booking_get_age_years($working_list[$spouse_id]->booking_dob); _booking_assign_attendee_group($spouse_id, $person->booking_session_id, 'female', $age, $working_list, $session_count); } - elseif ($bf_gf_id > 0) - { + elseif ($bf_gf_id > 0) { drupal_set_message(t('BF/GF with id !id assigned to session !session (currently with !num people).', array('!id' => $bf_gf_id, '!session' => $person->booking_session_id, '!num' => $session_count[$person->booking_session_id]['total']) @@ -765,8 +758,9 @@ function booking_studygroups_calculate() { //iterate over the attendee list while ($it->valid()) { //cycle the session counter if we already reached the end - if ($i > $group->booking_num_group_sessions) - $i = 1; + if ($i > $group->booking_num_group_sessions) { + $i = 1; + } //get the current attendee element $current = $it->current(); @@ -842,19 +836,16 @@ function booking_studygroups_calculate() { $insert_query = db_insert('booking_studygroup_mapping')->fields(array('booking_eventid', 'booking_node_id', 'booking_studygroup_id', 'booking_session_id', 'booking_studygroup_role')); - foreach($working_list as $person) - { + foreach($working_list as $person) { //watchdog('booking', "
Working list person:\n@info", array('@info' => print_r( $person, true))); //check to update existing records rather than inserting new one // if already in $group_mapping then just run an update query here $found = FALSE; - foreach ($group_mapping as $mapping) - { + foreach ($group_mapping as $mapping) { //check if we can find a study group session already for this user and this study group (eg Monday Tuesday or Wednesday) - if ($person->nid == $mapping->booking_node_id && $group->sid == $mapping->booking_studygroup_id) - { + if ($person->nid == $mapping->booking_node_id && $group->sid == $mapping->booking_studygroup_id) { $found = TRUE; //drupal_set_message(t('Found existing study group session for user id !id. Running update query on table id !sid to set session id to !session', @@ -1048,115 +1039,119 @@ function booking_studygroups_update_form($node, &$form_state, $sid) { } //search for the leaders helpers, spouses and boyfriend/girlfriend for this study group to pre-allocate - foreach ($group_mapping as $person) - { + foreach ($group_mapping as $person) { //dereference a bunch of fields we'll be using $committee_flag = $working_list[$person->booking_node_id]->booking_committee_member; + $manually_allocated_flag = $working_list[$person->booking_node_id]->booking_session_manually_allocated; $spouse_id = $working_list[$person->booking_node_id]->booking_partner_id; $bf_gf_id = $working_list[$person->booking_node_id]->booking_bf_gf_nid; $gender = $working_list[$person->booking_node_id]->booking_gender == 'M' ? 'male' : 'female'; $session_id = $person->booking_session_id; - //if the study group id matches the group we're currently looking at, and they have a role defined - //or if the group id matches, they are a committee member and this is the readings group - //if (($person->booking_studygroup_id == $group->sid && $person->booking_studygroup_role > 0) || - // ($person->booking_studygroup_id == $group->sid && $committee_flag == 'Y' && $group->sid == $reading_group_id)) - if (($person->booking_studygroup_id == $group->sid && $person->booking_studygroup_role > 0) || - ($person->booking_studygroup_id == $group->sid && $committee_flag == 'Y' && $group->booking_is_readinggroup == 'Y')) - { - $calculation_messages[] = t('Leader/helper/committee with id !id assigned to session !session (currently with !num people).', - array('!id' => $person->booking_node_id, '!session' => $person->booking_session_id, - '!num' => $session_count[$person->booking_session_id]['total']) - ); - - //mark this position as being used - $working_list[$person->booking_node_id]->booking_studygroup_role = $person->booking_studygroup_role; - $age = _booking_get_age_years($working_list[$person->booking_node_id]->booking_dob); - _booking_assign_attendee_group($person->booking_node_id, $session_id, 'male', $age, $working_list, $session_count, $calculation_messages); + //if the study group id matches the group we're currently looking at + if ($person->booking_studygroup_id == $group->sid) { + //if they have a role defined + //or if they are a committee member and this is the readings group + //or if the manually allocated flag is set + //then make sure they stay where they are + if (($person->booking_studygroup_role > 0) || + ($committee_flag == 'Y' && $group->booking_is_readinggroup == 'Y') || + ($manually_allocated_flag == 'Y')) { - //make sure the leader/helper's partner gets updated now, otherwise they could still end up in different groups - if ($spouse_id > 0) - { - //also mark their spouse as allocated to this group - $calculation_messages[] = t('Spouse with id !id assigned to session !session (currently with !num people).', - array('!id' => $spouse_id, '!session' => $person->booking_session_id, + $calculation_messages[] = t('Leader/helper/committee with id !id assigned to session !session (currently with !num people).', + array('!id' => $person->booking_node_id, '!session' => $person->booking_session_id, '!num' => $session_count[$person->booking_session_id]['total']) - ); - $age = _booking_get_age_years($working_list[$spouse_id]->booking_dob); - $spouse_gender = $working_list[$spouse_id]->booking_gender == 'M' ? 'male' : 'female'; - _booking_assign_attendee_group($spouse_id, $session_id, $spouse_gender, $age, $working_list, $session_count, $calculation_messages); - } - elseif ($bf_gf_id > 0) - { - //also mark their boyfriend/girlfriend as allocated to this group - $calculation_messages[] = t('BF/GF with id !id assigned to session !session (currently with !num people).', - array('!id' => $bf_gf_id, '!session' => $person->booking_session_id, - '!num' => $session_count[$person->booking_session_id]['total']) - ); - $age = _booking_get_age_years($working_list[$bf_gf_id]->booking_dob); - $bfgf_gender = $working_list[$bf_gf_id]->booking_gender == 'M' ? 'male' : 'female'; - _booking_assign_attendee_group($bf_gf_id, $session_id, $bfgf_gender, $age, $working_list, $session_count, $calculation_messages); - } - } - //anyone else already assigned to this group previously - elseif ($person->booking_studygroup_id == $group->sid && $working_list[$person->booking_node_id]->processed == 0) - { - if ($spouse_id > 0) - { - //if the spouse has already been processed due to being a leader or helper, use that session - if ($working_list[$spouse_id]->processed == 1) - { - $session_id = $working_list[$spouse_id]->session; - } + ); - //mark this person as allocated to this group - $calculation_messages[] = t('Married person with id !id assigned to session !session (currently with !num people).', - array('!id' => $person->booking_node_id, '!session' => $person->booking_session_id, - '!num' => $session_count[$person->booking_session_id]['total']) - ); + //mark this position as being used + $working_list[$person->booking_node_id]->booking_studygroup_role = $person->booking_studygroup_role; $age = _booking_get_age_years($working_list[$person->booking_node_id]->booking_dob); - _booking_assign_attendee_group($person->booking_node_id, $session_id, $gender, $age, $working_list, $session_count, $calculation_messages); - - //also mark their spouse as allocated to this group - $calculation_messages[] = t('Spouse with id !id assigned to session !session (currently with !num people).', - array('!id' => $spouse_id, '!session' => $person->booking_session_id, - '!num' => $session_count[$person->booking_session_id]['total']) - ); - $age = _booking_get_age_years($working_list[$spouse_id]->booking_dob); - $spouse_gender = $working_list[$spouse_id]->booking_gender == 'M' ? 'male' : 'female'; - _booking_assign_attendee_group($spouse_id, $session_id, $spouse_gender, $age, $working_list, $session_count, $calculation_messages); - } - elseif ($bf_gf_id > 0) - { - //if the bf/gf has already been processed due to being a leader or helper, use that session - if ($working_list[$bf_gf_id]->processed == 1) - { - $session_id = $working_list[$bf_gf_id]->session; + _booking_assign_attendee_group($person->booking_node_id, $session_id, 'male', $age, $working_list, $session_count, $calculation_messages); + + //make sure the leader/helper's partner gets updated now, otherwise they could still end up in different groups + if ($spouse_id > 0) + { + //also mark their spouse as allocated to this group + $calculation_messages[] = t('Spouse with id !id assigned to session !session (currently with !num people).', + array('!id' => $spouse_id, '!session' => $person->booking_session_id, + '!num' => $session_count[$person->booking_session_id]['total']) + ); + $age = _booking_get_age_years($working_list[$spouse_id]->booking_dob); + $spouse_gender = $working_list[$spouse_id]->booking_gender == 'M' ? 'male' : 'female'; + _booking_assign_attendee_group($spouse_id, $session_id, $spouse_gender, $age, $working_list, $session_count, $calculation_messages); } + elseif ($bf_gf_id > 0) + { + //also mark their boyfriend/girlfriend as allocated to this group + $calculation_messages[] = t('BF/GF with id !id assigned to session !session (currently with !num people).', + array('!id' => $bf_gf_id, '!session' => $person->booking_session_id, + '!num' => $session_count[$person->booking_session_id]['total']) + ); + $age = _booking_get_age_years($working_list[$bf_gf_id]->booking_dob); + $bfgf_gender = $working_list[$bf_gf_id]->booking_gender == 'M' ? 'male' : 'female'; + _booking_assign_attendee_group($bf_gf_id, $session_id, $bfgf_gender, $age, $working_list, $session_count, $calculation_messages); + } + } + //anyone else already assigned to this group previously + elseif ($working_list[$person->booking_node_id]->processed == 0) + { + if ($spouse_id > 0) + { + //if the spouse has already been processed due to being a leader or helper, use that session + if ($working_list[$spouse_id]->processed == 1) + { + $session_id = $working_list[$spouse_id]->session; + } + + //mark this person as allocated to this group + $calculation_messages[] = t('Married person with id !id assigned to session !session (currently with !num people).', + array('!id' => $person->booking_node_id, '!session' => $person->booking_session_id, + '!num' => $session_count[$person->booking_session_id]['total']) + ); + $age = _booking_get_age_years($working_list[$person->booking_node_id]->booking_dob); + _booking_assign_attendee_group($person->booking_node_id, $session_id, $gender, $age, $working_list, $session_count, $calculation_messages); + + //also mark their spouse as allocated to this group + $calculation_messages[] = t('Spouse with id !id assigned to session !session (currently with !num people).', + array('!id' => $spouse_id, '!session' => $person->booking_session_id, + '!num' => $session_count[$person->booking_session_id]['total']) + ); + $age = _booking_get_age_years($working_list[$spouse_id]->booking_dob); + $spouse_gender = $working_list[$spouse_id]->booking_gender == 'M' ? 'male' : 'female'; + _booking_assign_attendee_group($spouse_id, $session_id, $spouse_gender, $age, $working_list, $session_count, $calculation_messages); + } + elseif ($bf_gf_id > 0) + { + //if the bf/gf has already been processed due to being a leader or helper, use that session + if ($working_list[$bf_gf_id]->processed == 1) + { + $session_id = $working_list[$bf_gf_id]->session; + } - //mark this person as allocated to this group - $calculation_messages[] = t('Person with id !id in relationship assigned to session !session (currently with !num people).', - array('!id' => $person->booking_node_id, '!session' => $person->booking_session_id, - '!num' => $session_count[$person->booking_session_id]['total']) - ); - $age = _booking_get_age_years($working_list[$person->booking_node_id]->booking_dob); - _booking_assign_attendee_group($person->booking_node_id, $session_id, $gender, $age, $working_list, $session_count, $calculation_messages); - - //also mark their boyfriend/girlfriend as allocated to this group - $calculation_messages[] = t('BF/GF with id !id assigned to session !session (currently with !num people).', - array('!id' => $bf_gf_id, '!session' => $person->booking_session_id, - '!num' => $session_count[$person->booking_session_id]['total']) - ); - $age = _booking_get_age_years($working_list[$bf_gf_id]->booking_dob); - $bfgf_gender = $working_list[$bf_gf_id]->booking_gender == 'M' ? 'male' : 'female'; - _booking_assign_attendee_group($bf_gf_id, $session_id, $bfgf_gender, $age, $working_list, $session_count, $calculation_messages); - } - //for anyone else, just record what session they're currently in - else - { - $working_list[$person->booking_node_id]->session = $session_id; - } - } //end looking at people with spouse or bf/gf + //mark this person as allocated to this group + $calculation_messages[] = t('Person with id !id in relationship assigned to session !session (currently with !num people).', + array('!id' => $person->booking_node_id, '!session' => $person->booking_session_id, + '!num' => $session_count[$person->booking_session_id]['total']) + ); + $age = _booking_get_age_years($working_list[$person->booking_node_id]->booking_dob); + _booking_assign_attendee_group($person->booking_node_id, $session_id, $gender, $age, $working_list, $session_count, $calculation_messages); + + //also mark their boyfriend/girlfriend as allocated to this group + $calculation_messages[] = t('BF/GF with id !id assigned to session !session (currently with !num people).', + array('!id' => $bf_gf_id, '!session' => $person->booking_session_id, + '!num' => $session_count[$person->booking_session_id]['total']) + ); + $age = _booking_get_age_years($working_list[$bf_gf_id]->booking_dob); + $bfgf_gender = $working_list[$bf_gf_id]->booking_gender == 'M' ? 'male' : 'female'; + _booking_assign_attendee_group($bf_gf_id, $session_id, $bfgf_gender, $age, $working_list, $session_count, $calculation_messages); + } + //for anyone else, just record what session they're currently in + else + { + $working_list[$person->booking_node_id]->session = $session_id; + } + } //end looking at people with spouse or bf/gf + } //end checking for matching study group id } //end searching for people to pre-allocate //watchdog('booking', "
Attendee list working copy after pre-processing:\n@info", array('@info' => print_r( $working_list, true)));