function AAR::getSortOrder in Auto Assign Role 6.2
Same name and namespace in other branches
- 6 tests/autoassignrole.test \AAR::getSortOrder()
Helper function to determine sort order
Parameters
array $data An array of values to check:
Return value
string ASC, DESC or MIXED
1 call to AAR::getSortOrder()
File
- tests/
autoassignrole.test, line 97 - Autoassignrole functionality tests.
Class
- AAR
- @file Autoassignrole functionality tests.
Code
function getSortOrder($data) {
$asc = array();
$desc = array();
foreach ($data as $key => $option) {
if ($option) {
if (!isset($previous)) {
$previous = $option;
}
else {
if ($previous < $option) {
if (count($asc) == 0) {
$asc[] = $previous;
}
$previous = $option;
$asc[] = $option;
}
else {
if (count($desc) == 0) {
$desc[] = $previous;
}
$previous = $option;
$desc[] = $option;
}
}
}
else {
unset($data[$key]);
}
}
if (count($data) == count($asc)) {
return "ASC";
}
if (count($data) == count($desc)) {
return "DESC";
}
return "MIXED";
}