ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\Cron\Job\Collection\OrderedJobEntities Class Reference
+ Inheritance diagram for ILIAS\Cron\Job\Collection\OrderedJobEntities:
+ Collaboration diagram for ILIAS\Cron\Job\Collection\OrderedJobEntities:

Public Member Functions

 __construct (private readonly \ILIAS\Cron\Job\JobCollection $origin, mixed $sort, bool $reverse_order=false)
 
 getIterator ()
 
 count ()
 
 add (\ILIAS\Cron\Job\JobEntity $job)
 
 filter (callable $callable)
 Returns all the elements of this collection that satisfy the predicate $callable. More...
 
 slice (int $offset, ?int $length=null)
 Extracts a slice of $length elements starting at position $offset from the Collection. More...
 
 toArray ()
 
 add (\ILIAS\Cron\Job\JobEntity $job)
 
 filter (callable $callable)
 Returns all the elements of this collection that satisfy the predicate $callable. More...
 
 slice (int $offset, ?int $length=null)
 Extracts a slice of $length elements starting at position $offset from the Collection. More...
 
 toArray ()
 

Data Fields

final const int ORDER_BY_NONE = 0
 
final const int ORDER_BY_NAME = 1
 
final const int ORDER_BY_STATUS = 2
 
final const int ORDER_AS_PROVIDED = 1
 
final const int ORDER_REVERSE = -1
 

Private Member Functions

 getSortedJobs ()
 

Private Attributes

mixed $sort
 
array $sorted_jobs = null
 

Detailed Description

Definition at line 23 of file OrderedJobEntities.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Cron\Job\Collection\OrderedJobEntities::__construct ( private readonly \ILIAS\Cron\Job\JobCollection  $origin,
mixed  $sort,
bool  $reverse_order = false 
)
Parameters
int|callable(

ILIAS\Cron\Job\JobEntity, \ILIAS\Cron\Job\JobEntity): int|\Closure(\ILIAS\Cron\Job\JobEntity, \ILIAS\Cron\Job\JobEntity): int $sort

Definition at line 42 of file OrderedJobEntities.php.

46 {
47 $order = $reverse_order ? self::ORDER_REVERSE : self::ORDER_AS_PROVIDED;
48
49 if ($sort === self::ORDER_BY_NAME) {
50 $this->sort = static function (\ILIAS\Cron\Job\JobEntity $left, \ILIAS\Cron\Job\JobEntity $right) use (
51 $order
52 ): int {
53 return $order * \ilStr::strCmp($left->getEffectiveTitle(), $right->getEffectiveTitle());
54 };
55 } elseif ($sort === self::ORDER_BY_STATUS) {
56 $this->sort = static function (\ILIAS\Cron\Job\JobEntity $left, \ILIAS\Cron\Job\JobEntity $right) use (
57 $order
58 ): int {
59 return $order * ($right->getJobStatus() <=> $left->getJobStatus());
60 };
61 } elseif ($sort === self::ORDER_BY_NONE) {
62 $this->sort = $order;
63 } elseif (\is_callable($sort)) {
64 $this->sort = $sort;
65 if ($reverse_order) {
66 $this->sort = static fn(
67 \ILIAS\Cron\Job\JobEntity $left,
68 \ILIAS\Cron\Job\JobEntity $right
69 ): int => -$sort($left, $right);
70 }
71 } else {
72 throw new \InvalidArgumentException(
73 'The SortableIterator takes a PHP callable or a valid built-in sort algorithm as an argument.'
74 );
75 }
76 }
static strCmp(string $a, string $b)
Definition: class.ilStr.php:87
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.

References ILIAS\Cron\Job\Collection\OrderedJobEntities\$sort, ILIAS\Cron\Job\Collection\OrderedJobEntities\ORDER_AS_PROVIDED, ILIAS\Cron\Job\Collection\OrderedJobEntities\ORDER_REVERSE, ILIAS\UI\examples\Symbol\Glyph\Sort\sort(), and ilStr\strCmp().

+ Here is the call graph for this function:

Member Function Documentation

◆ add()

ILIAS\Cron\Job\Collection\OrderedJobEntities::add ( \ILIAS\Cron\Job\JobEntity  $job)

Implements ILIAS\Cron\Job\JobCollection.

Definition at line 91 of file OrderedJobEntities.php.

91 : void
92 {
93 $this->origin->add($job);
94 $this->sorted_jobs = null;
95 }

◆ count()

ILIAS\Cron\Job\Collection\OrderedJobEntities::count ( )

Definition at line 86 of file OrderedJobEntities.php.

86 : int
87 {
88 return $this->origin->count();
89 }

◆ filter()

ILIAS\Cron\Job\Collection\OrderedJobEntities::filter ( callable  $callable)

Returns all the elements of this collection that satisfy the predicate $callable.

Parameters
callable(

ILIAS\Cron\Job\JobEntity): bool $callable

Returns
static

Implements ILIAS\Cron\Job\JobCollection.

Definition at line 97 of file OrderedJobEntities.php.

97 : static
98 {
99 return new static(
100 $this->origin->filter($callable),
102 );
103 }

References ILIAS\Cron\Job\Collection\OrderedJobEntities\$sort.

◆ getIterator()

ILIAS\Cron\Job\Collection\OrderedJobEntities::getIterator ( )
Returns
\ArrayIterator<int, \ILIAS\Cron\Job\JobEntity>

Definition at line 81 of file OrderedJobEntities.php.

81 : \ArrayIterator
82 {
83 return new \ArrayIterator($this->getSortedJobs());
84 }

References ILIAS\Cron\Job\Collection\OrderedJobEntities\getSortedJobs().

+ Here is the call graph for this function:

◆ getSortedJobs()

ILIAS\Cron\Job\Collection\OrderedJobEntities::getSortedJobs ( )
private
Returns
list<\ILIAS\Cron\Job\JobEntity>

Definition at line 121 of file OrderedJobEntities.php.

121 : array
122 {
123 if ($this->sorted_jobs === null) {
124 $list = iterator_to_array($this->origin->toArray(), false);
125 if ($this->sort !== self::ORDER_AS_PROVIDED) {
126 if ($this->sort === self::ORDER_REVERSE) {
127 $list = array_reverse($list);
128 } else {
129 uasort($list, $this->sort);
130 }
131 }
132 $this->sorted_jobs = $list;
133 }
134
135 return $this->sorted_jobs;
136 }

References ILIAS\Cron\Job\Collection\OrderedJobEntities\$sorted_jobs, and ILIAS\UI\examples\Symbol\Glyph\Sort\sort().

Referenced by ILIAS\Cron\Job\Collection\OrderedJobEntities\getIterator(), ILIAS\Cron\Job\Collection\OrderedJobEntities\slice(), and ILIAS\Cron\Job\Collection\OrderedJobEntities\toArray().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ slice()

ILIAS\Cron\Job\Collection\OrderedJobEntities::slice ( int  $offset,
?int  $length = null 
)

Extracts a slice of $length elements starting at position $offset from the Collection.

If $length is null it returns all elements from $offset to the end of the Collection. Calling this method will only return the selected slice and NOT change the elements contained in the collection slice is called on.

Parameters
int$offsetThe offset to start from.
int | null$lengthThe maximum number of elements to return, or null for no limit.
Returns
static

Implements ILIAS\Cron\Job\JobCollection.

Definition at line 105 of file OrderedJobEntities.php.

105 : static
106 {
107 return new static(
108 new JobEntities(...\array_slice($this->getSortedJobs(), $offset, $length)),
110 );
111 }

References ILIAS\Cron\Job\Collection\OrderedJobEntities\$sort, and ILIAS\Cron\Job\Collection\OrderedJobEntities\getSortedJobs().

+ Here is the call graph for this function:

◆ toArray()

ILIAS\Cron\Job\Collection\OrderedJobEntities::toArray ( )
Returns
list<\ILIAS\Cron\Job\JobEntity>

Implements ILIAS\Cron\Job\JobCollection.

Definition at line 113 of file OrderedJobEntities.php.

113 : array
114 {
115 return $this->getSortedJobs();
116 }

References ILIAS\Cron\Job\Collection\OrderedJobEntities\getSortedJobs().

+ Here is the call graph for this function:

Field Documentation

◆ $sort

◆ $sorted_jobs

array ILIAS\Cron\Job\Collection\OrderedJobEntities::$sorted_jobs = null
private

◆ ORDER_AS_PROVIDED

final const int ILIAS\Cron\Job\Collection\OrderedJobEntities::ORDER_AS_PROVIDED = 1

◆ ORDER_BY_NAME

final const int ILIAS\Cron\Job\Collection\OrderedJobEntities::ORDER_BY_NAME = 1

◆ ORDER_BY_NONE

final const int ILIAS\Cron\Job\Collection\OrderedJobEntities::ORDER_BY_NONE = 0

Definition at line 25 of file OrderedJobEntities.php.

◆ ORDER_BY_STATUS

final const int ILIAS\Cron\Job\Collection\OrderedJobEntities::ORDER_BY_STATUS = 2

◆ ORDER_REVERSE

final const int ILIAS\Cron\Job\Collection\OrderedJobEntities::ORDER_REVERSE = -1

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