Work on bed allocations
This commit is contained in:
@@ -572,73 +572,6 @@ function booking_studygroups_edit_form_submit($form, &$form_state) {
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Function to correctly clone an associative array storing objects
|
||||
* Taken from http://stackoverflow.com/questions/1532618/is-there-a-function-to-make-a-copy-of-a-php-array-to-another
|
||||
*/
|
||||
function booking_clone_array($copied_array) {
|
||||
return array_map(function($element) {
|
||||
return (
|
||||
((is_array($element))
|
||||
? call_user_func(__FUNCTION__, $element)
|
||||
: ((is_object($element))
|
||||
? clone $element
|
||||
: $element
|
||||
)
|
||||
)
|
||||
);
|
||||
}, $copied_array);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function to randomise the ordering of an array
|
||||
* taken from http://stackoverflow.com/questions/4102777/php-random-shuffle-array-maintaining-key-value
|
||||
*/
|
||||
function booking_shuffle_assoc($list) {
|
||||
if (!is_array($list)) return $list;
|
||||
|
||||
$keys = array_keys($list);
|
||||
shuffle($keys);
|
||||
$random = array();
|
||||
foreach ($keys as $key) {
|
||||
$random[$key] = $list[$key];
|
||||
}
|
||||
return $random;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to mark an attendee as processed for group calculations
|
||||
* @param $input string containing passport number to be verified
|
||||
*/
|
||||
function booking_assign_attendee_group($nid, $session_id, $gender, $age, &$attendee_list, &$session_count)
|
||||
{
|
||||
|
||||
if (empty($nid))
|
||||
{
|
||||
drupal_set_message(t('Attempting to process a non-existent node id.'));
|
||||
return;
|
||||
}
|
||||
|
||||
//mark this person as processed in the working list
|
||||
$attendee_list[$nid]->processed = 1;
|
||||
$attendee_list[$nid]->session = $session_id;
|
||||
|
||||
//record the category of person
|
||||
$session_count[$session_id][$gender]++;
|
||||
$session_count[$session_id]['total']++;
|
||||
|
||||
//record the age bracket
|
||||
//$age = _booking_get_age_years($attendee_list[$nid]->booking_dob);
|
||||
|
||||
if ($age < 20)
|
||||
$session_count[$session_id]['under20']++;
|
||||
elseif($age >= 20 && $age < 25)
|
||||
$session_count[$session_id]['20to25']++;
|
||||
else
|
||||
$session_count[$session_id]['over25']++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for calculating who belongs to which study group
|
||||
*/
|
||||
@@ -731,7 +664,7 @@ function booking_studygroups_calculate() {
|
||||
|
||||
//create a temporary copy of the attendee list to work with for this study group
|
||||
$working_list = array();
|
||||
$working_list = booking_shuffle_assoc(booking_clone_array($attendees));
|
||||
$working_list = _booking_shuffle_assoc(_booking_clone_array($attendees));
|
||||
//set up the iterator
|
||||
$obj = new ArrayObject( $working_list );
|
||||
$it = $obj->getIterator();
|
||||
@@ -764,7 +697,7 @@ function booking_studygroups_calculate() {
|
||||
|
||||
//mark this position as being used
|
||||
$age = _booking_get_age_years($working_list[$person->booking_node_id]->booking_dob);
|
||||
booking_assign_attendee_group($person->booking_node_id, $person->booking_session_id, 'male', $age, $working_list, $session_count);
|
||||
_booking_assign_attendee_group($person->booking_node_id, $person->booking_session_id, 'male', $age, $working_list, $session_count);
|
||||
|
||||
//get any potential spouse or boyfriend/girlfriend
|
||||
$spouse_id = $working_list[$person->booking_node_id]->booking_partner_id;
|
||||
@@ -778,7 +711,7 @@ function booking_studygroups_calculate() {
|
||||
));
|
||||
//allocate the spouse to the same session
|
||||
$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);
|
||||
_booking_assign_attendee_group($spouse_id, $person->booking_session_id, 'female', $age, $working_list, $session_count);
|
||||
}
|
||||
elseif ($bf_gf_id > 0)
|
||||
{
|
||||
@@ -787,7 +720,7 @@ function booking_studygroups_calculate() {
|
||||
'!num' => $session_count[$person->booking_session_id]['total'])
|
||||
));
|
||||
//allocate the boyfriend/girlfriend to the same session
|
||||
booking_assign_attendee_group($bf_gf_id, $person->booking_session_id, $working_list[$bf_gf_id]->booking_gender == 'M' ? 'male' : 'female',
|
||||
_booking_assign_attendee_group($bf_gf_id, $person->booking_session_id, $working_list[$bf_gf_id]->booking_gender == 'M' ? 'male' : 'female',
|
||||
_booking_get_age_years($working_list[$bf_gf_id]->booking_dob), $working_list, $session_count);
|
||||
}
|
||||
}
|
||||
@@ -864,7 +797,7 @@ function booking_studygroups_calculate() {
|
||||
$partner_id = $current->booking_partner_id;
|
||||
$bf_gf_id = $current->booking_bf_gf_nid;
|
||||
|
||||
booking_assign_attendee_group($it->key(), $i, $gender, $age, $working_list, $session_count);
|
||||
_booking_assign_attendee_group($it->key(), $i, $gender, $age, $working_list, $session_count);
|
||||
|
||||
//check if the attendee was married
|
||||
if ($partner_id > 0)
|
||||
@@ -873,7 +806,7 @@ function booking_studygroups_calculate() {
|
||||
drupal_set_message(t('Assigning spouse (id !spouse) of id !id to session !session (currently with !num people).',
|
||||
array('!id' => $it->key(), '!session' => $i, '!spouse' => $current->booking_partner_id, '!num' => $session_count[$i]['total'])));
|
||||
|
||||
booking_assign_attendee_group($partner_id, $i, $working_list[$partner_id]->booking_gender == 'M' ? 'male' : 'female',
|
||||
_booking_assign_attendee_group($partner_id, $i, $working_list[$partner_id]->booking_gender == 'M' ? 'male' : 'female',
|
||||
_booking_get_age_years($working_list[$partner_id]->booking_dob), $working_list, $session_count);
|
||||
}
|
||||
|
||||
@@ -884,7 +817,7 @@ function booking_studygroups_calculate() {
|
||||
drupal_set_message(t('Assigning bf/gf (id !spouse) of id !id to session !session (currently with !num people).',
|
||||
array('!id' => $it->key(), '!session' => $i, '!spouse' => $current->booking_bf_gf_nid, '!num' => $session_count[$i]['total'])));
|
||||
|
||||
booking_assign_attendee_group($bf_gf_id, $i, $working_list[$bf_gf_id]->booking_gender == 'M' ? 'male' : 'female',
|
||||
_booking_assign_attendee_group($bf_gf_id, $i, $working_list[$bf_gf_id]->booking_gender == 'M' ? 'male' : 'female',
|
||||
_booking_get_age_years($working_list[$bf_gf_id]->booking_dob), $working_list, $session_count);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user