Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
entity.php
1<?
2
4
5class Entity implements \JsonSerializable
6{
7 protected $id;
8 protected $options = [];
9 protected $searchable = true;
10 protected $dynamicLoad = false;
11 protected $dynamicSearch = false;
12 protected $provider;
14 protected $filters = [];
15
16 public function __construct(array $options)
17 {
18 if (!empty($options['id']) && is_string($options['id']))
19 {
20 $this->id = strtolower($options['id']);
21 }
22
23 if (!empty($options['options']) && is_array($options['options']))
24 {
25 $this->options = $options['options'];
26 }
27
28 if (isset($options['searchable']) && is_bool($options['searchable']))
29 {
30 $this->setSearchable($options['searchable']);
31 }
32
33 if (isset($options['dynamicSearch']) && is_bool($options['dynamicSearch']))
34 {
35 $this->setDynamicSearch($options['dynamicSearch']);
36 }
37
38 if (isset($options['dynamicLoad']) && is_bool($options['dynamicLoad']))
39 {
40 $this->setDynamicLoad($options['dynamicLoad']);
41 }
42
43 if (isset($options['substituteEntityId']) && is_string($options['substituteEntityId']))
44 {
45 $this->substituteEntityId = $options['substituteEntityId'];
46 }
47 }
48
49 public static function create(array $entityOptions): ?Entity
50 {
51 $entity = new Entity($entityOptions);
53 if ($provider && $provider->isAvailable())
54 {
55 $entity->setProvider($provider);
56
57 $filters = [];
58 if (isset($entityOptions['filters']) && is_array($entityOptions['filters']))
59 {
60 $filters = Configuration::getFilters($entity->getId(), $entityOptions['filters']);
61 }
62
63 if (empty($filters))
64 {
65 return $entity;
66 }
67
68 foreach ($filters as $filter)
69 {
70 if ($filter instanceof BaseFilter && $filter->isAvailable())
71 {
72 $entity->addFilter($filter);
73 }
74 }
75
76 return $entity;
77 }
78
79 return null;
80 }
81
82 public function getId(): ?string
83 {
84 return $this->id;
85 }
86
87 public function getOptions(): array
88 {
89 return $this->options;
90 }
91
92 public function getProvider(): BaseProvider
93 {
94 return $this->provider;
95 }
96
97 public function setProvider(BaseProvider $provider): self
98 {
99 $this->provider = $provider;
100
101 return $this;
102 }
103
104 public function getSubstituteEntityId(): ?string
105 {
107 }
108
109 public function getFilters(): array
110 {
111 return $this->filters;
112 }
113
114 public function addFilter(BaseFilter $filter): self
115 {
116 $this->filters[] = $filter;
117
118 return $this;
119 }
120
121 public function isSearchable(): bool
122 {
123 return $this->searchable;
124 }
125
126 public function setSearchable(bool $flag = true): self
127 {
128 $this->searchable = $flag;
129
130 return $this;
131 }
132
133 public function hasDynamicSearch(): bool
134 {
136 }
137
138 public function setDynamicSearch(bool $flag = true): self
139 {
140 $this->dynamicSearch = $flag;
141
142 return $this;
143 }
144
145 public function hasDynamicLoad(): bool
146 {
147 return $this->dynamicLoad;
148 }
149
150 public function setDynamicLoad(bool $flag = true): self
151 {
152 $this->dynamicLoad = $flag;
153
154 return $this;
155 }
156
157 public function jsonSerialize(): array
158 {
159 return [
160 'id' => $this->getId(),
161 'dynamicSearch' => $this->hasDynamicSearch(),
162 ];
163 }
164}
static getFilters(string $entityId, array $filterOptions=[])
__construct(array $options)
Definition entity.php:16
addFilter(BaseFilter $filter)
Definition entity.php:114
setSearchable(bool $flag=true)
Definition entity.php:126
setDynamicLoad(bool $flag=true)
Definition entity.php:150
setProvider(BaseProvider $provider)
Definition entity.php:97
setDynamicSearch(bool $flag=true)
Definition entity.php:138
static create(array $entityOptions)
Definition entity.php:49