Work on bed allocations

This commit is contained in:
2014-05-27 10:28:28 +10:00
parent 4c75894786
commit 773ba5a101
6 changed files with 255 additions and 147 deletions

View File

@@ -354,6 +354,73 @@ function _date_range_to_string($date_start, $date_end) {
return $final_string;
}
/**
* 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 cleaning up study groups for people that have withdrawn their registration