1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of riesenia/pohoda package. |
5
|
|
|
* |
6
|
|
|
* Licensed under the MIT License |
7
|
|
|
* (c) RIESENIA.com |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace Riesenia\Pohoda\Type; |
13
|
|
|
|
14
|
|
|
use Riesenia\Pohoda\AbstractAgenda; |
15
|
|
|
use Riesenia\Pohoda\Common\OptionsResolver; |
16
|
|
|
use Riesenia\Pohoda\Common\SetNamespaceTrait; |
17
|
|
|
|
18
|
|
|
class ActionType extends AbstractAgenda |
19
|
|
|
{ |
20
|
|
|
use SetNamespaceTrait; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* {@inheritdoc} |
24
|
|
|
*/ |
25
|
8 |
|
public function getXML(): \SimpleXMLElement |
26
|
|
|
{ |
27
|
8 |
|
if (is_null($this->namespace)) { |
28
|
1 |
|
throw new \LogicException('Namespace not set.'); |
29
|
|
|
} |
30
|
|
|
|
31
|
7 |
|
$xml = $this->createXML()->addChild($this->namespace . ':actionType', '', $this->namespace($this->namespace)); |
32
|
7 |
|
$action = $xml->addChild($this->namespace . ':' . ('add/update' == $this->data['type'] ? 'add' : $this->data['type'])); |
33
|
|
|
|
34
|
7 |
|
if ('add/update' == $this->data['type']) { |
35
|
1 |
|
$action->addAttribute('update', 'true'); |
36
|
|
|
} |
37
|
|
|
|
38
|
7 |
|
if (isset($this->data['filter']) && is_iterable($this->data['filter'])) { |
39
|
6 |
|
$filter = $action->addChild('ftr:filter', '', $this->namespace('ftr')); |
40
|
|
|
|
41
|
6 |
|
if ($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, $tValue, $this->namespace('typ')); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
7 |
|
return $xml; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritdoc} |
61
|
|
|
*/ |
62
|
1 |
|
protected function configureOptions(OptionsResolver $resolver): void |
63
|
|
|
{ |
64
|
|
|
// available options |
65
|
1 |
|
$resolver->setDefined(['type', 'filter', 'agenda']); |
66
|
|
|
|
67
|
|
|
// validate / format options |
68
|
1 |
|
$resolver->setRequired('type'); |
69
|
1 |
|
$resolver->setAllowedValues('type', ['add', 'add/update', 'update', 'delete']); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|