wip: continue implementation

This commit is contained in:
Björn Fromme
2024-12-02 17:38:56 +01:00
parent 84ab6446ea
commit 6f989d4c7a
24 changed files with 444 additions and 237 deletions
@@ -2,6 +2,7 @@
namespace App\BusProNet\ApiResponseParser;
use App\BusProNet\Model\CrmAction;
use App\BusProNet\Model\CrmAttributes;
use App\BusProNet\Model\CrmSelection;
use App\BusProNet\Model\CrmSelectionGroup;
@@ -18,11 +19,13 @@ class CrmAttributesResponseParser
public function parse(\SimpleXMLElement $xml): CrmAttributes
{
$groups = [];
$actions = [];
$isAdmin = $isManager = $isHouseManager = $isTeamer = false;
$hotelCode = null;
foreach ($xml->selektionsmerkmale->selektionsgruppe as $item) {
$group = new CrmSelectionGroup();
$group->id = (int) $item->attributes()['id'];
$group->label = (string) $item->attributes()['bezeichnung'];
$attributes = [];
@@ -32,6 +35,7 @@ class CrmAttributesResponseParser
$attribute = new CrmSelection();
$attribute->id = (int) $subItemAttributes['id'];
$attribute->label = $attributeLabel;
$attribute->mutable = $this->stringToBool((string) $subItemAttributes['aenderbar']);
$attribute->selected = $this->stringToBool((string) $subItemAttributes['auswahl']);
if (1 === preg_match('/^Hausleitung ([A-Z0-9]+)$/', $attributeLabel, $matches) && true === $attribute->selected) {
@@ -54,8 +58,21 @@ class CrmAttributesResponseParser
$groups[] = $group;
}
foreach ($xml->crmaktionen->crmaktion as $item) {
$attributes = $item->attributes();
$crmAction = new CrmAction();
$crmAction->id = (int) $attributes['id'];
$crmAction->code = (string) $attributes['code'];
$crmAction->label = (string) $attributes['bezeichnung'];
$crmAction->mutable = $this->stringToBool((string) $attributes['aenderbar']);
$crmAction->selected = $this->stringToBool((string) $attributes['auswahl']);
$actions[] = $crmAction;
}
$response = new CrmAttributes();
$response->selectionGroups = $groups;
$response->crmActions = $actions;
$response->admin = $isAdmin;
$response->manager = $isManager;
$response->houseManager = $isHouseManager;
@@ -64,4 +81,4 @@ class CrmAttributesResponseParser
return $response;
}
}
}
+9 -1
View File
@@ -2,10 +2,18 @@
namespace App\BusProNet\Model;
class Availability
class Availability implements \JsonSerializable
{
public ?int $serviceId = null;
public ?string $status = null;
public ?int $available = null;
public ?float $price = null;
public function jsonSerialize(): array
{
return [
'id' => $this->serviceId,
'available' => $this->available,
];
}
}
+12
View File
@@ -0,0 +1,12 @@
<?php
namespace App\BusProNet\Model;
class CrmAction
{
public ?int $id = null;
public ?string $code = null;
public ?string $label = null;
public bool $mutable = false;
public bool $selected = false;
}
+1 -21
View File
@@ -5,30 +5,10 @@ namespace App\BusProNet\Model;
class CrmAttributes
{
public ?array $selectionGroups = null;
public ?array $crmActions = null;
public bool $admin = false;
public bool $manager = false;
public bool $houseManager = false;
public bool $teamer = false;
public ?string $hotelCode = null;
public function toArray(): array
{
$crmSelections = [];
foreach ($this->selectionGroups as $group) {
/** @var CrmSelectionGroup $group */
if (false === isset($crmSelections[$group->label])) {
$crmSelections[$group->label] = [];
}
foreach ($group->selections as $attribute) {
/** @var CrmSelection $attribute */
if (false === $attribute->selected) {
continue;
}
$crmSelections[$group->label][] = $attribute->label;
}
}
return $crmSelections;
}
}
+1
View File
@@ -6,5 +6,6 @@ class CrmSelection
{
public ?int $id = null;
public ?string $label = null;
public bool $mutable = false;
public bool $selected = false;
}
+12
View File
@@ -19,4 +19,16 @@ class CrmSelectionGroup
public ?int $id = null;
public ?string $label = null;
public ?array $selections = null;
public function getMutableSelections(): array
{
return array_filter($this->selections, function (CrmSelection $selection) {
return $selection->mutable;
});
}
public function isVisible(): bool
{
return 0 < count($this->getMutableSelections());
}
}