19declare(strict_types=1);
45 bool $reverse_order =
false
49 if (
$sort === self::ORDER_BY_NAME) {
53 return $order *
\ilStr::strCmp($left->getEffectiveTitle(), $right->getEffectiveTitle());
55 } elseif (
$sort === self::ORDER_BY_STATUS) {
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;
final const int ORDER_AS_PROVIDED
add(\ILIAS\Cron\Job\JobEntity $job)
final const int ORDER_BY_NAME
filter(callable $callable)
Returns all the elements of this collection that satisfy the predicate $callable.
final const int ORDER_BY_NONE
final const int ORDER_BY_STATUS
__construct(private readonly \ILIAS\Cron\Job\JobCollection $origin, mixed $sort, bool $reverse_order=false)
slice(int $offset, ?int $length=null)
Extracts a slice of $length elements starting at position $offset from the Collection.
final const int ORDER_REVERSE
static strCmp(string $a, string $b)
@template-extends \IteratorAggregate<\ILIAS\Cron\Job\JobEntity>
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.