19 declare(strict_types=1);
45 bool $reverse_order =
false 47 $order = $reverse_order ? self::ORDER_REVERSE : self::ORDER_AS_PROVIDED;
49 if ($sort === self::ORDER_BY_NAME) {
50 $this->
sort =
static function (\ILIAS\Cron\Job\JobEntity $left, \ILIAS\Cron\Job\JobEntity $right) use (
53 return $order *
\ilStr::strCmp($left->getEffectiveTitle(), $right->getEffectiveTitle());
55 } elseif ($sort === self::ORDER_BY_STATUS) {
56 $this->
sort =
static function (\ILIAS\Cron\Job\JobEntity $left, \ILIAS\Cron\Job\JobEntity $right) use (
59 return $order * ($right->getJobStatus() <=> $left->getJobStatus());
61 } elseif ($sort === self::ORDER_BY_NONE) {
63 } elseif (\is_callable($sort)) {
66 $this->
sort =
static fn(
69 ):
int => -
$sort($left, $right);
72 throw new \InvalidArgumentException(
73 'The SortableIterator takes a PHP callable or a valid built-in sort algorithm as an argument.' 88 return $this->origin->count();
93 $this->origin->add($job);
94 $this->sorted_jobs =
null;
97 public function filter(callable $callable): static
100 $this->origin->filter($callable),
105 public function slice(
int $offset, ?
int $length =
null): static
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);
129 uasort($list, $this->
sort);
132 $this->sorted_jobs = $list;
Interface Observer Contains several chained tasks and infos about them.
__construct(private readonly \ILIAS\Cron\Job\JobCollection $origin, mixed $sort, bool $reverse_order=false)
final const int ORDER_REVERSE
sort()
description: > Example for rendering a Sort Glyph.
slice(int $offset, ?int $length=null)
Extracts a slice of $length elements starting at position $offset from the Collection.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
final const int ORDER_AS_PROVIDED
final const int ORDER_BY_STATUS
final const int ORDER_BY_NONE
add(\ILIAS\Cron\Job\JobEntity $job)
static strCmp(string $a, string $b)
filter(callable $callable)
Returns all the elements of this collection that satisfy the predicate $callable. ...
final const int ORDER_BY_NAME