Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
customdata.php
1<?php
2
4
10final class CustomData
11{
12 public const CONTENT_CATEGORY_PRODUCT = "product";
13 public const CONTENT_CATEGORY_PRODUCT_GROUP = "product_group";
14
15 private $container = [];
16
22 public function __construct(?array $params = null)
23 {
24 if ($params && !empty($params))
25 {
26 if (array_key_exists('value',$params))
27 {
28 $this->setValue($params['value']);
29 }
30 if (array_key_exists('currency',$params) && is_string($params['currency']))
31 {
32 $this->setCurrency($params['currency']);
33 }
34 if (array_key_exists('content_name',$params) && is_string($params['content_name']))
35 {
36 $this->setContentName($params['content_name']);
37 }
38 if (array_key_exists('content_category',$params) && is_string($params['content_category']))
39 {
40 $this->setContentCategory($params['content_category']);
41 }
42 if (array_key_exists('content_ids',$params) && is_array($params['content_ids']))
43 {
44 $this->setContentIds($params['content_ids']);
45 }
46 if (array_key_exists('contents',$params) && is_array($params['contents']))
47 {
48 $this->setContents($params['contents']);
49 }
50 if (array_key_exists('content_type',$params) && is_string($params['content_type']))
51 {
52 $this->setContentType($params['content_type']);
53 }
54 if (array_key_exists('predicted_ltv',$params))
55 {
56 $this->setPredictedLtv($params['predicted_ltv']);
57 }
58 if (array_key_exists('num_items',$params) && is_int($params['num_items']))
59 {
60 $this->setNumItems($params['num_items']);
61 }
62 if (array_key_exists('status',$params) && is_string($params['status']))
63 {
64 $this->setStatus($params['status']);
65 }
66 if (array_key_exists('search_string',$params) && is_string($params['search_string']))
67 {
68 $this->setSearchString($params['search_string']);
69 }
70 if (array_key_exists('custom_properties',$params) && is_array($params['custom_properties']))
71 {
72 $this->setCustomProperties($params['custom_properties']);
73 }
74
75 }
76
77 }
78
79 public function setValue($value)
80 {
81 if(is_float($value) || is_int($value))
82 {
83 $this->container['value'] = $value;
84 }
85 return $this;
86 }
87
88 public function setCurrency(?string $currency)
89 {
90 $this->container['currency'] = $currency;
91 return $this;
92 }
93
94 public function setContentName(?string $contentName)
95 {
96 $this->container['content_name'] = $contentName;
97 return $this;
98 }
99
100 public function setContentCategory(?string $contentCategory)
101 {
102 $this->container['content_category'] = $contentCategory;
103 return $this;
104 }
105
106 public function setContentIds(?array $contentIds)
107 {
108 if (!empty($contentIds))
109 {
110 $this->container['content_ids'] = array_filter($contentIds, function($item){
111 return is_string($item) || is_int($item);
112 });
113 }
114 return $this;
115 }
116
117 public function setContents(?array $contents)
118 {
119 if (!empty($contents))
120 {
121 $this->container['contents'] = array_filter(
122 $contents,
123 static function($item)
124 {
125 return is_array($item) && isset($item['product_id'],$item['quantity']);
126 }
127 );
128 }
129
130 return $this;
131 }
132
133 public function setContentType(?string $type)
134 {
135 if (in_array($type,[static::CONTENT_CATEGORY_PRODUCT,static::CONTENT_CATEGORY_PRODUCT_GROUP]))
136 {
137 $this->container['content_type'] = $type;
138 }
139 return $this;
140 }
141
142 public function setPredictedLtv($predicted)
143 {
144 if (is_float($predicted) || is_int($predicted))
145 {
146 $this->container['predicted_ltv'] = $predicted;
147 }
148 return $this;
149 }
150
151 public function setNumItems(?int $items)
152 {
153 $this->container['num_items'] = $items;
154 return $this;
155 }
156
157 public function setStatus($status)
158 {
159 $this->container['status'] = $status;
160 return $this;
161 }
162
163 public function setSearchString(?string $searchString)
164 {
165 $this->container['search_string'] = $searchString;
166 return $this;
167 }
168
169 public function setDeliveryCategory($category)
170 {
171 $this->container['delivery_category'] = $category;
172 return $this;
173 }
174
175 public function setCustomProperties(?array $custom_properties)
176 {
177 $this->container['custom_properties'] = $custom_properties;
178 return $this;
179 }
180
181 public function getValue()
182 {
183 return $this->container['value'];
184 }
185
186 public function getCurrency()
187 {
188 return $this->container['currency'];
189 }
190
191 public function getContentName()
192 {
193 return $this->container['content_name'];
194 }
195
196 public function getContentCategory()
197 {
198 return $this->container['content_category'];
199 }
200
201 public function getContentIds()
202 {
203 return $this->container['content_ids'];
204 }
205
206 public function getContents()
207 {
208 return $this->container['contents'];
209 }
210
211 public function getContentType()
212 {
213 return $this->container['content_type'];
214 }
215
216 public function getPredictedLtv()
217 {
218 return $this->container['predicted_ltv'];
219 }
220
221 public function getNumItems()
222 {
223 return $this->container['num_items'];
224 }
225
226 public function getStatus()
227 {
228 return $this->container['status'];
229 }
230
231 public function getSearchString()
232 {
233 return $this->container['search_string'];
234 }
235
236 public function getDeliveryCategory()
237 {
238 return $this->container['delivery_category'];
239 }
240
241 public function getCustomProperties($custom_properties)
242 {
243 return $this->container['custom_properties'];
244 }
245
246 public function validate() : bool
247 {
248 return true;
249 }
250
251 public function toArray()
252 {
253 return $this->container;
254 }
255}
setCustomProperties(?array $custom_properties)
setContentCategory(?string $contentCategory)