Skip to content

Commit

Permalink
Fix ordering of functions for committees and organs
Browse files Browse the repository at this point in the history
Ordering is now guaranteed to follow:
- Chair
- Secretary
- Treasurer
- Vice-Chair

If someone has multiple functions then the highest function is used
for the actual ordering. So someone who is both secretary and vice-
chair will be above someone who is treasurer. Likewise, if someone
is treasurer and vice-chair they will still be ranked below chair
and secretary.
  • Loading branch information
tomudding committed Mar 14, 2024
1 parent 3368f55 commit 2354606
Showing 1 changed file with 34 additions and 13 deletions.
47 changes: 34 additions & 13 deletions module/Decision/src/Service/Organ.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,31 @@
use User\Permissions\NotAllowedException;

use function array_filter;
use function array_map;
use function array_merge;
use function count;
use function array_search;
use function floatval;
use function getimagesize;
use function getrandmax;
use function in_array;
use function random_int;
use function round;
use function sys_get_temp_dir;
use function usort;

use const PHP_INT_MAX;

/**
* User service.
*/
class Organ
{
private const array FUNCTION_ORDER = [

Check failure on line 44 in module/Decision/src/Service/Organ.php

View workflow job for this annotation

GitHub Actions / php-codesniffer / PHP_CodeSniffer (8.3)

Class constants must be uppercase; expected ARRAY but found array
'Voorzitter',
'Secretaris',
'Penningmeester',
'Vice-Voorzitter',
];

/**
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification
*/
Expand Down Expand Up @@ -408,17 +417,29 @@ public function getOrganMemberInformation(OrganModel $organ): array
});

// Sort members by function
usort($activeMembers, static function ($a, $b) {
if ($a['functions'] === $b['functions']) {
return 0;
}

if (count($a['functions']) > count($b['functions'])) {
return -1;
}

return in_array('Voorzitter', $a['functions']) ? -1 : 1;
});
usort(
$activeMembers,
static function ($a, $b) {
$aFunctionPriorities = array_map(
function ($function) {

Check failure on line 424 in module/Decision/src/Service/Organ.php

View workflow job for this annotation

GitHub Actions / php-codesniffer / PHP_CodeSniffer (8.3)

Closure not using "$this" should be declared static.
return array_search($function, self::FUNCTION_ORDER);
},
$a['functions'],
);

$bFunctionPriorities = array_map(
function ($function) {

Check failure on line 431 in module/Decision/src/Service/Organ.php

View workflow job for this annotation

GitHub Actions / php-codesniffer / PHP_CodeSniffer (8.3)

Closure not using "$this" should be declared static.
return array_search($function, self::FUNCTION_ORDER);
},
$b['functions'],
);

$aHighestFunction = !empty($aFunctionPriorities) ? min($aFunctionPriorities) : PHP_INT_MAX;

Check failure on line 437 in module/Decision/src/Service/Organ.php

View workflow job for this annotation

GitHub Actions / php-codesniffer / PHP_CodeSniffer (8.3)

Function min() should not be referenced via a fallback global name, but via a use statement.
$bHighestFunction = !empty($bFunctionPriorities) ? min($bFunctionPriorities) : PHP_INT_MAX;

Check failure on line 438 in module/Decision/src/Service/Organ.php

View workflow job for this annotation

GitHub Actions / php-codesniffer / PHP_CodeSniffer (8.3)

Function min() should not be referenced via a fallback global name, but via a use statement.

return $aHighestFunction <=> $bHighestFunction;
},
);

return [
'activeMembers' => $activeMembers,
Expand Down

0 comments on commit 2354606

Please sign in to comment.