1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of riesenia/pohoda package. |
4
|
|
|
* |
5
|
|
|
* Licensed under the MIT License |
6
|
|
|
* (c) RIESENIA.com |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
declare(strict_types=1); |
10
|
|
|
|
11
|
|
|
namespace Riesenia\Pohoda; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
use Riesenia\Pohoda\Stock\Header; |
15
|
|
|
use Riesenia\Pohoda\Stock\Price; |
16
|
|
|
use Riesenia\Pohoda\Stock\StockItem; |
17
|
|
|
use Riesenia\Pohoda\ValueTransformer\SanitizeEncoding; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
class Stock extends AbstractAgenda |
21
|
|
|
{ |
22
|
|
|
use Common\AddActionTypeTrait; |
23
|
|
|
use Common\AddParameterToHeaderTrait; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
*/ |
28
|
19 |
|
public function __construct( |
29
|
|
|
Common\NamespacesPaths $namespacesPaths, |
30
|
|
|
SanitizeEncoding $sanitizeEncoding, |
31
|
|
|
array $data, |
32
|
|
|
string $companyRegistrationNumber, |
33
|
|
|
bool $resolveOptions = true, |
34
|
|
|
) |
35
|
|
|
{ |
36
|
|
|
// pass to header |
37
|
19 |
|
if (!empty($data)) { |
38
|
19 |
|
$data = ['header' => new Header($namespacesPaths, $sanitizeEncoding, $data, $companyRegistrationNumber, $resolveOptions)]; |
39
|
|
|
} |
40
|
|
|
|
41
|
19 |
|
parent::__construct($namespacesPaths, $sanitizeEncoding, $data, $companyRegistrationNumber, $resolveOptions); |
42
|
|
|
} |
43
|
|
|
|
44
|
1 |
|
public function getImportRoot(): string |
45
|
|
|
{ |
46
|
1 |
|
return 'lStk:stock'; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Add stock item. |
51
|
|
|
* |
52
|
|
|
* @param array<string,mixed> $data |
53
|
|
|
* |
54
|
|
|
* @return $this |
55
|
|
|
*/ |
56
|
1 |
|
public function addStockItem(array $data): self |
57
|
|
|
{ |
58
|
1 |
|
if (!isset($this->data['stockDetail']) |
59
|
1 |
|
|| !( |
60
|
1 |
|
is_array($this->data['stockDetail']) |
61
|
1 |
|
|| (is_object($this->data['stockDetail']) && is_a($this->data['stockDetail'], \ArrayAccess::class)) |
62
|
1 |
|
) |
63
|
|
|
) { |
64
|
1 |
|
$this->data['stockDetail'] = []; |
65
|
|
|
} |
66
|
|
|
|
67
|
1 |
|
$this->data['stockDetail'][] = new StockItem($this->namespacesPaths, $this->sanitizeEncoding, $data, $this->companyRegistrationNumber); |
68
|
|
|
|
69
|
1 |
|
return $this; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Add price. |
74
|
|
|
* |
75
|
|
|
* @param string $code |
76
|
|
|
* @param float $value |
77
|
|
|
* |
78
|
|
|
* @return $this |
79
|
|
|
*/ |
80
|
1 |
|
public function addPrice(string $code, float $value): self |
81
|
|
|
{ |
82
|
1 |
|
if (!isset($this->data['stockPriceItem']) |
83
|
1 |
|
|| !( |
84
|
1 |
|
is_array($this->data['stockPriceItem']) |
85
|
1 |
|
|| (is_object($this->data['stockPriceItem']) && is_a($this->data['stockPriceItem'], \ArrayAccess::class)) |
86
|
1 |
|
) |
87
|
|
|
) { |
88
|
1 |
|
$this->data['stockPriceItem'] = []; |
89
|
|
|
} |
90
|
|
|
|
91
|
1 |
|
$this->data['stockPriceItem'][] = new Price($this->namespacesPaths, $this->sanitizeEncoding, [ |
92
|
1 |
|
'ids' => $code, |
93
|
1 |
|
'price' => $value |
94
|
1 |
|
], $this->companyRegistrationNumber); |
95
|
|
|
|
96
|
1 |
|
return $this; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Add image. |
101
|
|
|
* |
102
|
|
|
* @param string $filepath |
103
|
|
|
* @param string $description |
104
|
|
|
* @param int|null $order |
105
|
|
|
* @param bool $default |
106
|
|
|
* |
107
|
|
|
* @return $this |
108
|
|
|
*/ |
109
|
1 |
|
public function addImage(string $filepath, string $description = '', int $order = null, bool $default = false): self |
110
|
|
|
{ |
111
|
1 |
|
$object = $this->data['header']; |
112
|
|
|
/** @var Header $object */ |
113
|
1 |
|
$object->addImage($filepath, $description, $order, $default); |
114
|
|
|
|
115
|
1 |
|
return $this; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Add category. |
120
|
|
|
* |
121
|
|
|
* @param int $categoryId |
122
|
|
|
* |
123
|
|
|
* @return $this |
124
|
|
|
*/ |
125
|
1 |
|
public function addCategory(int $categoryId): self |
126
|
|
|
{ |
127
|
1 |
|
$object = $this->data['header']; |
128
|
|
|
/** @var Header $object */ |
129
|
1 |
|
$object->addCategory($categoryId); |
130
|
|
|
|
131
|
1 |
|
return $this; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Add int parameter. |
136
|
|
|
* |
137
|
|
|
* @param array<string,mixed> $data |
138
|
|
|
* |
139
|
|
|
* @return $this |
140
|
|
|
*/ |
141
|
1 |
|
public function addIntParameter(array $data): self |
142
|
|
|
{ |
143
|
1 |
|
$object = $this->data['header']; |
144
|
|
|
/** @var Header $object */ |
145
|
1 |
|
$object->addIntParameter($data); |
146
|
|
|
|
147
|
1 |
|
return $this; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* {@inheritdoc} |
152
|
|
|
*/ |
153
|
16 |
|
public function getXML(): \SimpleXMLElement |
154
|
|
|
{ |
155
|
16 |
|
$xml = $this->createXML()->addChild('stk:stock', '', $this->namespace('stk')); |
156
|
16 |
|
$xml->addAttribute('version', '2.0'); |
157
|
|
|
|
158
|
16 |
|
$this->addElements($xml, ['actionType', 'header', 'stockDetail', 'stockPriceItem'], 'stk'); |
159
|
|
|
|
160
|
16 |
|
return $xml; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* {@inheritdoc} |
165
|
|
|
*/ |
166
|
1 |
|
protected function configureOptions(Common\OptionsResolver $resolver): void |
167
|
|
|
{ |
168
|
|
|
// available options |
169
|
1 |
|
$resolver->setDefined(['header']); |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
|