42 lines
1.5 KiB
PHP
42 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\BusProNet\XmlParser;
|
|
|
|
use App\BusProNet\Model\Room;
|
|
use Symfony\Component\DomCrawler\Crawler;
|
|
|
|
class RoomsParser extends AbstractParser
|
|
{
|
|
public function parse(Crawler $result): array
|
|
{
|
|
$rooms = [];
|
|
|
|
$result->each(function (Crawler $node) use (&$rooms) {
|
|
$room = new Room();
|
|
$room->id = (int) $node->attr('idzimmer');
|
|
$room->label = $node->attr('zimmer');
|
|
$room->category = $node->attr('kategorie');
|
|
$room->boardId = (int) $node->attr('idverpflegung');
|
|
$room->dateFrom = $this->stringToDate($node->attr('anreise'));
|
|
$room->dateTo = $this->stringToDate($node->attr('abreise'));
|
|
$room->totalCount = (int) $node->attr('anzahl');
|
|
$room->minPax = (int) $node->attr('minpax');
|
|
$room->maxPax = (int) $node->attr('maxpax');
|
|
$room->board = $node->attr('verpflegung');
|
|
$mapping = $this->stringToArray($node->attr('zuordnung'));
|
|
$room->mapping = array_map(function ($index) { return (int) $index - 1; }, $mapping);
|
|
$room->totalPrice = $this->stringToFloat($node->attr('gesamtpreis'));
|
|
$individualPrices = array_map(
|
|
function ($price) {
|
|
return $this->stringToFloat($price);
|
|
}, $this->stringToArray($node->attr('einzelpreis', ''), '/')
|
|
);
|
|
$room->individualPrice = array_combine($room->mapping, $individualPrices);
|
|
|
|
$rooms[$room->id] = $room;
|
|
});
|
|
|
|
return $rooms;
|
|
}
|
|
}
|