ILIAS  release_8 Revision v8.24
Card.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
22
24use ILIAS\UI\Implementation\Component\ComponentHelper;
32
33class Card implements C\Card
34{
35 use ComponentHelper;
37 use Triggerer;
38
42 protected $title;
44
48 protected array $content_sections = [];
49 protected ?Image $image;
50
54 protected $title_action = '';
55 protected bool $highlight = false;
56
61 public function __construct($title, Image $image = null)
62 {
63 if (!$title instanceof Shy) {
64 $this->checkStringArg("title", $title);
65 }
66
67 $this->title = $title;
68 $this->image = $image;
69 }
70
74 public function withTitle($title): C\Card
75 {
76 if (!$title instanceof Shy) {
77 $this->checkStringArg("title", $title);
78 }
79
80 $clone = clone $this;
81 $clone->title = $title;
82
83 return $clone;
84 }
85
89 public function getTitle()
90 {
91 return $this->title;
92 }
93
97 public function withImage(Image $image): C\Card
98 {
99 $clone = clone $this;
100 $clone->image = $image;
101 return $clone;
102 }
103
107 public function getImage(): ?Image
108 {
109 return $this->image;
110 }
111
115 public function withSections(array $sections): C\Card
116 {
117 $classes = [Component::class];
118 $this->checkArgListElements("sections", $sections, $classes);
119
120 $clone = clone $this;
121 $clone->content_sections = $sections;
122 return $clone;
123 }
124
128 public function getSections(): array
129 {
131 }
132
136 public function withTitleAction($action): C\Card
137 {
138 $this->checkStringOrSignalArg("title_action", $action);
139
140 $clone = clone $this;
141 if (is_string($action)) {
142 $clone->title_action = $action;
143 } else {
147 $clone->title_action = null;
148 $clone->setTriggeredSignal($action, "click");
149 }
150
151 return $clone;
152 }
153
157 public function getTitleAction()
158 {
159 if ($this->title_action !== null) {
160 return $this->title_action;
161 }
162 return $this->getTriggeredSignalsFor("click");
163 }
164
168 public function withHighlight(bool $status): Card
169 {
170 $clone = clone $this;
171 $clone->highlight = $status;
172
173 return $clone;
174 }
175
179 public function isHighlighted(): bool
180 {
181 return $this->highlight;
182 }
183
187 public function withOnClick(Signal $signal): Clickable
188 {
189 return $this->withTriggeredSignal($signal, 'click');
190 }
194 public function appendOnClick(Signal $signal): Clickable
195 {
196 return $this->appendTriggeredSignal($signal, 'click');
197 }
198}
__construct($title, Image $image=null)
Definition: Card.php:61
A component is the most general form of an entity in the UI.
Definition: Component.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Card.php:21
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Card.php:21
appendTriggeredSignal(C\Signal $signal, string $event)
Append a triggered signal to other signals of the same event.
Definition: Triggerer.php:47
withTriggeredSignal(C\Signal $signal, string $event)
Add a triggered signal, replacing any other signals registered on the same event.
Definition: Triggerer.php:62
getTriggeredSignalsFor(string $event)
Get signals that are triggered for a certain event.
Definition: Triggerer.php:94
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.