|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace kalanis\Pohoda; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @property Category\CategoryDto $data |
|
9
|
|
|
*/ |
|
10
|
|
|
class Category extends AbstractAgenda |
|
11
|
|
|
{ |
|
12
|
4 |
|
public function getImportRoot(): string |
|
13
|
|
|
{ |
|
14
|
4 |
|
return 'ctg:category'; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
3 |
|
public function canImportRecursive(): bool |
|
18
|
|
|
{ |
|
19
|
3 |
|
return true; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Add subcategory. |
|
24
|
|
|
* |
|
25
|
|
|
* @param self|Category\CategoryDto $category |
|
26
|
|
|
* |
|
27
|
|
|
* @return $this |
|
28
|
|
|
*/ |
|
29
|
1 |
|
public function addSubcategory(self|Category\CategoryDto $category): self |
|
30
|
|
|
{ |
|
31
|
1 |
|
$this->data->subCategories[] = $category; |
|
32
|
|
|
|
|
33
|
1 |
|
return $this; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* {@inheritdoc} |
|
38
|
|
|
*/ |
|
39
|
2 |
|
public function getXML(): \SimpleXMLElement |
|
40
|
|
|
{ |
|
41
|
2 |
|
$xml = $this->createXML()->addChild('ctg:categoryDetail', '', $this->namespace('ctg')); |
|
42
|
2 |
|
$xml->addAttribute('version', '2.0'); |
|
43
|
|
|
|
|
44
|
2 |
|
$this->categoryXML($xml); |
|
45
|
|
|
|
|
46
|
2 |
|
return $xml; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Attach category to XML element. |
|
51
|
|
|
* |
|
52
|
|
|
* @param \SimpleXMLElement $xml |
|
53
|
|
|
* |
|
54
|
|
|
* @return void |
|
55
|
|
|
*/ |
|
56
|
2 |
|
public function categoryXML(\SimpleXMLElement $xml) |
|
57
|
|
|
{ |
|
58
|
2 |
|
$category = $xml->addChild('ctg:category', '', $this->namespace('ctg')); |
|
59
|
|
|
|
|
60
|
2 |
|
$this->addElements($category, $this->getDataElements(), 'ctg'); |
|
61
|
|
|
|
|
62
|
2 |
|
if (!empty($this->data->subCategories)) { |
|
63
|
1 |
|
$subCategories = $category->addChild('ctg:subCategories', '', $this->namespace('ctg')); |
|
64
|
|
|
|
|
65
|
1 |
|
foreach ($this->data->subCategories as $subCategory) { |
|
66
|
1 |
|
if (\is_a($subCategory, self::class)) { |
|
67
|
1 |
|
$subCategory->categoryXML($subCategories); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* {@inheritdoc} |
|
75
|
|
|
*/ |
|
76
|
6 |
|
protected function getDefaultDto(): Common\Dtos\AbstractDto |
|
77
|
|
|
{ |
|
78
|
6 |
|
return new Category\CategoryDto(); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|