<?php namespace App\Mapper; use App\Entity\Address; use App\Entity\Email; use App\Entity\Kitchen; use App\Entity\Phone; use App\Entity\Restaurant; use App\Entity\RestaurantType; use App\Entity\Tags; use App\Model\File; use App\Model\KitchenType; use App\Model\RestaurantDetailElement; use App\Model\RestaurantListingElement; use App\Model\RestaurantType as RestaurantTypeModel; use App\Model\Tag; use Ramsey\Collection\Collection; class RestaurantMapper { public static function mapToListElement(Restaurant $restaurant): RestaurantListingElement { return new RestaurantListingElement( $restaurant->getId(), $restaurant->getName(), $restaurant->getCode(), new RestaurantTypeModel( $restaurant->getTypeId()->getId(), $restaurant->getTypeId()->getName(), $restaurant->getTypeId()->getCode() ), $restaurant->getCheckInfo(), new File( 1, "name", "description", 10, "jpg", $restaurant->getPreviewImage() ), $restaurant->getSite() ); } public static function mapToDetailElement(Restaurant $restaurant): RestaurantDetailElement { $file = new File( 1, "name", "description", 10, "jpg", $restaurant->getPreviewImage() ); return new RestaurantDetailElement( $restaurant->getId(), $restaurant->getName(), $restaurant->getCode(), implode(',', $restaurant->getCoordinates()), //self::mapToRestaurantType($restaurant->getTypeId()), $restaurant->getCheckPrice(), $restaurant->getCheckInfo(), new Collection( KitchenType::class, array_map( function (Kitchen $kitchen) { return self::mapToKitchenType($kitchen); }, $restaurant->getKitchen()->toArray()), ), new Collection(Phone::class, $restaurant->getPhone()->toArray()), new Collection(Email::class, $restaurant->getEmail()->toArray()), new Collection(Address::class, $restaurant->getAddress()->toArray()), new Collection(Tag::class, array_map( function (Tags $tag) { return new Tag( "группа тегов 1", new Collection($tag->getName()), ); }, $restaurant->getTags()->toArray() )), $restaurant->getSite(), $file, new Collection(File::class, [$file]), "Отель Арктика", "otel arktika", "otel arktika" ); } public static function mapToRestaurantType(RestaurantType $restaurantType): RestaurantTypeModel { return new RestaurantTypeModel( $restaurantType->getId(), $restaurantType->getName(), $restaurantType->getCode() ); } public static function mapToKitchenType(Kitchen $kitchen): KitchenType { return new KitchenType( $kitchen->getId(), $kitchen->getName() ); } }