Skip to content

feat: added support for nested filters (extId, selectedNumbers, selectedCompanys, selectedIco) #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions spec/Pohoda/ListRequestSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,31 @@ public function it_creates_correct_xml_for_order()
$this->getXML()->asXML()->shouldReturn('<lst:listOrderRequest version="2.0" orderVersion="2.0" orderType="receivedOrder"><lst:requestOrder/></lst:listOrderRequest>');
}

public function it_creates_correct_xml_for_order_with_complex_filter()
{
$this->beConstructedWith([
'type' => 'Order'
], '123');

$this->addFilter([
'extId' => [
'ids' => '2022041186',
'exSystemName' => 'Riešenia',
],
'selectedNumbers' => [
'number' => [
'numberRequested' => '2022041186',
],
],
'selectedCompanys' => [
'company' => ['Riešenia, spol. s r.o.'],
],
'selectedIco' => [
'ico' => [35948345],
],
])->getXML()->asXML()->shouldReturn('<lst:listOrderRequest version="2.0" orderVersion="2.0" orderType="receivedOrder"><lst:requestOrder><ftr:filter><ftr:extId><typ:ids>2022041186</typ:ids><typ:exSystemName>Riešenia</typ:exSystemName></ftr:extId><ftr:selectedNumbers><ftr:number><typ:numberRequested>2022041186</typ:numberRequested></ftr:number></ftr:selectedNumbers><ftr:selectedCompanys><ftr:company>Riešenia, spol. s r.o.</ftr:company></ftr:selectedCompanys><ftr:selectedIco><ftr:ico>35948345</ftr:ico></ftr:selectedIco></ftr:filter></lst:requestOrder></lst:listOrderRequest>');
}

public function it_creates_correct_xml_for_advance_invoice()
{
$this->beConstructedWith([
Expand Down
16 changes: 15 additions & 1 deletion src/Pohoda/Agenda.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,21 @@ protected function _addRefElement(\SimpleXMLElement $xml, string $name, $value,
}

foreach ($value as $key => $value) {
$node->addChild('typ:' . $key, $this->_sanitize($value), $this->_namespace('typ'));
if (\is_array($value)) {
if (array_is_list($value)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nema backward compatibility

foreach ($value as $value) {
$node->addChild($namespace . ':' . $key, $this->_sanitize($value), $this->_namespace($namespace));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toto je dost na mieru toho filtra na to, ze je to umiestnene v Agende. ja by som pravdupovediac idealne tuto cast kodu vobec nechytal

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
} else {
$node = $node->addChild($namespace . ':' . $key, '', $this->_namespace($namespace));

foreach ($value as $key => $value) {
$node->addChild('typ:' . $key, $this->_sanitize($value), $this->_namespace('typ'));
}
}
} else {
$node->addChild('typ:' . $key, $this->_sanitize($value), $this->_namespace('typ'));
}
}

return $node;
Expand Down
4 changes: 2 additions & 2 deletions src/Pohoda/ListRequest/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
class Filter extends Agenda
{
/** @var string[] */
protected $_refElements = ['storage', 'store'];
protected $_refElements = ['extId', 'storage', 'store', 'selectedNumbers', 'selectedCompanys', 'selectedIco'];

/** @var string[] */
protected $_elements = ['id', 'code', 'EAN', 'name', 'storage', 'store', 'internet', 'company', 'ico', 'dic', 'lastChanges', 'dateFrom', 'dateTill'];
protected $_elements = ['id', 'extId', 'code', 'EAN', 'name', 'storage', 'store', 'internet', 'company', 'ico', 'dic', 'lastChanges', 'dateFrom', 'dateTill', 'selectedNumbers', 'selectedCompanys', 'selectedIco'];

/**
* {@inheritdoc}
Expand Down
Loading