Added randomisation to study group calculations
This commit is contained in:
@@ -201,6 +201,19 @@ function clone_array($copied_array) {
|
|||||||
}, $copied_array);
|
}, $copied_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//taken from http://stackoverflow.com/questions/4102777/php-random-shuffle-array-maintaining-key-value
|
||||||
|
function 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 for calculating who belongs to which study group
|
* Function for calculating who belongs to which study group
|
||||||
*/
|
*/
|
||||||
@@ -242,7 +255,7 @@ function booking_studygroups_calculate() {
|
|||||||
|
|
||||||
//create a temporary copy of the attendee list to work with for this study group
|
//create a temporary copy of the attendee list to work with for this study group
|
||||||
$working_list = array();
|
$working_list = array();
|
||||||
$working_list = clone_array($attendees);
|
$working_list = shuffle_assoc(clone_array($attendees));
|
||||||
//set up the iterator
|
//set up the iterator
|
||||||
$obj = new ArrayObject( $working_list );
|
$obj = new ArrayObject( $working_list );
|
||||||
$it = $obj->getIterator();
|
$it = $obj->getIterator();
|
||||||
@@ -296,7 +309,7 @@ function booking_studygroups_calculate() {
|
|||||||
//watchdog('booking', 'Attendee before leader check has id !id.', array('!id' => $it->key()));
|
//watchdog('booking', 'Attendee before leader check has id !id.', array('!id' => $it->key()));
|
||||||
|
|
||||||
//check if this attendee is a leader
|
//check if this attendee is a leader
|
||||||
if ($current->processed == 0 && $current->booking_available_lead > 0)
|
if ($current->processed == 0 && $current->booking_available_lead > 0 && $leader_found == FALSE)
|
||||||
{
|
{
|
||||||
drupal_set_message(t('Found available leader with id !id for session !session.', array('!id' => $it->key(), '!session' => $session_id)));
|
drupal_set_message(t('Found available leader with id !id for session !session.', array('!id' => $it->key(), '!session' => $session_id)));
|
||||||
|
|
||||||
@@ -322,7 +335,7 @@ function booking_studygroups_calculate() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//check if this attendee is a helper
|
//check if this attendee is a helper
|
||||||
elseif ($current->processed == 0 && $current->booking_available_help > 0)
|
elseif ($current->processed == 0 && $current->booking_available_help > 0 && $helper_found == FALSE)
|
||||||
{
|
{
|
||||||
drupal_set_message(t('Found available helper with id !id for session !session.', array('!id' => $it->key(), '!session' => $session_id)));
|
drupal_set_message(t('Found available helper with id !id for session !session.', array('!id' => $it->key(), '!session' => $session_id)));
|
||||||
|
|
||||||
@@ -408,8 +421,9 @@ function booking_studygroups_calculate() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//move to the next attendee in the list
|
//move to the next unprocessed attendee in the list
|
||||||
$it->next();
|
while ($it->valid() && $it->current()->processed == 1)
|
||||||
|
$it->next();
|
||||||
|
|
||||||
} //finished looping through session list
|
} //finished looping through session list
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user