ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Column.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ILIAS\UI\Implementation\Component\ComponentHelper;
27
28abstract class Column implements C\Column
29{
30 use ComponentHelper;
31
32 protected const SEPERATOR = ', ';
33
34 protected bool $sortable = true;
35 protected bool $optional = false;
36 protected bool $initially_visible = true;
37 protected bool $highlighted = false;
38 protected int $index;
39 protected ?string $asc_label = null;
40 protected ?string $desc_label = null;
41
42 public function __construct(
43 protected Language $lng,
44 protected string $title
45 ) {
46 }
47
48 public function getTitle(): string
49 {
50 return $this->title;
51 }
52
53 public function getType(): string
54 {
55 $class = explode('\\', $this::class);
56 return array_pop($class);
57 }
58
59 public function withIsSortable(
60 bool $flag
61 ): self {
62 $clone = clone $this;
63 $clone->sortable = $flag;
64 return $clone;
65 }
66
67 public function isSortable(): bool
68 {
69 return $this->sortable;
70 }
71
72 public function withOrderingLabels(
73 ?string $asc_label = null,
74 ?string $desc_label = null
75 ): self {
76 $clone = clone $this;
77 $clone->asc_label = $asc_label;
78 $clone->desc_label = $desc_label;
79 return $clone;
80 }
81
85 public function getOrderingLabels(): array
86 {
87 return [
88 $this->asc_label ?? $this->getTitle() . self::SEPERATOR . $this->lng->txt('order_option_generic_ascending'),
89 $this->desc_label ?? $this->getTitle() . self::SEPERATOR . $this->lng->txt('order_option_generic_descending')
90 ];
91 }
92
93 public function withIsOptional(bool $is_optional, bool $is_initially_visible = true): self
94 {
95 $clone = clone $this;
96 $clone->optional = $is_optional;
97 $clone->initially_visible = $is_initially_visible;
98 return $clone;
99 }
100
101 public function isOptional(): bool
102 {
103 return $this->optional;
104 }
105
106 public function isInitiallyVisible(): bool
107 {
108 return $this->initially_visible;
109 }
110
111 public function withIndex(int $index): self
112 {
113 $clone = clone $this;
114 $clone->index = $index;
115 return $clone;
116 }
117
118 public function getIndex(): int
119 {
120 return $this->index;
121 }
122
123 public function withHighlight(bool $flag): self
124 {
125 $clone = clone $this;
126 $clone->highlighted = $flag;
127 return $clone;
128 }
129
130 public function isHighlighted(): bool
131 {
132 return $this->highlighted;
133 }
134
135 public function format($value): string|Component
136 {
137 return (string) $value;
138 }
139}
withIsOptional(bool $is_optional, bool $is_initially_visible=true)
Definition: Column.php:93
withOrderingLabels(?string $asc_label=null, ?string $desc_label=null)
Definition: Column.php:72
__construct(protected Language $lng, protected string $title)
Definition: Column.php:42
A component is the most general form of an entity in the UI.
Definition: Component.php:28
global $lng
Definition: privfeed.php:31