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