add keep separate flag
This commit is contained in:
@@ -739,75 +739,6 @@ function booking_studygroups_update_form($node, &$form_state, $sid) {
|
||||
//allocate everyone else to a session
|
||||
_booking_studygroups_update_allocate($iterator, $max_people, $maximums, $group, $group_mapping, $session_count, $working_list, $calculation_messages);
|
||||
|
||||
/*
|
||||
//reset the iterator to starting position
|
||||
$it->rewind();
|
||||
|
||||
//initialise our counters
|
||||
$session_id = 1;
|
||||
$rewound = FALSE;
|
||||
$i = 1;
|
||||
|
||||
//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;
|
||||
}
|
||||
|
||||
//get the current attendee element
|
||||
$current = $it->current();
|
||||
|
||||
//assign this attendee to this session if unprocessed so far
|
||||
if ($current->processed == 0) {
|
||||
//use their existing study group as a starting point, if already defined
|
||||
if ($current->session > 0) {
|
||||
$start = $current->session;
|
||||
}
|
||||
else {
|
||||
$start = $i;
|
||||
}
|
||||
|
||||
//generate stats about this attendee
|
||||
$gender = $current->booking_gender == 'M' ? 'male' : 'female';
|
||||
$age = _booking_get_age_years($current->booking_dob);
|
||||
|
||||
if ($age < 20) {
|
||||
$age_type = 'under20';
|
||||
}
|
||||
elseif($age >= 20 && $age < 25) {
|
||||
$age_type = '20to25';
|
||||
}
|
||||
else {
|
||||
$age_type = 'over25';
|
||||
}
|
||||
|
||||
//make sure this person is going to fit in with our calculated gender ratios
|
||||
_booking_loop_carefully($session_count, $gender, $start, $maximums[$gender], $group->booking_num_group_sessions, 3, $calculation_messages);
|
||||
//make sure this person is going to fit in with our calculated age ratios
|
||||
_booking_loop_carefully($session_count, $age_type, $start, $maximums[$age_type], $group->booking_num_group_sessions, 3, $calculation_messages);
|
||||
//check for maximum group size
|
||||
_booking_loop_carefully($session_count, 'total', $start, $max_people, $group->booking_num_group_sessions, 4, $calculation_messages);
|
||||
|
||||
$calculation_messages[] = t('Assigning person with id !id with gender !gender and age group !age to session !session (currently with !num people).',
|
||||
array('!id' => $it->key(), '!session' => $start, '!num' => $session_count[$start]['total'], '!gender' => $gender, '!age' => $age_type )
|
||||
);
|
||||
|
||||
_booking_assign_attendee_group($it->key(), $start, $gender, $age, $working_list, $session_count, $calculation_messages);
|
||||
|
||||
} //end processed check
|
||||
|
||||
//move to the next unprocessed attendee in the list
|
||||
while ($it->valid() && $it->current()->processed == 1) {
|
||||
//drupal_set_message(t("Skipping attendee ID !id, already processed.", array('!id' => $it->key())));
|
||||
$it->next();
|
||||
}
|
||||
|
||||
//move to the next session
|
||||
$i++;
|
||||
} //finished looping through attendees for this study group
|
||||
*/
|
||||
|
||||
//now calculate the updates for the database
|
||||
foreach($working_list as $person) {
|
||||
$found = FALSE;
|
||||
@@ -954,6 +885,7 @@ function _booking_studygroups_update_preallocate($group, $group_mapping, &$sessi
|
||||
$manually_allocated_flag = $person->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;
|
||||
$keep_separate_id = $working_list[$person->booking_node_id]->booking_keepseparate_id;
|
||||
$gender = $working_list[$person->booking_node_id]->booking_gender == 'M' ? 'male' : 'female';
|
||||
$session_id = $person->booking_session_id;
|
||||
|
||||
@@ -967,7 +899,7 @@ function _booking_studygroups_update_preallocate($group, $group_mapping, &$sessi
|
||||
($committee_flag == 'Y') ||
|
||||
($manually_allocated_flag == 'Y')) {
|
||||
|
||||
$calculation_messages[] = t('Leader/helper/committee/manual allocation with id !id assigned to session !session (currently with !num people).',
|
||||
$calculation_messages[] = t('Leader/helper/committee/manual allocation with id !id pre-allocated 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'])
|
||||
);
|
||||
@@ -976,6 +908,20 @@ function _booking_studygroups_update_preallocate($group, $group_mapping, &$sessi
|
||||
$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);
|
||||
|
||||
//check if there is someone that should be allocated to a different group than this person
|
||||
if (keep_separate_id > 0) {
|
||||
//work out the next session to assign the other person to
|
||||
$next_session = ($session_id % $group->booking_num_group_sessions) + 1;
|
||||
|
||||
$calculation_messages[] = t('Keeping person with id !id separate from !separate by assigning !separate to session !session (currently with !num people).',
|
||||
array('!id' => $spouse_id, '!session' => $next_session, '!separate' => $keep_separate_id,
|
||||
'!num' => $session_count[$person->booking_session_id]['total'])
|
||||
);
|
||||
$age = _booking_get_age_years($working_list[$keep_separate_id]->booking_dob);
|
||||
$gender = $working_list[$keep_separate_id]->booking_gender == 'M' ? 'male' : 'female';
|
||||
_booking_assign_attendee_group($keep_separate_id, $next_session, $gender, $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) {
|
||||
@@ -1000,7 +946,22 @@ function _booking_studygroups_update_preallocate($group, $group_mapping, &$sessi
|
||||
}
|
||||
}
|
||||
//anyone else already assigned to this group previously
|
||||
elseif ($working_list[$person->booking_node_id]->processed == 0) {
|
||||
//this was checking equal to zero, shouldn't it be equal to 1?
|
||||
elseif ($working_list[$person->booking_node_id]->processed == 1) {
|
||||
//check if there is someone that should be allocated to a different group than this person
|
||||
if (keep_separate_id > 0) {
|
||||
//work out the next session to assign the other person to
|
||||
$next_session = ($session_id % $group->booking_num_group_sessions) + 1;
|
||||
|
||||
$calculation_messages[] = t('Keeping person with id !id separate from !separate by assigning !separate to session !session (currently with !num people).',
|
||||
array('!id' => $spouse_id, '!session' => $next_session, '!separate' => $keep_separate_id,
|
||||
'!num' => $session_count[$person->booking_session_id]['total'])
|
||||
);
|
||||
$age = _booking_get_age_years($working_list[$keep_separate_id]->booking_dob);
|
||||
$gender = $working_list[$keep_separate_id]->booking_gender == 'M' ? 'male' : 'female';
|
||||
_booking_assign_attendee_group($keep_separate_id, $next_session, $gender, $age, $working_list, $session_count, $calculation_messages);
|
||||
}
|
||||
//if there is a spouse or bf/gf then keep them together
|
||||
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) {
|
||||
|
Reference in New Issue
Block a user