ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
ILIAS\Badge\Sorting Class Reference
+ Collaboration diagram for ILIAS\Badge\Sorting:

Public Member Functions

 __construct (string $sort_by='')
 
 compare (array $badge_and_assignment, array $other)
 
 key ()
 
 label ()
 
 options ()
 

Private Member Functions

 reverse ()
 
 minus ()
 

Private Attributes

readonly string $method
 
readonly Closure $compare
 
readonly string $direction
 
readonly string $key
 
readonly string $badgeOrAssignment
 

Detailed Description

Definition at line 27 of file Sorting.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Badge\Sorting::__construct ( string  $sort_by = '')

Definition at line 36 of file Sorting.php.

References ILIAS\Badge\Sorting\$direction, ILIAS\Badge\Sorting\$key, $parts, ILIAS\Badge\Sorting\compare(), ILIAS\Badge\Sorting\key(), and ILIAS\Badge\Sorting\minus().

37  {
38  $parts = explode('_', $sort_by);
39  $what = $parts[0] ?? '';
40  $direction = $parts[1] ?? '';
41 
42  $map = [
43  'title' => ['badge', 'getTitle', 'strcasecmp'],
44  'date' => ['assignment', 'getTimestamp', $this->minus()],
45  ];
46  $directions = ['asc' => 'asc', 'desc' => 'desc'];
47 
48  $key = isset($map[$what]) ? $what : key($map);
49  $direction = $directions[$direction] ?? 'asc';
50 
51  $this->badgeOrAssignment = $map[$key][0];
52  $this->method = $map[$key][1];
53  $this->compare = Closure::fromCallable($map[$key][2]);
54  $this->direction = $direction;
55  $this->key = $key . '_' . $direction;
56  }
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:61
readonly string $key
Definition: Sorting.php:33
readonly string $direction
Definition: Sorting.php:32
compare(array $badge_and_assignment, array $other)
Definition: Sorting.php:63
+ Here is the call graph for this function:

Member Function Documentation

◆ compare()

ILIAS\Badge\Sorting::compare ( array  $badge_and_assignment,
array  $other 
)
Parameters
array{badgeilBadge, assignment: ilBadgeAssignment} $badge_and_assignment
array{badgeilBadge, assignment: ilBadgeAssignment} $other
Returns
int

Definition at line 63 of file Sorting.php.

References ILIAS\Badge\Sorting\$badgeOrAssignment, ILIAS\Badge\Sorting\$compare, ILIAS\Badge\Sorting\$method, and ILIAS\Badge\Sorting\reverse().

Referenced by ILIAS\Badge\Sorting\__construct().

63  : int
64  {
66  $value = $badge_and_assignment[$this->badgeOrAssignment]->$method();
67  $other = $other[$this->badgeOrAssignment]->$method();
68 
69  return $this->reverse() * ($this->compare)($value, $other);
70  }
readonly Closure $compare
Definition: Sorting.php:31
readonly string $badgeOrAssignment
Definition: Sorting.php:34
readonly string $method
Definition: Sorting.php:29
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ key()

ILIAS\Badge\Sorting::key ( )

Definition at line 72 of file Sorting.php.

References ILIAS\Badge\Sorting\$key.

Referenced by ILIAS\Badge\Sorting\__construct(), and ILIAS\Badge\TileView\sortComponent().

72  : string
73  {
74  return $this->key;
75  }
readonly string $key
Definition: Sorting.php:33
+ Here is the caller graph for this function:

◆ label()

ILIAS\Badge\Sorting::label ( )

Definition at line 77 of file Sorting.php.

References ILIAS\Badge\Sorting\$key, and ILIAS\Badge\Sorting\options().

77  : string
78  {
79  return $this->options()[$this->key];
80  }
readonly string $key
Definition: Sorting.php:33
+ Here is the call graph for this function:

◆ minus()

ILIAS\Badge\Sorting::minus ( )
private

Definition at line 100 of file Sorting.php.

Referenced by ILIAS\Badge\Sorting\__construct().

100  : Closure
101  {
102  return static fn(int $x, int $y): int => $x - $y;
103  }
+ Here is the caller graph for this function:

◆ options()

ILIAS\Badge\Sorting::options ( )
Returns
array<string, string>

Definition at line 85 of file Sorting.php.

Referenced by ILIAS\Badge\Sorting\label(), and ILIAS\Badge\TileView\sortComponent().

85  : array
86  {
87  return [
88  'title_asc' => 'sort_by_title_asc',
89  'title_desc' => 'sort_by_title_desc',
90  'date_asc' => 'sort_by_date_asc',
91  'date_desc' => 'sort_by_date_desc',
92  ];
93  }
+ Here is the caller graph for this function:

◆ reverse()

ILIAS\Badge\Sorting::reverse ( )
private

Definition at line 95 of file Sorting.php.

Referenced by ILIAS\Badge\Sorting\compare().

95  : int
96  {
97  return $this->direction === 'asc' ? 1 : -1;
98  }
+ Here is the caller graph for this function:

Field Documentation

◆ $badgeOrAssignment

readonly string ILIAS\Badge\Sorting::$badgeOrAssignment
private

Definition at line 34 of file Sorting.php.

Referenced by ILIAS\Badge\Sorting\compare().

◆ $compare

readonly Closure ILIAS\Badge\Sorting::$compare
private

Definition at line 31 of file Sorting.php.

Referenced by ILIAS\Badge\Sorting\compare().

◆ $direction

readonly string ILIAS\Badge\Sorting::$direction
private

Definition at line 32 of file Sorting.php.

Referenced by ILIAS\Badge\Sorting\__construct().

◆ $key

readonly string ILIAS\Badge\Sorting::$key
private

◆ $method

readonly string ILIAS\Badge\Sorting::$method
private

Definition at line 29 of file Sorting.php.

Referenced by ILIAS\Badge\Sorting\compare().


The documentation for this class was generated from the following file: