ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
ILIAS\BackgroundTasks\Task\Job\Collection\OrderedJobEntities Class Reference
+ Inheritance diagram for ILIAS\BackgroundTasks\Task\Job\Collection\OrderedJobEntities:
+ Collaboration diagram for ILIAS\BackgroundTasks\Task\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 ()
 

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\BackgroundTasks\Task\Job\Collection\OrderedJobEntities::__construct ( private readonly \ILIAS\Cron\Job\JobCollection  $origin,
mixed  $sort,
bool  $reverse_order = false 
)
Parameters
int|callable(

Definition at line 42 of file OrderedJobEntities.php.

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

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  }
Interface Observer Contains several chained tasks and infos about them.
sort()
description: > Example for rendering a Sort Glyph.
Definition: sort.php:41
static strCmp(string $a, string $b)
Definition: class.ilStr.php:87
+ Here is the call graph for this function:

Member Function Documentation

◆ add()

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

Implements ILIAS\BackgroundTasks\Task\Job\JobCollection.

Definition at line 91 of file OrderedJobEntities.php.

References null.

91  : void
92  {
93  $this->origin->add($job);
94  $this->sorted_jobs = null;
95  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null

◆ count()

ILIAS\BackgroundTasks\Task\Job\Collection\OrderedJobEntities::count ( )

Definition at line 86 of file OrderedJobEntities.php.

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

◆ filter()

ILIAS\BackgroundTasks\Task\Job\Collection\OrderedJobEntities::filter ( callable  $callable)

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

Parameters
callable(

Implements ILIAS\BackgroundTasks\Task\Job\JobCollection.

Definition at line 97 of file OrderedJobEntities.php.

References ILIAS\BackgroundTasks\Task\Job\Collection\OrderedJobEntities\$sort.

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

◆ getIterator()

ILIAS\BackgroundTasks\Task\Job\Collection\OrderedJobEntities::getIterator ( )
Returns
<int, >

Definition at line 81 of file OrderedJobEntities.php.

References ILIAS\BackgroundTasks\Task\Job\Collection\OrderedJobEntities\getSortedJobs().

81  : \ArrayIterator
82  {
83  return new \ArrayIterator($this->getSortedJobs());
84  }
+ Here is the call graph for this function:

◆ getSortedJobs()

ILIAS\BackgroundTasks\Task\Job\Collection\OrderedJobEntities::getSortedJobs ( )
private
Returns
list<>

Definition at line 121 of file OrderedJobEntities.php.

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

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

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  }
sort()
description: > Example for rendering a Sort Glyph.
Definition: sort.php:41
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ slice()

ILIAS\BackgroundTasks\Task\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\BackgroundTasks\Task\Job\JobCollection.

Definition at line 105 of file OrderedJobEntities.php.

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

105  : static
106  {
107  return new static(
108  new JobEntities(...\array_slice($this->getSortedJobs(), $offset, $length)),
110  );
111  }
+ Here is the call graph for this function:

◆ toArray()

ILIAS\BackgroundTasks\Task\Job\Collection\OrderedJobEntities::toArray ( )
Returns
list<>

Implements ILIAS\BackgroundTasks\Task\Job\JobCollection.

Definition at line 113 of file OrderedJobEntities.php.

References ILIAS\BackgroundTasks\Task\Job\Collection\OrderedJobEntities\getSortedJobs().

113  : array
114  {
115  return $this->getSortedJobs();
116  }
+ Here is the call graph for this function:

Field Documentation

◆ $sort

◆ $sorted_jobs

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

◆ ORDER_AS_PROVIDED

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

Definition at line 29 of file OrderedJobEntities.php.

◆ ORDER_BY_NAME

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

◆ ORDER_BY_NONE

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

Definition at line 25 of file OrderedJobEntities.php.

◆ ORDER_BY_STATUS

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

◆ ORDER_REVERSE

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

Definition at line 30 of file OrderedJobEntities.php.


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