1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Block.php
См. документацию.
1<?php
2declare(strict_types=1);
3
5
10
11class Block
12{
13 private int $id;
14 private string $code;
15 private string $section;
16
21 private Site $site;
22
23 // todo: move to enum
24 private string $bgType; //transparent || primary || image
25
26 private string $menuTitle;
27 private array $wrapperClasses;
28
32 private array $nodes = [];
33 private array $styles = [];
34
42 public function __construct(string $code, string $section, string $bgType)
43 {
44 $this->code = $code;
45 $this->section = $section;
46 $this->bgType = $bgType;
47 }
48
54 public function setParentSite(Site $site): self
55 {
56 $this->site = $site;
57
58 return $this;
59 }
60
65 public function getParentSite(): Site
66 {
67 return $this->site;
68 }
69
75 public function getCode(): string
76 {
77 return $this->code;
78 }
79
85 public function getSection(): string
86 {
87 return $this->section;
88 }
89
95 public function isMenu(): bool
96 {
97 return $this->section === Collector::SECTIONS['MENU'];
98 }
99
105 public function isSeparator(): bool
106 {
107 return $this->section === Collector::SECTIONS['SEPARATORS'];
108 }
109
115 public function isCover(): bool
116 {
117 return $this->section === Collector::SECTIONS['COVER'];
118 }
119
125 public function isTitle(): bool
126 {
127 return $this->section === Collector::SECTIONS['TITLE'];
128 }
129
135 // todo: move to enum
136 public function getBgType(): string
137 {
138 return $this->bgType;
139 }
140
148 public function setBgType(string $bgType): self
149 {
150 $this->bgType = $bgType;
151
152 return $this;
153 }
154
160 public function getMenuTitle(): string
161 {
162 return $this->menuTitle ?? '';
163 }
164
172 public function setMenuTitle(string $menuTitle): self
173 {
174 $this->menuTitle = $menuTitle;
175
176 return $this;
177 }
178
179 public function setStyles(array $styles): self
180 {
181 $this->styles = $styles;
182
183 return $this;
184 }
185
186 public function getStyles(): array
187 {
188 return $this->styles;
189 }
190
196 public function getId(): int
197 {
198 return $this->id ?? 0;
199 }
200
201 public static function getAnchor(int $id): string
202 {
203 return 'block' . $id;
204 }
205
213 public function setId(int $id): self
214 {
215 $this->id = $id;
216
217 return $this;
218 }
219
227 public function addNode(Node $node): self
228 {
229 $node->setParentBlock($this);
230 $this->nodes[] = $node;
231
232 return $this;
233 }
234
240 public function getNodes(?array $codes = null): array
241 {
242 if (empty($codes))
243 {
244 return $this->nodes;
245 }
246
247 return array_filter($this->nodes, function (Node $node) use ($codes)
248 {
249 return in_array($node->getCode(), $codes, true);
250 });
251 }
252
258 public function getWrapperClasses(): array
259 {
260 return $this->wrapperClasses ?? [];
261 }
262
270 public function setWrapperClasses(array $classes): self
271 {
272 $this->wrapperClasses = $classes;
273
274 return $this;
275 }
276
282 public function toArray(): array
283 {
284 $data = [];
285 $data['code'] = $this->code;
286 $data['section'] = $this->section;
287 $data['bgType'] = $this->bgType;
288 $data['styles'] = $this->styles;
289
290 if (isset($this->id))
291 {
292 $data['id'] = $this->id;
293 }
294
295 $data['nodes'] = [];
296 foreach ($this->nodes as $node)
297 {
298 $data['nodes'][] = $node->toArray();
299 }
300
301 return $data;
302 }
303
311 public static function fromArray(array $data): self
312 {
313 $code = $data['code'] ?? null;
314 $section = $data['section'] ?? null;
315 $bgType = $data['bgType'] ?? null;
316 $styles = $data['styles'] ?? [];
317
318 if (!$code || $section === null || $bgType === null)
319 {
320 throw new GenerationException(
321 GenerationErrors::dataValidation,
322 "Not exist key block data in array.",
323 );
324 }
325
326 $blockData = new Block($code, $section, $bgType);
327
328 $id = (int)($data['id'] ?? 0);
329 if ($id)
330 {
331 $blockData->setId($id);
332 }
333
334 if ($styles)
335 {
336 $blockData->setStyles($styles);
337 }
338
339 foreach (($data['nodes'] ?? []) as $node)
340 {
341 $node = Node::fromArray($node);
342 if (!$node)
343 {
344 break;
345 }
346 $blockData->addNode($node);
347 }
348
349 return $blockData;
350 }
351}
static fromArray(array $data)
Определения Block.php:311
setStyles(array $styles)
Определения Block.php:179
setParentSite(Site $site)
Определения Block.php:54
setMenuTitle(string $menuTitle)
Определения Block.php:172
static getAnchor(int $id)
Определения Block.php:201
setBgType(string $bgType)
Определения Block.php:148
addNode(Node $node)
Определения Block.php:227
setWrapperClasses(array $classes)
Определения Block.php:270
__construct(string $code, string $section, string $bgType)
Определения Block.php:42
getNodes(?array $codes=null)
Определения Block.php:240
setId(int $id)
Определения Block.php:213
static fromArray(array $data)
Определения Site.php:729
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
Определения cookies.php:2
$site
Определения yandex_run.php:614