ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
Column.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
26 
27 abstract 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 $asc_label = null;
39  protected ?string $desc_label = null;
40 
41  public function __construct(
42  protected \ilLanguage $lng,
43  protected string $title
44  ) {
45  }
46 
47  public function getTitle(): string
48  {
49  return $this->title;
50  }
51 
52  public function getType(): string
53  {
54  $class = explode('\\', $this::class);
55  return array_pop($class);
56  }
57 
58  public function withIsSortable(
59  bool $flag
60  ): self {
61  $clone = clone $this;
62  $clone->sortable = $flag;
63  return $clone;
64  }
65 
66  public function isSortable(): bool
67  {
68  return $this->sortable;
69  }
70 
71  public function withOrderingLabels(
72  string $asc_label = null,
73  string $desc_label = null
74  ): self {
75  $clone = clone $this;
76  $clone->asc_label = $asc_label;
77  $clone->desc_label = $desc_label;
78  return $clone;
79  }
80 
84  public function getOrderingLabels(): array
85  {
86  return [
87  $this->asc_label ?? $this->getTitle() . self::SEPERATOR . $this->lng->txt('order_option_generic_ascending'),
88  $this->desc_label ?? $this->getTitle() . self::SEPERATOR . $this->lng->txt('order_option_generic_descending')
89  ];
90  }
91 
92  public function withIsOptional(bool $is_optional, bool $is_initially_visible = true): self
93  {
94  $clone = clone $this;
95  $clone->optional = $is_optional;
96  $clone->initially_visible = $is_initially_visible;
97  return $clone;
98  }
99 
100  public function isOptional(): bool
101  {
102  return $this->optional;
103  }
104 
105  public function isInitiallyVisible(): bool
106  {
108  }
109 
110  public function withIndex(int $index): self
111  {
112  $clone = clone $this;
113  $clone->index = $index;
114  return $clone;
115  }
116 
117  public function getIndex(): int
118  {
119  return $this->index;
120  }
121 
122  public function withHighlight(bool $flag): self
123  {
124  $clone = clone $this;
125  $clone->highlighted = $flag;
126  return $clone;
127  }
128 
129  public function isHighlighted(): bool
130  {
131  return $this->highlighted;
132  }
133 
134  public function format($value): string|Component
135  {
136  return (string) $value;
137  }
138 }
withIsOptional(bool $is_optional, bool $is_initially_visible=true)
Definition: Column.php:92
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(protected \ilLanguage $lng, protected string $title)
Definition: Column.php:41
$lng
withOrderingLabels(string $asc_label=null, string $desc_label=null)
Definition: Column.php:71