From 0a6f8030f99f00bfff238cb839d4896764dafb8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Fromme?= Date: Fri, 10 Aug 2018 12:47:17 +0200 Subject: [PATCH] Refactor product export to include ids and service categories --- composer.json | 4 +- composer.lock | 7 +- .../Domain/Repository/ProductRepository.php | 4 +- .../Classes/Domain/Serialization/City.php | 44 +++------ .../Classes/Domain/Serialization/Date.php | 90 ++++--------------- .../Classes/Domain/Serialization/Hotel.php | 57 +++--------- .../Classes/Domain/Serialization/Product.php | 90 +++++-------------- .../Classes/Domain/Serialization/Region.php | 73 ++++----------- .../Classes/Domain/Serialization/Room.php | 55 +++--------- .../Classes/Domain/Serialization/Service.php | 55 ------------ .../{Pickup.php => Services.php} | 53 +++++------ .../Classes/Service/ResellerService.php | 10 +-- 12 files changed, 127 insertions(+), 415 deletions(-) delete mode 100644 web/typo3conf/ext/ep_products/Classes/Domain/Serialization/Service.php rename web/typo3conf/ext/ep_products/Classes/Domain/Serialization/{Pickup.php => Services.php} (60%) diff --git a/composer.json b/composer.json index 10b8988c..fcfe37f8 100644 --- a/composer.json +++ b/composer.json @@ -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": [ diff --git a/composer.lock b/composer.lock index 1258560c..f986c0f2 100644 --- a/composer.lock +++ b/composer.lock @@ -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": { diff --git a/web/typo3conf/ext/ep_products/Classes/Domain/Repository/ProductRepository.php b/web/typo3conf/ext/ep_products/Classes/Domain/Repository/ProductRepository.php index 25dbbef6..3eb5ead1 100644 --- a/web/typo3conf/ext/ep_products/Classes/Domain/Repository/ProductRepository.php +++ b/web/typo3conf/ext/ep_products/Classes/Domain/Repository/ProductRepository.php @@ -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' ) diff --git a/web/typo3conf/ext/ep_products/Classes/Domain/Serialization/City.php b/web/typo3conf/ext/ep_products/Classes/Domain/Serialization/City.php index 36569d1b..b75f87d3 100644 --- a/web/typo3conf/ext/ep_products/Classes/Domain/Serialization/City.php +++ b/web/typo3conf/ext/ep_products/Classes/Domain/Serialization/City.php @@ -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()); diff --git a/web/typo3conf/ext/ep_products/Classes/Domain/Serialization/Date.php b/web/typo3conf/ext/ep_products/Classes/Domain/Serialization/Date.php index 01cfc7dd..e29fb96c 100644 --- a/web/typo3conf/ext/ep_products/Classes/Domain/Serialization/Date.php +++ b/web/typo3conf/ext/ep_products/Classes/Domain/Serialization/Date.php @@ -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; diff --git a/web/typo3conf/ext/ep_products/Classes/Domain/Serialization/Hotel.php b/web/typo3conf/ext/ep_products/Classes/Domain/Serialization/Hotel.php index 037e2305..0fee39f2 100644 --- a/web/typo3conf/ext/ep_products/Classes/Domain/Serialization/Hotel.php +++ b/web/typo3conf/ext/ep_products/Classes/Domain/Serialization/Hotel.php @@ -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; } diff --git a/web/typo3conf/ext/ep_products/Classes/Domain/Serialization/Product.php b/web/typo3conf/ext/ep_products/Classes/Domain/Serialization/Product.php index 0715f069..9a9f1cc8 100644 --- a/web/typo3conf/ext/ep_products/Classes/Domain/Serialization/Product.php +++ b/web/typo3conf/ext/ep_products/Classes/Domain/Serialization/Product.php @@ -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->name = preg_replace('/[\r\n\s]+/', ' ', $entity->getName()); + $product = [ + 'concept' => [], + 'facts' => [], + 'hotels' => [], + 'images' => [], + ]; - $product->facts['fact'] = array_map(function ($fact) { + $product['@id'] = $entity->getBusProId(); + $product['@code'] = $entity->getCode(); + $product['name'] = preg_replace('/[\r\n\s]+/', ' ', $entity->getName()); + + $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; } diff --git a/web/typo3conf/ext/ep_products/Classes/Domain/Serialization/Region.php b/web/typo3conf/ext/ep_products/Classes/Domain/Serialization/Region.php index 4adca799..312b74c0 100644 --- a/web/typo3conf/ext/ep_products/Classes/Domain/Serialization/Region.php +++ b/web/typo3conf/ext/ep_products/Classes/Domain/Serialization/Region.php @@ -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()); diff --git a/web/typo3conf/ext/ep_products/Classes/Domain/Serialization/Room.php b/web/typo3conf/ext/ep_products/Classes/Domain/Serialization/Room.php index 02a9592d..44627403 100644 --- a/web/typo3conf/ext/ep_products/Classes/Domain/Serialization/Room.php +++ b/web/typo3conf/ext/ep_products/Classes/Domain/Serialization/Room.php @@ -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; } diff --git a/web/typo3conf/ext/ep_products/Classes/Domain/Serialization/Service.php b/web/typo3conf/ext/ep_products/Classes/Domain/Serialization/Service.php deleted file mode 100644 index 3ad6077c..00000000 --- a/web/typo3conf/ext/ep_products/Classes/Domain/Serialization/Service.php +++ /dev/null @@ -1,55 +0,0 @@ -, 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; - } -} diff --git a/web/typo3conf/ext/ep_products/Classes/Domain/Serialization/Pickup.php b/web/typo3conf/ext/ep_products/Classes/Domain/Serialization/Services.php similarity index 60% rename from web/typo3conf/ext/ep_products/Classes/Domain/Serialization/Pickup.php rename to web/typo3conf/ext/ep_products/Classes/Domain/Serialization/Services.php index cd4c0413..aca0d325 100644 --- a/web/typo3conf/ext/ep_products/Classes/Domain/Serialization/Pickup.php +++ b/web/typo3conf/ext/ep_products/Classes/Domain/Serialization/Services.php @@ -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; } } diff --git a/web/typo3conf/ext/ep_products/Classes/Service/ResellerService.php b/web/typo3conf/ext/ep_products/Classes/Service/ResellerService.php index 0c867da1..636559b6 100644 --- a/web/typo3conf/ext/ep_products/Classes/Service/ResellerService.php +++ b/web/typo3conf/ext/ep_products/Classes/Service/ResellerService.php @@ -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);