|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace kalanis\Pohoda\Type; |
|
6
|
|
|
|
|
7
|
|
|
use kalanis\Pohoda\AbstractAgenda; |
|
8
|
|
|
use kalanis\Pohoda\Common; |
|
9
|
|
|
use kalanis\PohodaException; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @property Dtos\ActionTypeDto $data |
|
13
|
|
|
*/ |
|
14
|
|
|
class ActionType extends AbstractAgenda |
|
15
|
|
|
{ |
|
16
|
|
|
use Common\SetNamespaceTrait; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* {@inheritdoc} |
|
20
|
|
|
*/ |
|
21
|
8 |
|
public function getXML(): \SimpleXMLElement |
|
22
|
|
|
{ |
|
23
|
8 |
|
if (is_null($this->namespace)) { |
|
24
|
1 |
|
throw new PohodaException('Namespace not set.'); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
7 |
|
$xml = $this->createXML()->addChild($this->namespace . ':actionType', '', $this->namespace($this->namespace)); |
|
28
|
7 |
|
$action = $xml->addChild($this->namespace . ':' . ( |
|
29
|
7 |
|
Enums\ActionTypeEnum::AddUpdate->value == $this->data->type |
|
30
|
1 |
|
? Enums\ActionTypeEnum::Add->value |
|
31
|
7 |
|
: \strval($this->data->type) |
|
32
|
7 |
|
)); |
|
33
|
|
|
|
|
34
|
7 |
|
if (Enums\ActionTypeEnum::AddUpdate->value == $this->data->type) { |
|
35
|
1 |
|
$action->addAttribute(Enums\ActionTypeEnum::Update->value, 'true'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
7 |
|
if (!empty($this->data->filter)) { |
|
39
|
6 |
|
$filter = $action->addChild('ftr:filter', '', $this->namespace('ftr')); |
|
40
|
|
|
|
|
41
|
6 |
|
if (!empty($this->data->agenda)) { |
|
42
|
1 |
|
$filter->addAttribute('agenda', strval($this->data->agenda)); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
6 |
|
foreach ($this->data->filter as $property => $value) { |
|
46
|
6 |
|
$ftr = $filter->addChild('ftr:' . $property, \is_array($value) ? null : \strval($value)); |
|
47
|
|
|
|
|
48
|
6 |
|
if (\is_array($value)) { |
|
49
|
2 |
|
foreach ($value as $tProperty => $tValue) { |
|
50
|
2 |
|
$ftr->addChild('typ:' . $tProperty, \strval($tValue), $this->namespace('typ')); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
7 |
|
return $xml; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* {@inheritDoc} |
|
61
|
|
|
*/ |
|
62
|
10 |
|
protected function getDefaultDto(): Common\Dtos\AbstractDto |
|
63
|
|
|
{ |
|
64
|
10 |
|
return new Dtos\ActionTypeDto(); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|