Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
StoreDocumentElement.php
1<?php
2
4
7
9{
10 private int $id;
14 private array $storeIds;
15
20 public function __construct(int $id, array $storeIds = [])
21 {
22 $this->id = $id;
23 $this->storeIds = array_unique(
24 array_map('intval', $storeIds)
25 );
26 }
27
28 private static function getStoresById(int $id): array
29 {
30 $storeIds = [];
31
32 if ($id > 0)
33 {
35 'select' => [
36 'STORE_TO',
37 'STORE_FROM',
38 ],
39 'filter' => [
40 '=ID' => $id,
41 ],
42 ]);
43 if ($row)
44 {
45 if (isset($row['STORE_TO']))
46 {
47 $storeIds[] = $row['STORE_TO'];
48 }
49
50 if (isset($row['STORE_FROM']))
51 {
52 $storeIds[] = $row['STORE_FROM'];
53 }
54 }
55 }
56
57 return $storeIds;
58 }
59
68 public static function createFromId(int $itemId, ?array $storeIds = null): StoreDocumentElement
69 {
70 return new static(
71 $itemId,
72 $storeIds ?? self::getStoresById($itemId)
73 );
74 }
75
83 public static function createFromArray(array $fields): StoreDocumentElement
84 {
85 $id = (int)($fields['ID'] ?? 0);
86 $storeIds = [];
87
88 if (isset($fields['STORE_TO']))
89 {
90 $storeIds[] = $fields['STORE_TO'];
91 }
92
93 if (isset($fields['STORE_FROM']))
94 {
95 $storeIds[] = $fields['STORE_FROM'];
96 }
97
98 array_push($storeIds, ... self::getStoresById($id));
99
100 return new static($id, $storeIds);
101 }
102
106 public function getId(): int
107 {
108 return $this->id;
109 }
110
116 public function getStoreIds(): array
117 {
118 return $this->storeIds;
119 }
120}
static createFromId(int $itemId, ?array $storeIds=null)
static getRow(array $parameters)