1 | <?php |
||
2 | |||
3 | |||
4 | namespace Zenwalker\CommerceML\Model; |
||
5 | |||
6 | |||
7 | use Zenwalker\CommerceML\Collections\PropertyCollection; |
||
8 | |||
9 | /** |
||
10 | * Class Classifier |
||
11 | * |
||
12 | * @package Zenwalker\CommerceML\Model |
||
13 | * @property PropertyCollection properties |
||
14 | * @property Group[] groups |
||
15 | */ |
||
16 | class Classifier extends Simple |
||
17 | { |
||
18 | /** |
||
19 | * @var Group[] |
||
20 | */ |
||
21 | protected $groups = []; |
||
22 | /** |
||
23 | * @var PropertyCollection |
||
24 | */ |
||
25 | protected $properties; |
||
26 | |||
27 | protected $stockrooms = []; |
||
28 | |||
29 | /** |
||
30 | * @return null|\SimpleXMLElement |
||
31 | */ |
||
32 | 31 | public function loadXml() |
|
33 | { |
||
34 | 31 | if ($this->owner->importXml && $this->owner->importXml->Классификатор) { |
|
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
35 | 31 | return $this->owner->importXml->Классификатор; |
|
36 | } |
||
37 | |||
38 | return null; |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * @param $id |
||
43 | * @return \SimpleXMLElement[] |
||
44 | */ |
||
45 | 4 | public function getReferenceBookById($id) |
|
46 | { |
||
47 | 4 | return $this->xpath('//c:Свойство[c:Ид = :id]/c:ВариантыЗначений/c:Справочник', ['id' => $id]); |
|
48 | } |
||
49 | |||
50 | /** |
||
51 | * @param $id |
||
52 | * @return null|\SimpleXMLElement |
||
53 | */ |
||
54 | 6 | public function getReferenceBookValueById($id) |
|
55 | { |
||
56 | 6 | if ($id) { |
|
57 | 5 | $xpath = '//c:Свойство/c:ВариантыЗначений/c:Справочник[c:ИдЗначения = :id]'; |
|
58 | 5 | $type = $this->xpath($xpath, ['id' => $id]); |
|
59 | 5 | return $type ? $type[0] : null; |
|
60 | } |
||
61 | |||
62 | 1 | return null; |
|
63 | } |
||
64 | |||
65 | /** |
||
66 | * @param $id |
||
67 | * @return null|Group |
||
68 | */ |
||
69 | 5 | public function getGroupById($id) |
|
70 | { |
||
71 | 5 | foreach ($this->getGroups() as $group) { |
|
72 | 5 | if ($group->id === $id) { |
|
73 | 1 | return $group; |
|
74 | } |
||
75 | |||
76 | 5 | if ($child = $group->getChildById($id)) { |
|
77 | 2 | return $child; |
|
78 | } |
||
79 | } |
||
80 | 2 | return null; |
|
81 | } |
||
82 | |||
83 | /** |
||
84 | * @return PropertyCollection |
||
85 | */ |
||
86 | 2 | public function getProperties() |
|
87 | { |
||
88 | 2 | if (!$this->properties) { |
|
89 | 2 | $this->properties = new PropertyCollection($this->owner, $this->xml->Свойства); |
|
90 | } |
||
91 | 2 | return $this->properties; |
|
92 | } |
||
93 | |||
94 | /** |
||
95 | * @return Group[] |
||
96 | */ |
||
97 | 5 | public function getGroups() |
|
98 | { |
||
99 | 5 | if (empty($this->groups) && isset($this->xml->Группы->Группа)) { |
|
100 | 5 | foreach ($this->xml->Группы->Группа as $group) { |
|
101 | 5 | $this->groups[] = new Group($this->owner, $group); |
|
102 | } |
||
103 | } |
||
104 | 5 | return $this->groups; |
|
105 | } |
||
106 | |||
107 | /** |
||
108 | * @return Stockroom[] |
||
109 | */ |
||
110 | public function getStockrooms() |
||
111 | { |
||
112 | if (empty($this->stockrooms) && isset($this->xml->Склады)) { |
||
113 | foreach ($this->xml->Склады->Склад as $stockroom) { |
||
114 | $this->stockrooms[] = new Stockroom($this->owner, $stockroom); |
||
115 | } |
||
116 | } |
||
117 | return $this->stockrooms; |
||
118 | } |
||
119 | } |
||
120 |