1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Entity.php
См. документацию.
1<?php
2
4
9
10class Entity implements RestEntity
11{
12 public ?int $id = null;
13 public ?string $placement = null;
14 public ?string $title = null;
15 public ?int $restApplicationId = null;
16 public ?array $options = null;
17 public ?int $order = null;
18
19
20 public function __construct(?array $fields = null)
21 {
22 if ($fields !== null)
23 {
24 $this->hydrate($fields);
25 }
26 }
27
28 public function hydrate(array $fields): void
29 {
30 $this->id = $fields['id'] ?? null;
31 $this->placement = $fields['placement'] ?? null;
32 $this->title = $fields['title'] ?? null;
33 $this->restApplicationId = $fields['restApplicationId'] ?? null;
34 $this->order = $fields['order'] ?? null;
35 $this->hydrateOptions(($fields['options'] ?? null));
36 }
37
38 private function hydrateOptions(?array $options): void
39 {
40 if (!$options)
41 {
42 return;
43 }
44
45 if (isset($options['role']))
46 {
47 $this->options['role'] = mb_strtolower($options['role']);
48 }
49 if (isset($options['extranet']))
50 {
51 $this->options['extranet'] = $options['extranet'] === 'Y'? 'Y': 'N';
52 }
53 if (isset($options['context']))
54 {
55 $this->options['context'] = $this->getContext($options['context']);
56 }
57 if (isset($options['width']))
58 {
59 $this->options['width'] = $options['width'];
60 }
61 if (isset($options['height']))
62 {
63 $this->options['height'] = $options['height'];
64 }
65 if (isset($options['iconName']))
66 {
67 $this->options['iconName'] = $options['iconName'];
68 }
69 if ($this->placement === Placement::IM_TEXTAREA || $this->placement === Placement::IM_SIDEBAR)
70 {
71 $this->options['color'] = Color::getColor($options['color']) ?? Color::getColorByNumber($this->id);
72 }
73 }
74
75 private function getContext(string $contextOption): array
76 {
77 $userContextList = explode(';', trim($contextOption));
78 if (in_array(Context::ALL, $userContextList, true))
79 {
80 return [mb_strtolower(Context::ALL)];
81 }
82
83 return array_map('mb_strtolower', $userContextList);
84 }
85
89 public function getId(): ?int
90 {
91 return $this->id;
92 }
93
99 public function getTitle(): ?string
100 {
101 return $this->title;
102 }
103
109 public function getOrder(): ?int
110 {
111 return $this->order;
112 }
113
117 public static function getRestEntityName(): string
118 {
119 return 'placementApplication';
120 }
121
122 protected function toRestFormatOptions(): array
123 {
125 if (isset($options['extranet']))
126 {
127 unset($options['extranet']);
128 }
129 if (isset($options['role']))
130 {
131 unset($options['role']);
132 }
133
134 return $options;
135 }
136
140 public function toRestFormat(array $option = []): array
141 {
142 return [
143 'id' => (int)$this->id,
144 'title' => $this->title,
145 'options' => $this->toRestFormatOptions(),
146 'placement' => $this->placement,
147 'order' => $this->order,
148 'loadConfiguration' => [
150 'PLACEMENT' => $this->placement,
151 'PLACEMENT_ID' => $this->id,
152 ],
153 ];
154 }
155}
static getColorByNumber($number)
Определения color.php:144
static getColor($code)
Определения color.php:121
toRestFormat(array $option=[])
Определения Entity.php:140
hydrate(array $fields)
Определения Entity.php:28
__construct(?array $fields=null)
Определения Entity.php:20
$fields
Определения entity.php:45
$options
Определения commerceml2.php:49
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
<? endif;?> window document title
Определения prolog_main_admin.php:76
$option
Определения options.php:1711