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",
"yohang/calendr": "^2.1",
"wyrihaximus/html-compress": "^1.4",
"symfony/serializer": "3.3.*",
"symfony/property-access": "^3.4",
"symfony/options-resolver": "^3.4"
"symfony/options-resolver": "^3.4",
"symfony/serializer": "^3.3"
},
"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",
"This file is @generated automatically"
],
"content-hash": "24a1dae8a5e81d4d36f7e5988eaace7a",
"content-hash": "f02741f6bee387f8f2b8ec67b91ef940",
"packages": [
{
"name": "cogpowered/finediff",
@@ -2262,7 +2262,7 @@
},
{
"name": "symfony/serializer",
"version": "v3.3.17",
"version": "v3.3.18",
"source": {
"type": "git",
"url": "https://github.com/symfony/serializer.git",
@@ -4675,7 +4675,8 @@
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
"php": "^5.6"
"php": "^5.6",
"ext-json": "*"
},
"platform-dev": [],
"platform-overrides": {
@@ -253,12 +253,12 @@ class ProductRepository extends AbstractRepository
$query = $qb
->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.nights dateNights', 'date.bus_included dateBusIncluded', 'date.services_included dateServicesIncluded',
'date.services_general dateServicesGeneral', 'date.skipass_included dateSkipassIncluded',
'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.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!
***************************************************************/
use EP\EpProducts\Domain\Model\Fact;
use EP\EpProducts\Utility\SerializationUtility;
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
* @return City
* @return array
*/
public static function fromEntity(\EP\EpProducts\Domain\Model\City $entity)
{
$city = new self;
$city = [];
$city->name = $entity->getName();
$city->description = SerializationUtility::sanitizeText($entity->getDescription());
$city->party = SerializationUtility::sanitizeText($entity->getParty());
$city->leisure = SerializationUtility::sanitizeText($entity->getLeisure());
$city->facts['fact'] = array_map(function ($fact) {
$city['@id'] = $entity->getUid();
$city['name'] = $entity->getName();
$city['description'] = SerializationUtility::sanitizeText($entity->getDescription());
$city['party'] = SerializationUtility::sanitizeText($entity->getParty());
$city['leisure'] = SerializationUtility::sanitizeText($entity->getLeisure());
$city['facts'] = [];
$city['facts']['fact'] = array_map(function ($fact) {
/** @var Fact $fact */
return htmlspecialchars($fact->getName());
}, $entity->getFacts()->toArray());
@@ -29,88 +29,32 @@ namespace EP\EpProducts\Domain\Serialization;
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
* @return Date
* @return array
*/
public static function fromArray(array $array)
{
$date = new self;
$date = [
'servicesincluded' => [],
'servicesoptional' => [],
'rooms' => [],
];
$date->from = $array['dateStart'];
$date->to = $array['dateEnd'];
$date->minprice = $array['dateMinPrice'];
$date->nights = $array['dateNights'];
$date->skipassincluded = $array['dateSkipassIncluded'];
$date->busincluded = $array['dateBusIncluded'];
$date->servicesincluded['service'] = unserialize($array['dateServicesIncluded']);
$date['@id'] = $array['dateBusProId'];
$date['from'] = $array['dateStart'];
$date['to'] = $array['dateEnd'];
$date['minprice'] = $array['dateMinPrice'];
$date['nights'] = $array['dateNights'];
$date['skipassincluded'] = $array['dateSkipassIncluded'];
$date['busincluded'] = $array['dateBusIncluded'];
$date['servicesincluded']['service'] = unserialize($array['dateServicesIncluded']);
$servicesGeneral = unserialize($array['dateServicesGeneral']);
foreach ($servicesGeneral as $category)
{
foreach ($category as $row)
{
$date->servicesoptional['service'][] = Service::fromArray($row);
}
}
$date['servicesoptional'] = Services::fromArray($servicesGeneral);
$date['pickups'] = [];
foreach (unserialize($array['pickups']) as $row)
{
$date->pickups['pickup'][] = Pickup::fromArray($row);
$date['pickups']['pickup'][] = $row;
}
return $date;
@@ -30,56 +30,25 @@ use EP\EpProducts\Utility\SerializationUtility;
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
* @return Hotel
* @return array
*/
public static function fromEntity(\EP\EpProducts\Domain\Model\Hotel $entity)
{
$hotel = new self;
$hotel = [
'dates' => [],
'images' => [],
];
$hotel->name = $entity->getName();
$hotel->category = \EP\EpProducts\Domain\Model\Hotel::$categoryLabels[$entity->getCategory()];
$hotel->type = \EP\EpProducts\Domain\Model\Hotel::$typeLabels[$entity->getType()];
$hotel->description = SerializationUtility::sanitizeText($entity->getDescription());
$hotel->features = SerializationUtility::sanitizeText($entity->getFeatures());
$hotel->images['image'] = SerializationUtility::preprocessImages($entity->getResellerImages());
$hotel['@id'] = $entity->getUid();
$hotel['@code'] = $entity->getCode();
$hotel['name'] = $entity->getName();
$hotel['category'] = \EP\EpProducts\Domain\Model\Hotel::$categoryLabels[$entity->getCategory()];
$hotel['type'] = \EP\EpProducts\Domain\Model\Hotel::$typeLabels[$entity->getType()];
$hotel['description'] = SerializationUtility::sanitizeText($entity->getDescription());
$hotel['features'] = SerializationUtility::sanitizeText($entity->getFeatures());
$hotel['images']['image'] = SerializationUtility::preprocessImages($entity->getResellerImages());
return $hotel;
}
@@ -32,86 +32,38 @@ use EP\EpProducts\Utility\SerializationUtility;
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
* @return Product
* @return array
*/
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 */
return htmlspecialchars($fact->getName());
}, $entity->getFacts()->toArray());
$product->skipass = SerializationUtility::sanitizeText($entity->getSkiPassDescription());
$product->concept['name'] = $entity->getConcept()->getName();
$product->concept['description'] = SerializationUtility::sanitizeText($entity->getConcept()->getDescription());
$product->board = SerializationUtility::sanitizeText($entity->getBoardDescription());
$product->programme = SerializationUtility::sanitizeText($entity->getProgrammeDescription());
$product->images['image'] = SerializationUtility::preprocessImages($entity->getResellerImages());
$product->video = $entity->getVideo();
$product['skipass'] = SerializationUtility::sanitizeText($entity->getSkiPassDescription());
$product['concept']['name'] = $entity->getConcept()->getName();
$product['concept']['description'] = SerializationUtility::sanitizeText($entity->getConcept()->getDescription());
$product['board'] = SerializationUtility::sanitizeText($entity->getBoardDescription());
$product['programme'] = SerializationUtility::sanitizeText($entity->getProgrammeDescription());
$product['images']['image'] = SerializationUtility::preprocessImages($entity->getResellerImages());
$product['video'] = $entity->getVideo();
$product->region = Region::fromEntity($entity->getRegion());
$product->city = City::fromEntity($entity->getCity());
$product['region'] = Region::fromEntity($entity->getRegion());
$product['city'] = City::fromEntity($entity->getCity());
return $product;
}
@@ -27,74 +27,31 @@ namespace EP\EpProducts\Domain\Serialization;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use EP\EpProducts\Domain\Model\Fact;
use EP\EpProducts\Utility\SerializationUtility;
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
* @return Region
* @return array
*/
public static function fromEntity(\EP\EpProducts\Domain\Model\Region $entity)
{
$region = new self;
$region = [];
$region->name = $entity->getName();
$region->description = SerializationUtility::sanitizeText($entity->getSkiArea());
$region->descriptionExtended = SerializationUtility::sanitizeText($entity->getSkiAreaExtended());
$region->piste = $entity->getLength();
$region->height = $entity->getHeight();
$region->lifts = $entity->getLifts();
$region->skipass = SerializationUtility::sanitizeText($entity->getSkiPass());
$region->news = SerializationUtility::sanitizeText($entity->getNews());
$region->facts['fact'] = array_map(function ($fact) {
$region['@id'] = $entity->getUid();
$region['name'] = $entity->getName();
$region['description'] = SerializationUtility::sanitizeText($entity->getSkiArea());
$region['descriptionExtended'] = SerializationUtility::sanitizeText($entity->getSkiAreaExtended());
$region['piste'] = $entity->getLength();
$region['height'] = $entity->getHeight();
$region['lifts'] = $entity->getLifts();
$region['skipass'] = SerializationUtility::sanitizeText($entity->getSkiPass());
$region['news'] = SerializationUtility::sanitizeText($entity->getNews());
$region['facts'] = [];
$region['facts']['fact'] = array_map(function ($fact) {
/** @var Fact $fact */
return htmlspecialchars($fact->getName());
}, $entity->getFacts()->toArray());
@@ -28,59 +28,24 @@ namespace EP\EpProducts\Domain\Serialization;
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
* @return Room
* @return array
*/
public static function fromArray(array $array)
{
$room = new self;
$room = [];
$room->name = $array['roomName'];
$room->price = $array['roomPrice'];
$room->busprice = $array['busPrice'];
$room->nights = $array['roomNights'];
$room->available = $array['roomAvailable'];
$room['@id'] = $array['roomBusProId'];
$room['@code'] = $array['roomCode'];
$room['name'] = $array['roomName'];
$room['price'] = $array['roomPrice'];
$room['busprice'] = $array['busPrice'];
$room['nights'] = $array['roomNights'];
$room['available'] = $array['roomAvailable'];
$servicesOptional = unserialize($array['roomOptionalServices']);
foreach ($servicesOptional as $category)
{
foreach ($category as $row)
{
$room->servicesoptional['service'][] = Service::fromArray($row);
}
}
$room['servicesoptional'] = Services::fromArray($servicesOptional);
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!
***************************************************************/
class Pickup
class Services
{
/**
* @var string
* @var array
*/
public $city;
/**
* @var string
*/
public $street;
/**
* @var string
*/
public $time;
/**
* @var float
*/
public $price;
protected static $categoryLabels = [
'BUS' => 'Anreise',
'VPF' => 'Verpflegung',
'SPA' => 'Skipass',
'KUR' => 'Kurse',
'VER' => 'Verleih',
'SON' => 'Sonstiges',
];
/**
* @param array $array
* @return Pickup
* @return array
*/
public static function fromArray(array $array)
{
$pickup = new self;
$services = [
'category' => [],
];
$pickup->city = $array['city'];
$pickup->street = $array['street'];
$pickup->time = $array['time'];
$pickup->price = $array['price'];
foreach ($array as $categoryId => $categoryData)
{
$category = [
'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 Reseller $reseller
* @return \EP\EpProducts\Domain\Serialization\Product
* @return array
*/
public function preprocessSingle(Product $product, Reseller $reseller)
{
@@ -88,8 +88,8 @@ class ResellerService implements SingletonInterface
/** @var Hotel $hotel */
$hotelData = \EP\EpProducts\Domain\Serialization\Hotel::fromEntity($hotel);
$dates = $this->productRepository->getDatesForExport($product, $hotel);
$hotelData->dates['date'] = $this->preprocessDates($dates, $paCode);
$data->hotels['hotel'][] = $hotelData;
$hotelData['dates']['date'] = $this->preprocessDates($dates, $paCode);
$data['hotels']['hotel'][] = $hotelData;
}
return $data;
@@ -111,14 +111,14 @@ class ResellerService implements SingletonInterface
$data[$row['dateStart']] = $date;
}
$date->bookingurl = BookingUrlUtility::generateResellerUrl([
$data[$row['dateStart']]['bookingurl'] = BookingUrlUtility::generateResellerUrl([
'bookingId' => $row['dateBusProId'],
'hotelId' => $row['hotelBusProId'],
'dateEnd' => $row['dateEnd'],
'paCode' => $paCode,
]);
$date->rooms['room'][] = Room::fromArray($row);
$data[$row['dateStart']]['rooms']['room'][] = Room::fromArray($row);
}
return array_values($data);