Refactor product export to include ids and service categories

This commit is contained in:
Björn Fromme
2018-08-10 12:47:17 +02:00
parent 24f9387f59
commit 0a6f8030f9
12 changed files with 127 additions and 415 deletions
+2 -2
View File
@@ -65,9 +65,9 @@
"doctrine/dbal": "^2.5", "doctrine/dbal": "^2.5",
"yohang/calendr": "^2.1", "yohang/calendr": "^2.1",
"wyrihaximus/html-compress": "^1.4", "wyrihaximus/html-compress": "^1.4",
"symfony/serializer": "3.3.*",
"symfony/property-access": "^3.4", "symfony/property-access": "^3.4",
"symfony/options-resolver": "^3.4" "symfony/options-resolver": "^3.4",
"symfony/serializer": "^3.3"
}, },
"scripts": { "scripts": {
"typo3-cms-scripts": [ "typo3-cms-scripts": [
Generated
+4 -3
View File
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "24a1dae8a5e81d4d36f7e5988eaace7a", "content-hash": "f02741f6bee387f8f2b8ec67b91ef940",
"packages": [ "packages": [
{ {
"name": "cogpowered/finediff", "name": "cogpowered/finediff",
@@ -2262,7 +2262,7 @@
}, },
{ {
"name": "symfony/serializer", "name": "symfony/serializer",
"version": "v3.3.17", "version": "v3.3.18",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/serializer.git", "url": "https://github.com/symfony/serializer.git",
@@ -4675,7 +4675,8 @@
"prefer-stable": false, "prefer-stable": false,
"prefer-lowest": false, "prefer-lowest": false,
"platform": { "platform": {
"php": "^5.6" "php": "^5.6",
"ext-json": "*"
}, },
"platform-dev": [], "platform-dev": [],
"platform-overrides": { "platform-overrides": {
@@ -253,12 +253,12 @@ class ProductRepository extends AbstractRepository
$query = $qb $query = $qb
->select( ->select(
'date.date_start dateStart', 'date.date_end dateEnd', 'date.bus_pro_id dateBusProId', 'date.date_start dateStart', 'date.date_end dateEnd',
'date.min_price dateMinPrice', 'date.discount dateDiscount', 'date.bus_price busPrice', 'date.min_price dateMinPrice', 'date.discount dateDiscount', 'date.bus_price busPrice',
'date.nights dateNights', 'date.bus_included dateBusIncluded', 'date.services_included dateServicesIncluded', 'date.nights dateNights', 'date.bus_included dateBusIncluded', 'date.services_included dateServicesIncluded',
'date.services_general dateServicesGeneral', 'date.skipass_included dateSkipassIncluded', 'date.services_general dateServicesGeneral', 'date.skipass_included dateSkipassIncluded',
'date.bus_pro_id dateBusProId', 'date.hotel_bus_pro_id hotelBusProId', 'date.pickups pickups', 'date.bus_pro_id dateBusProId', 'date.hotel_bus_pro_id hotelBusProId', 'date.pickups pickups',
'room.uid as roomUid', 'room.bus_pro_id roomBusProId', 'room.name roomName', 'room.uid as roomUid', 'room.bus_pro_id roomBusProId', 'room.code roomCode', 'room.name roomName',
'room.price roomPrice', 'date.discount roomDiscount', 'date.bus_price busPrice', 'room.price roomPrice', 'date.discount roomDiscount', 'date.bus_price busPrice',
'room.services roomOptionalServices', 'room.nights roomNights', 'room.available roomAvailable' 'room.services roomOptionalServices', 'room.nights roomNights', 'room.available roomAvailable'
) )
@@ -27,49 +27,27 @@ namespace EP\EpProducts\Domain\Serialization;
* This copyright notice MUST APPEAR in all copies of the script! * This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/ ***************************************************************/
use EP\EpProducts\Domain\Model\Fact;
use EP\EpProducts\Utility\SerializationUtility; use EP\EpProducts\Utility\SerializationUtility;
class City class City
{ {
/**
* @var string
*/
public $name;
/**
* @var string
*/
public $description;
/**
* @var string
*/
public $party;
/**
* @var string
*/
public $leisure;
/**
* @var array
*/
public $facts = [];
/** /**
* @param \EP\EpProducts\Domain\Model\City $entity * @param \EP\EpProducts\Domain\Model\City $entity
* @return City * @return array
*/ */
public static function fromEntity(\EP\EpProducts\Domain\Model\City $entity) public static function fromEntity(\EP\EpProducts\Domain\Model\City $entity)
{ {
$city = new self; $city = [];
$city->name = $entity->getName(); $city['@id'] = $entity->getUid();
$city->description = SerializationUtility::sanitizeText($entity->getDescription()); $city['name'] = $entity->getName();
$city->party = SerializationUtility::sanitizeText($entity->getParty()); $city['description'] = SerializationUtility::sanitizeText($entity->getDescription());
$city->leisure = SerializationUtility::sanitizeText($entity->getLeisure()); $city['party'] = SerializationUtility::sanitizeText($entity->getParty());
$city->facts['fact'] = array_map(function ($fact) { $city['leisure'] = SerializationUtility::sanitizeText($entity->getLeisure());
$city['facts'] = [];
$city['facts']['fact'] = array_map(function ($fact) {
/** @var Fact $fact */
return htmlspecialchars($fact->getName()); return htmlspecialchars($fact->getName());
}, $entity->getFacts()->toArray()); }, $entity->getFacts()->toArray());
@@ -29,88 +29,32 @@ namespace EP\EpProducts\Domain\Serialization;
class Date class Date
{ {
/**
* @var string
*/
public $from;
/**
* @var string
*/
public $to;
/**
* @var string
*/
public $minprice;
/**
* @var string
*/
public $nights;
/**
* @var string
*/
public $busincluded;
/**
* @var string
*/
public $skipassincluded;
/**
* @var array
*/
public $servicesincluded = [];
/**
* @var array
*/
public $servicesoptional = [];
/**
* @var array
*/
public $rooms = [];
/**
* @var array
*/
public $pickups = [];
/**
* @var string
*/
public $bookingurl;
/** /**
* @param array $array * @param array $array
* @return Date * @return array
*/ */
public static function fromArray(array $array) public static function fromArray(array $array)
{ {
$date = new self; $date = [
'servicesincluded' => [],
'servicesoptional' => [],
'rooms' => [],
];
$date->from = $array['dateStart']; $date['@id'] = $array['dateBusProId'];
$date->to = $array['dateEnd']; $date['from'] = $array['dateStart'];
$date->minprice = $array['dateMinPrice']; $date['to'] = $array['dateEnd'];
$date->nights = $array['dateNights']; $date['minprice'] = $array['dateMinPrice'];
$date->skipassincluded = $array['dateSkipassIncluded']; $date['nights'] = $array['dateNights'];
$date->busincluded = $array['dateBusIncluded']; $date['skipassincluded'] = $array['dateSkipassIncluded'];
$date->servicesincluded['service'] = unserialize($array['dateServicesIncluded']); $date['busincluded'] = $array['dateBusIncluded'];
$date['servicesincluded']['service'] = unserialize($array['dateServicesIncluded']);
$servicesGeneral = unserialize($array['dateServicesGeneral']); $servicesGeneral = unserialize($array['dateServicesGeneral']);
foreach ($servicesGeneral as $category) $date['servicesoptional'] = Services::fromArray($servicesGeneral);
{ $date['pickups'] = [];
foreach ($category as $row)
{
$date->servicesoptional['service'][] = Service::fromArray($row);
}
}
foreach (unserialize($array['pickups']) as $row) foreach (unserialize($array['pickups']) as $row)
{ {
$date->pickups['pickup'][] = Pickup::fromArray($row); $date['pickups']['pickup'][] = $row;
} }
return $date; return $date;
@@ -30,56 +30,25 @@ use EP\EpProducts\Utility\SerializationUtility;
class Hotel class Hotel
{ {
/**
* @var string
*/
public $name;
/**
* @var string
*/
public $type;
/**
* @var string
*/
public $category;
/**
* @var string
*/
public $description;
/**
* @var string
*/
public $features;
/**
* @var array
*/
public $images = [];
/**
* @var array
*/
public $dates = [];
/** /**
* @param \EP\EpProducts\Domain\Model\Hotel $entity * @param \EP\EpProducts\Domain\Model\Hotel $entity
* @return Hotel * @return array
*/ */
public static function fromEntity(\EP\EpProducts\Domain\Model\Hotel $entity) public static function fromEntity(\EP\EpProducts\Domain\Model\Hotel $entity)
{ {
$hotel = new self; $hotel = [
'dates' => [],
'images' => [],
];
$hotel->name = $entity->getName(); $hotel['@id'] = $entity->getUid();
$hotel->category = \EP\EpProducts\Domain\Model\Hotel::$categoryLabels[$entity->getCategory()]; $hotel['@code'] = $entity->getCode();
$hotel->type = \EP\EpProducts\Domain\Model\Hotel::$typeLabels[$entity->getType()]; $hotel['name'] = $entity->getName();
$hotel->description = SerializationUtility::sanitizeText($entity->getDescription()); $hotel['category'] = \EP\EpProducts\Domain\Model\Hotel::$categoryLabels[$entity->getCategory()];
$hotel->features = SerializationUtility::sanitizeText($entity->getFeatures()); $hotel['type'] = \EP\EpProducts\Domain\Model\Hotel::$typeLabels[$entity->getType()];
$hotel->images['image'] = SerializationUtility::preprocessImages($entity->getResellerImages()); $hotel['description'] = SerializationUtility::sanitizeText($entity->getDescription());
$hotel['features'] = SerializationUtility::sanitizeText($entity->getFeatures());
$hotel['images']['image'] = SerializationUtility::preprocessImages($entity->getResellerImages());
return $hotel; return $hotel;
} }
@@ -32,86 +32,38 @@ use EP\EpProducts\Utility\SerializationUtility;
class Product class Product
{ {
/**
* @var string
*/
public $name;
/**
* @var array
*/
public $facts = [];
/**
* @var string
*/
public $skipass;
/**
* @var array
*/
public $concept = [];
/**
* @var string
*/
public $board;
/**
* @var string
*/
public $programme;
/**
* @var Region
*/
public $region;
/**
* @var City
*/
public $city;
/**
* @var array
*/
public $images = [];
/**
* @var array
*/
public $hotels = [];
/**
* @var string
*/
public $video;
/** /**
* @param \EP\EpProducts\Domain\Model\Product $entity * @param \EP\EpProducts\Domain\Model\Product $entity
* @return Product * @return array
*/ */
public static function fromEntity(\EP\EpProducts\Domain\Model\Product $entity) public static function fromEntity(\EP\EpProducts\Domain\Model\Product $entity)
{ {
$product = new self; $product = [
'concept' => [],
'facts' => [],
'hotels' => [],
'images' => [],
];
$product->name = preg_replace('/[\r\n\s]+/', ' ', $entity->getName()); $product['@id'] = $entity->getBusProId();
$product['@code'] = $entity->getCode();
$product['name'] = preg_replace('/[\r\n\s]+/', ' ', $entity->getName());
$product->facts['fact'] = array_map(function ($fact) { $product['facts']['fact'] = array_map(function ($fact) {
/** @var Fact $fact */ /** @var Fact $fact */
return htmlspecialchars($fact->getName()); return htmlspecialchars($fact->getName());
}, $entity->getFacts()->toArray()); }, $entity->getFacts()->toArray());
$product->skipass = SerializationUtility::sanitizeText($entity->getSkiPassDescription()); $product['skipass'] = SerializationUtility::sanitizeText($entity->getSkiPassDescription());
$product->concept['name'] = $entity->getConcept()->getName(); $product['concept']['name'] = $entity->getConcept()->getName();
$product->concept['description'] = SerializationUtility::sanitizeText($entity->getConcept()->getDescription()); $product['concept']['description'] = SerializationUtility::sanitizeText($entity->getConcept()->getDescription());
$product->board = SerializationUtility::sanitizeText($entity->getBoardDescription()); $product['board'] = SerializationUtility::sanitizeText($entity->getBoardDescription());
$product->programme = SerializationUtility::sanitizeText($entity->getProgrammeDescription()); $product['programme'] = SerializationUtility::sanitizeText($entity->getProgrammeDescription());
$product->images['image'] = SerializationUtility::preprocessImages($entity->getResellerImages()); $product['images']['image'] = SerializationUtility::preprocessImages($entity->getResellerImages());
$product->video = $entity->getVideo(); $product['video'] = $entity->getVideo();
$product->region = Region::fromEntity($entity->getRegion()); $product['region'] = Region::fromEntity($entity->getRegion());
$product->city = City::fromEntity($entity->getCity()); $product['city'] = City::fromEntity($entity->getCity());
return $product; return $product;
} }
@@ -27,74 +27,31 @@ namespace EP\EpProducts\Domain\Serialization;
* This copyright notice MUST APPEAR in all copies of the script! * This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/ ***************************************************************/
use EP\EpProducts\Domain\Model\Fact;
use EP\EpProducts\Utility\SerializationUtility; use EP\EpProducts\Utility\SerializationUtility;
class Region class Region
{ {
/**
* @var string
*/
public $name;
/**
* @var string
*/
public $description;
/**
* @var string
*/
public $descriptionExtended;
/**
* @var string
*/
public $piste;
/**
* @var string
*/
public $height;
/**
* @var string
*/
public $lifts;
/**
* @var string
*/
public $skipass;
/**
* @var
*/
public $news;
/**
* @var array
*/
public $facts = [];
/** /**
* @param \EP\EpProducts\Domain\Model\Region $entity * @param \EP\EpProducts\Domain\Model\Region $entity
* @return Region * @return array
*/ */
public static function fromEntity(\EP\EpProducts\Domain\Model\Region $entity) public static function fromEntity(\EP\EpProducts\Domain\Model\Region $entity)
{ {
$region = new self; $region = [];
$region->name = $entity->getName(); $region['@id'] = $entity->getUid();
$region->description = SerializationUtility::sanitizeText($entity->getSkiArea()); $region['name'] = $entity->getName();
$region->descriptionExtended = SerializationUtility::sanitizeText($entity->getSkiAreaExtended()); $region['description'] = SerializationUtility::sanitizeText($entity->getSkiArea());
$region->piste = $entity->getLength(); $region['descriptionExtended'] = SerializationUtility::sanitizeText($entity->getSkiAreaExtended());
$region->height = $entity->getHeight(); $region['piste'] = $entity->getLength();
$region->lifts = $entity->getLifts(); $region['height'] = $entity->getHeight();
$region->skipass = SerializationUtility::sanitizeText($entity->getSkiPass()); $region['lifts'] = $entity->getLifts();
$region->news = SerializationUtility::sanitizeText($entity->getNews()); $region['skipass'] = SerializationUtility::sanitizeText($entity->getSkiPass());
$region['news'] = SerializationUtility::sanitizeText($entity->getNews());
$region->facts['fact'] = array_map(function ($fact) { $region['facts'] = [];
$region['facts']['fact'] = array_map(function ($fact) {
/** @var Fact $fact */
return htmlspecialchars($fact->getName()); return htmlspecialchars($fact->getName());
}, $entity->getFacts()->toArray()); }, $entity->getFacts()->toArray());
@@ -28,59 +28,24 @@ namespace EP\EpProducts\Domain\Serialization;
class Room class Room
{ {
/**
* @var string
*/
public $name;
/**
* @var string
*/
public $price;
/**
* @var string
*/
public $busprice;
/**
* @var array
*/
public $servicesoptional;
/**
* @var string
*/
public $nights;
/**
* @var string
*/
public $available;
/** /**
* @param array $array * @param array $array
* @return Room * @return array
*/ */
public static function fromArray(array $array) public static function fromArray(array $array)
{ {
$room = new self; $room = [];
$room->name = $array['roomName']; $room['@id'] = $array['roomBusProId'];
$room->price = $array['roomPrice']; $room['@code'] = $array['roomCode'];
$room->busprice = $array['busPrice']; $room['name'] = $array['roomName'];
$room->nights = $array['roomNights']; $room['price'] = $array['roomPrice'];
$room->available = $array['roomAvailable']; $room['busprice'] = $array['busPrice'];
$room['nights'] = $array['roomNights'];
$room['available'] = $array['roomAvailable'];
$servicesOptional = unserialize($array['roomOptionalServices']); $servicesOptional = unserialize($array['roomOptionalServices']);
foreach ($servicesOptional as $category) $room['servicesoptional'] = Services::fromArray($servicesOptional);
{
foreach ($category as $row)
{
$room->servicesoptional['service'][] = Service::fromArray($row);
}
}
return $room; return $room;
} }
@@ -1,55 +0,0 @@
<?php
namespace EP\EpProducts\Domain\Serialization;
/***************************************************************
*
* Copyright notice
*
* (c) 2018 Björn Fromme <[email protected]>, dreipunktnull
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
class Service
{
/**
* @var string
*/
public $label;
/**
* @var string
*/
public $price;
/**
* @param array $array
* @return Service
*/
public static function fromArray(array $array)
{
$service = new self;
$service->label = $array['label'];
$service->price = $array['price'];
return $service;
}
}
@@ -26,42 +26,43 @@ namespace EP\EpProducts\Domain\Serialization;
* This copyright notice MUST APPEAR in all copies of the script! * This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/ ***************************************************************/
class Pickup class Services
{ {
/** /**
* @var string * @var array
*/ */
public $city; protected static $categoryLabels = [
'BUS' => 'Anreise',
/** 'VPF' => 'Verpflegung',
* @var string 'SPA' => 'Skipass',
*/ 'KUR' => 'Kurse',
public $street; 'VER' => 'Verleih',
'SON' => 'Sonstiges',
/** ];
* @var string
*/
public $time;
/**
* @var float
*/
public $price;
/** /**
* @param array $array * @param array $array
* @return Pickup * @return array
*/ */
public static function fromArray(array $array) public static function fromArray(array $array)
{ {
$pickup = new self; $services = [
'category' => [],
];
$pickup->city = $array['city']; foreach ($array as $categoryId => $categoryData)
$pickup->street = $array['street']; {
$pickup->time = $array['time']; $category = [
$pickup->price = $array['price']; 'service' => [],
'@label' => self::$categoryLabels[$categoryId],
];
foreach ($categoryData as $row)
{
$category['service'][] = $row;
}
$services['category'][] = $category;
}
return $pickup; return $services;
} }
} }
@@ -74,7 +74,7 @@ class ResellerService implements SingletonInterface
/** /**
* @param Product $product * @param Product $product
* @param Reseller $reseller * @param Reseller $reseller
* @return \EP\EpProducts\Domain\Serialization\Product * @return array
*/ */
public function preprocessSingle(Product $product, Reseller $reseller) public function preprocessSingle(Product $product, Reseller $reseller)
{ {
@@ -88,8 +88,8 @@ class ResellerService implements SingletonInterface
/** @var Hotel $hotel */ /** @var Hotel $hotel */
$hotelData = \EP\EpProducts\Domain\Serialization\Hotel::fromEntity($hotel); $hotelData = \EP\EpProducts\Domain\Serialization\Hotel::fromEntity($hotel);
$dates = $this->productRepository->getDatesForExport($product, $hotel); $dates = $this->productRepository->getDatesForExport($product, $hotel);
$hotelData->dates['date'] = $this->preprocessDates($dates, $paCode); $hotelData['dates']['date'] = $this->preprocessDates($dates, $paCode);
$data->hotels['hotel'][] = $hotelData; $data['hotels']['hotel'][] = $hotelData;
} }
return $data; return $data;
@@ -111,14 +111,14 @@ class ResellerService implements SingletonInterface
$data[$row['dateStart']] = $date; $data[$row['dateStart']] = $date;
} }
$date->bookingurl = BookingUrlUtility::generateResellerUrl([ $data[$row['dateStart']]['bookingurl'] = BookingUrlUtility::generateResellerUrl([
'bookingId' => $row['dateBusProId'], 'bookingId' => $row['dateBusProId'],
'hotelId' => $row['hotelBusProId'], 'hotelId' => $row['hotelBusProId'],
'dateEnd' => $row['dateEnd'], 'dateEnd' => $row['dateEnd'],
'paCode' => $paCode, 'paCode' => $paCode,
]); ]);
$date->rooms['room'][] = Room::fromArray($row); $data[$row['dateStart']]['rooms']['room'][] = Room::fromArray($row);
} }
return array_values($data); return array_values($data);