ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
TableViewControlOrdering.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27
29{
30 protected ?Order $order = null;
31
32 protected function initViewControlOrdering(): void
33 {
34 $this->order = $this->getOrder();
35 }
36
37 private function initialOrder(): string
38 {
39 $visible_cols = $this->getVisibleColumns();
40 $sortable_visible_cols = array_filter(
41 $visible_cols,
42 static fn($c): bool => $c->isSortable()
43 );
44 if ($sortable_visible_cols === []) {
45 return array_key_first($visible_cols);
46 }
47 return array_key_first($sortable_visible_cols);
48 }
49
50 protected function getViewControlOrdering(int|null $total_count): Sortation|ViewControl\Group
51 {
52 $sortable_visible_cols = array_filter(
53 $this->getVisibleColumns(),
54 static fn($c): bool => $c->isSortable()
55 );
56
57 if ($sortable_visible_cols === [] ||
58 ($total_count !== null && $total_count < 2)
59 ) {
60 return $this->view_control_factory->group([
61 $this->view_control_factory->nullControl(),
62 $this->view_control_factory->nullControl()
63 ]);
64 }
65
66 $sort_options = [];
67 foreach ($sortable_visible_cols as $col_id => $col) {
68
69 $order_asc = $this->data_factory->order($col_id, Order::ASC);
70 $order_desc = $this->data_factory->order($col_id, Order::DESC);
71
72 $labels = $col->getOrderingLabels();
73 $sort_options[$labels[0]] = $order_asc;
74 $sort_options[$labels[1]] = $order_desc;
75 }
76
77 $value = $this->getOrder()->join('', fn($ret, $key, $value) => [$key, $value]);
78 return $this->view_control_factory->sortation($sort_options)
79 ->withValue($value);
80 }
81
82 public function withOrder(?Order $order): self
83 {
84 $clone = clone $this;
85 $clone->order = $order;
86 return $clone;
87 }
88
89 public function getOrder(): Order
90 {
91 return $this->order ?? $this->data_factory->order($this->initialOrder(), Order::ASC);
92 }
93}
Both the subject and the direction need to be specified when expressing an order.
Definition: Order.php:29
const DESC
Definition: Order.php:31
$c
Definition: deliver.php:25
Groups are a special kind of input because they are a monoid operation.
Definition: Group.php:38
This describes a Sortation View Control.
Definition: Sortation.php:29
A Column describes the form of presentation for a certain aspect of data, i.e.
Definition: Column.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Factory.php:21