diff --git a/booking.install b/booking.install
index 4b13875..4e77f9b 100644
--- a/booking.install
+++ b/booking.install
@@ -575,6 +575,15 @@ function booking_update_7236() {
//update the view to match the new table definition
_booking_node_create_mysqlview();
}
+/**
+* Add flag to indicate an attendee that should be kept separate for automated group calculations
+*/
+function booking_update_7237() {
+ $spec = array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'disp-width' => '10', 'default' => 0);
+ db_add_field('booking_person', 'booking_keepseparate_id', $spec);
+ //update the view to match the new table definition
+ _booking_node_create_mysqlview();
+}
/**
* Implementation of hook_install().
@@ -660,7 +669,8 @@ function booking_schema() {
'booking_partner_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'disp-width' => '10'),
'booking_dependant_children' => array('type' => 'varchar', 'length' => '1', 'not null' => TRUE, 'default' => 'N'),
'booking_bf_gf' => array('type' => 'varchar', 'length' => '100', 'not null' => FALSE),
- 'booking_bf_gf_nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'disp-width' => '10'),
+ 'booking_bf_gf_nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'disp-width' => '10'),
+ 'booking_keepseparate_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'disp-width' => '10', 'default' => 0),
'booking_room_mate1' => array('type' => 'varchar', 'length' => '200', 'not null' => FALSE),
'booking_room_mate2' => array('type' => 'varchar', 'length' => '200', 'not null' => FALSE),
//payment info
diff --git a/booking.regn_form.inc b/booking.regn_form.inc
index d4b993f..569c431 100644
--- a/booking.regn_form.inc
+++ b/booking.regn_form.inc
@@ -381,6 +381,16 @@ function booking_form($node, &$form_state, $inserting = FALSE)
'#required' => FALSE,
'#default_value' => !empty($data->booking_bf_gf_nid) ? $data->booking_bf_gf_nid : ''
);
+
+ $form['internal-details']['booking_keepseparate_id'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Registration ID of a person to keep separate when calculating discussion groups. Only a site administrator may set this.'),
+ '#maxlength' => 15,
+ '#size' => 4,
+ '#required' => FALSE,
+ '#default_value' => !empty($data->booking_keepseparate_id) ? $data->booking_keepseparate_id : ''
+ );
+
}
} //end allow couples check
@@ -1170,6 +1180,7 @@ function booking_form_submit($form, &$form_state)
$node->booking_partner_name = empty($values['booking_partner_name']) ? '' : ucwords($values['booking_partner_name']);
$node->booking_partner_id = empty($values['booking_partner_id']) ? 0 : $values['booking_partner_id'];
$node->booking_bf_gf_nid = empty($values['booking_bf_gf_nid']) ? 0 : $values['booking_bf_gf_nid'];
+ $node->booking_keepseparate_id = empty($values['booking_keepseparate_id']) ? 0 : $values['booking_keepseparate_id'];
//allow for user-entered value if the state is not already listed
if ($values['booking_state'] == 'Other') {
diff --git a/booking.regn_node.inc b/booking.regn_node.inc
index 702322c..f7d39b0 100644
--- a/booking.regn_node.inc
+++ b/booking.regn_node.inc
@@ -389,6 +389,7 @@ function booking_update($node) {
'booking_partner_id' => $node->booking_partner_id,
'booking_dependant_children' => $node->booking_dependant_children,
'booking_bf_gf_nid' => $node->booking_bf_gf_nid == '' ? 0 : $node->booking_bf_gf_nid,
+ 'booking_keepseparate_id' => $node->booking_keepseparate_id == '' ? 0 : $node->booking_keepseparate_id,
'booking_room_mate1' => $node->booking_room_mate1,
'booking_room_mate2' => $node->booking_room_mate2,
'booking_random_facts' => $node->booking_random_facts,
@@ -760,7 +761,8 @@ function booking_view($node, $view_mode) {
$rows[] = array(t('Bringing dependant children:'), t('!ans', array('!ans' => ($node->booking_dependant_children == 'Y' ? 'Yes' : 'No'))));
}
$rows[] = array(t('Linked Partner:'), t($partner_name));
- $rows[] = array(t('Linked Boyfriend/Girlfriend:'), t($bf_gf));
+ $rows[] = array(t('Linked Boyfriend/Girlfriend:'), t($bf_gf));
+ $rows[] = array(t('Node ID to keep separate:'), $node->booking_keepseparate_id);
$rows[] = array(t('Home Phone Number:'), t('!home', array('!home' => $node->booking_phone)));
$rows[] = array(t('Mobile Phone Number:'), t('!mob', array('!mob' => $node->booking_mobile)));
$rows[] = array(t('Postal Address:'), t('!street
!suburb !state !code
!country',
diff --git a/booking.studygroups.inc b/booking.studygroups.inc
index 05d5392..579d166 100644
--- a/booking.studygroups.inc
+++ b/booking.studygroups.inc
@@ -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) {