ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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
53 $sortable_visible_cols = array_filter(
54 $this->getVisibleColumns(),
55 static fn($c): bool => $c->isSortable()
56 );
57
58 if ($sortable_visible_cols === [] ||
59 ($total_count !== null && $total_count < 2)
60 ) {
61 return $this->view_control_factory->group([
62 $this->view_control_factory->nullControl(),
63 $this->view_control_factory->nullControl()
64 ]);
65 }
66
67 $sort_options = [];
68 foreach ($sortable_visible_cols as $col_id => $col) {
69
70 $order_asc = $this->data_factory->order($col_id, Order::ASC);
71 $order_desc = $this->data_factory->order($col_id, Order::DESC);
72
73 $labels = $col->getOrderingLabels();
74 $sort_options[$labels[0]] = $order_asc;
75 $sort_options[$labels[1]] = $order_desc;
76 }
77
78 $value = $this->getOrder()->join('', fn($ret, $key, $value) => [$key, $value]);
79 return $this->view_control_factory->sortation($sort_options)
80 ->withValue($value);
81 }
82
83 public function withOrder(?Order $order): self
84 {
85 $clone = clone $this;
86 $clone->order = $order;
87 return $clone;
88 }
89
90 public function getOrder(): Order
91 {
92 return $this->order ?? $this->data_factory->order($this->initialOrder(), Order::ASC);
93 }
94}
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