Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
tab.php
1<?
3
4class Tab implements \JsonSerializable
5{
6 protected $id;
7
9 protected $title = '';
10 protected $visible = true;
11 protected $itemOrder = [];
12 protected $itemMaxDepth;
13 protected $icon = [];
14 protected $textColor = [];
15 protected $bgColor = [];
16 protected $stub;
17 protected $stubOptions;
18
20 protected $header;
21
23 protected $headerOptions;
24
26 protected $showDefaultHeader = true;
27
29 protected $footer;
30
32 protected $footerOptions;
33
35 protected $showDefaultFooter = true;
36
38 protected $showAvatars;
39
40 public function __construct(array $options)
41 {
42 $id = $options['id'] ?? null;
43 if (is_string($id) && $id !== '')
44 {
45 $this->id = $id;
46 }
47
48 $title = $options['title'] ?? null;
49 if (is_string($title) || is_array($title))
50 {
51 $this->setTitle($options['title']);
52 }
53
54 if (isset($options['icon']))
55 {
56 if (is_string($options['icon']))
57 {
58 $this->setIcon(['default' => $options['icon']]);
59 }
60 elseif (is_array($options['icon']))
61 {
62 $this->setIcon($options['icon']);
63 }
64 }
65
66 if (isset($options['textColor']))
67 {
68 if (is_string($options['textColor']))
69 {
70 $this->setTextColor(['default' => $options['textColor']]);
71 }
72 elseif (is_array($options['textColor']))
73 {
74 $this->setTextColor($options['textColor']);
75 }
76 }
77
78 if (isset($options['bgColor']))
79 {
80 if (is_string($options['bgColor']))
81 {
82 $this->setBgColor(['default' => $options['bgColor']]);
83 }
84 elseif (is_array($options['bgColor']))
85 {
86 $this->setBgColor($options['bgColor']);
87 }
88 }
89
90 if (isset($options['visible']) && is_bool($options['visible']))
91 {
92 $this->setVisible($options['visible']);
93 }
94
95 if (!empty($options['itemOrder']) && is_array($options['itemOrder']))
96 {
97 $this->setItemOrder($options['itemOrder']);
98 }
99
100 if (isset($options['itemMaxDepth']) && is_int($options['itemMaxDepth']))
101 {
102 $this->setItemMaxDepth($options['itemMaxDepth']);
103 }
104
105 if (isset($options['stub']) && (is_bool($options['stub']) || is_string($options['stub'])))
106 {
107 $this->setStub($options['stub']);
108 }
109
110 if (!empty($options['stubOptions']) && is_array($options['stubOptions']))
111 {
112 $this->setStubOptions($options['stubOptions']);
113 }
114
115 if (isset($options['header']) && is_string($options['header']))
116 {
118 isset($options['headerOptions']) && is_array($options['headerOptions'])
119 ? $options['headerOptions']
120 : []
121 ;
122
123 $this->setFooter($options['header'], $headerOptions);
124 }
125
126 if (isset($options['showDefaultHeader']) && is_bool($options['showDefaultHeader']))
127 {
128 $this->showDefaultHeader = $options['showDefaultHeader'];
129 }
130
131 if (isset($options['footer']) && is_string($options['footer']))
132 {
134 isset($options['footerOptions']) && is_array($options['footerOptions'])
135 ? $options['footerOptions']
136 : []
137 ;
138
139 $this->setFooter($options['footer'], $footerOptions);
140 }
141
142 if (isset($options['showDefaultFooter']) && is_bool($options['showDefaultFooter']))
143 {
144 $this->showDefaultFooter = $options['showDefaultFooter'];
145 }
146
147 if (isset($options['showAvatars']) && is_bool($options['showAvatars']))
148 {
149 $this->setShowAvatars($options['showAvatars']);
150 }
151 }
152
153 public function getId(): ?string
154 {
155 return $this->id;
156 }
157
158 public function getTitle(): string
159 {
160 return $this->getTitleNode() && !$this->getTitleNode()->isNullable() ? $this->getTitleNode()->getText() : '';
161 }
162
163 public function getTitleNode(): ?TextNode
164 {
165 return $this->title;
166 }
167
168 public function setTitle($title): self
169 {
170 if (TextNode::isValidText($title) || $title === null)
171 {
172 $this->title = $title === null ? null : new TextNode($title);
173 }
174
175 return $this;
176 }
177
178 public function getIcon(): array
179 {
180 return $this->icon;
181 }
182
183 public function setIcon(array $icon): self
184 {
185 $this->icon = $icon;
186
187 return $this;
188 }
189
190 public function getTextColor(): array
191 {
192 return $this->textColor;
193 }
194
195 public function setTextColor(array $textColor): self
196 {
197 $this->textColor = $textColor;
198
199 return $this;
200 }
201
202 public function getBgColor(): array
203 {
204 return $this->bgColor;
205 }
206
207 public function setBgColor(array $bgColor): self
208 {
209 $this->bgColor = $bgColor;
210
211 return $this;
212 }
213
214 public function setVisible(bool $flag): self
215 {
216 $this->visible = $flag;
217
218 return $this;
219 }
220
221 public function isVisible(): bool
222 {
223 return $this->visible;
224 }
225
226 public function setItemOrder(array $order): self
227 {
228 $this->itemOrder = $order;
229
230 return $this;
231 }
232
233 public function getItemOrder(): array
234 {
235 return $this->itemOrder;
236 }
237
238 public function setItemMaxDepth(int $depth): self
239 {
240 $this->itemMaxDepth = $depth;
241
242 return $this;
243 }
244
245 public function getItemMaxDepth(): ?int
246 {
247 return $this->itemMaxDepth;
248 }
249
250 public function setStub($stub): self
251 {
252 if (is_bool($stub) || is_string($stub))
253 {
254 $this->stub = $stub;
255 }
256
257 return $this;
258 }
259
260 public function getStub()
261 {
262 return $this->stub;
263 }
264
265 public function setStubOptions(array $options): self
266 {
267 $this->stubOptions = $options;
268
269 return $this;
270 }
271
272 public function getStubOptions(): ?array
273 {
274 return $this->stubOptions;
275 }
276
277 public function setHeader(string $header, array $options = []): self
278 {
279 if (strlen($header) > 0)
280 {
281 $this->header = $header;
282 $this->headerOptions = $options;
283 }
284
285 return $this;
286 }
287
288 public function getHeader(): ?string
289 {
290 return $this->header;
291 }
292
293 public function getHeaderOptions(): ?array
294 {
296 }
297
298 public function canShowDefaultHeader(): bool
299 {
301 }
302
303 public function enableDefaultHeader(): self
304 {
305 $this->showDefaultHeader = true;
306
307 return $this;
308 }
309
310 public function disableDefaultHeader(): self
311 {
312 $this->showDefaultHeader = false;
313
314 return $this;
315 }
316
317 public function setFooter(string $footer, array $options = []): self
318 {
319 if (strlen($footer) > 0)
320 {
321 $this->footer = $footer;
322 $this->footerOptions = $options;
323 }
324
325 return $this;
326 }
327
328 public function getFooter(): ?string
329 {
330 return $this->footer;
331 }
332
333 public function getFooterOptions(): ?array
334 {
336 }
337
338 public function canShowDefaultFooter(): bool
339 {
341 }
342
343 public function enableDefaultFooter(): self
344 {
345 $this->showDefaultFooter = true;
346
347 return $this;
348 }
349
350 public function disableDefaultFooter(): self
351 {
352 $this->showDefaultFooter = false;
353
354 return $this;
355 }
356
357 public function setShowAvatars(bool $flag): self
358 {
359 $this->showAvatars = $flag;
360
361 return $this;
362 }
363
364 public function getShowAvatars(): ?bool
365 {
366 return $this->showAvatars;
367 }
368
369 public function jsonSerialize()
370 {
371 $json = [
372 'id' => $this->getId(),
373 'title' => $this->getTitleNode() !== null ? $this->getTitleNode()->jsonSerialize() : '',
374 'visible' => $this->isVisible(),
375 'itemOrder' => $this->getItemOrder(),
376 'itemMaxDepth' => $this->getItemMaxDepth(),
377 'icon' => $this->getIcon(),
378 'textColor' => $this->getTextColor(),
379 'bgColor' => $this->getBgColor(),
380 ];
381
382 if ($this->getStub() !== null)
383 {
384 $json['stub'] = $this->getStub();
385 }
386
387 if ($this->getStubOptions() !== null)
388 {
389 $json['stubOptions'] = $this->getStubOptions();
390 }
391
392 if ($this->getHeader())
393 {
394 $json['header'] = $this->getHeader();
395 $json['headerOptions'] = $this->getHeaderOptions();
396 }
397
398 if (!$this->canShowDefaultHeader())
399 {
400 $json['showDefaultHeader'] = false;
401 }
402
403 if ($this->getFooter())
404 {
405 $json['footer'] = $this->getFooter();
406 $json['footerOptions'] = $this->getFooterOptions();
407 }
408
409 if (!$this->canShowDefaultFooter())
410 {
411 $json['showDefaultFooter'] = false;
412 }
413
414 if ($this->getShowAvatars() !== null)
415 {
416 $json['showAvatars'] = $this->getShowAvatars();
417 }
418
419 return $json;
420 }
421}
setStubOptions(array $options)
Definition tab.php:265
__construct(array $options)
Definition tab.php:40
setBgColor(array $bgColor)
Definition tab.php:207
setShowAvatars(bool $flag)
Definition tab.php:357
setFooter(string $footer, array $options=[])
Definition tab.php:317
setItemOrder(array $order)
Definition tab.php:226
setHeader(string $header, array $options=[])
Definition tab.php:277
setItemMaxDepth(int $depth)
Definition tab.php:238
setTextColor(array $textColor)
Definition tab.php:195