ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
Card.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
32 
33 class 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 
60  protected array $hidden_sections = [];
61 
66  public function __construct($title, ?Image $image = null)
67  {
68  if (!$title instanceof Shy) {
69  $this->checkStringArg("title", $title);
70  }
71 
72  $this->title = $title;
73  $this->image = $image;
74  }
75 
79  public function withTitle($title): C\Card
80  {
81  if (!$title instanceof Shy) {
82  $this->checkStringArg("title", $title);
83  }
84 
85  $clone = clone $this;
86  $clone->title = $title;
87 
88  return $clone;
89  }
90 
94  public function getTitle()
95  {
96  return $this->title;
97  }
98 
102  public function withImage(Image $image): C\Card
103  {
104  $clone = clone $this;
105  $clone->image = $image;
106  return $clone;
107  }
108 
112  public function getImage(): ?Image
113  {
114  return $this->image;
115  }
116 
120  public function withSections(array $sections): C\Card
121  {
122  $classes = [Component::class];
123  $this->checkArgListElements("sections", $sections, $classes);
124 
125  $clone = clone $this;
126  $clone->content_sections = $sections;
127  return $clone;
128  }
129 
133  public function getSections(): array
134  {
136  }
137 
138  public function withHiddenSections(array $sections): Card
139  {
140  $clone = clone $this;
141  $clone->hidden_sections = $sections;
142 
143  return $clone;
144  }
145 
146  public function getHiddenSections(): array
147  {
148  return $this->hidden_sections;
149  }
150 
154  public function withTitleAction($action): C\Card
155  {
156  $this->checkStringOrSignalArg("title_action", $action);
157 
158  $clone = clone $this;
159  if (is_string($action)) {
160  $clone->title_action = $action;
161  } else {
165  $clone->title_action = null;
166  $clone->setTriggeredSignal($action, "click");
167  }
168 
169  return $clone;
170  }
171 
175  public function getTitleAction()
176  {
177  if ($this->title_action !== null) {
178  return $this->title_action;
179  }
180  return $this->getTriggeredSignalsFor("click");
181  }
182 
186  public function withHighlight(bool $status): Card
187  {
188  $clone = clone $this;
189  $clone->highlight = $status;
190 
191  return $clone;
192  }
193 
197  public function isHighlighted(): bool
198  {
199  return $this->highlight;
200  }
201 
205  public function withOnClick(Signal $signal): Clickable
206  {
207  return $this->withTriggeredSignal($signal, 'click');
208  }
212  public function appendOnClick(Signal $signal): Clickable
213  {
214  return $this->appendTriggeredSignal($signal, 'click');
215  }
216 }
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
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getTriggeredSignalsFor(string $event)
Get signals that are triggered for a certain event.
Definition: Triggerer.php:94
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
__construct($title, ?Image $image=null)
Definition: Card.php:66