ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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 28 of file Sorting.php.

Constructor & Destructor Documentation

◆ __construct()

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

Definition at line 37 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().

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

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

◆ key()

ILIAS\Badge\Sorting::key ( )

Definition at line 73 of file Sorting.php.

References ILIAS\Badge\Sorting\$key.

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

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

◆ label()

ILIAS\Badge\Sorting::label ( )

Definition at line 78 of file Sorting.php.

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

Referenced by ILIAS\Badge\TileView\sortComponent().

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

◆ minus()

ILIAS\Badge\Sorting::minus ( )
private

Definition at line 101 of file Sorting.php.

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

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

◆ options()

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

Definition at line 86 of file Sorting.php.

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

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

◆ reverse()

ILIAS\Badge\Sorting::reverse ( )
private

Definition at line 96 of file Sorting.php.

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

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

Field Documentation

◆ $badgeOrAssignment

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

Definition at line 35 of file Sorting.php.

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

◆ $compare

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

Definition at line 32 of file Sorting.php.

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

◆ $direction

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

Definition at line 33 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 30 of file Sorting.php.

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


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