Skip to content
Snippets Groups Projects
RestaurantMapper.php 4.67 KiB
Newer Older
use App\Entity\Gallery;
use App\Entity\Kitchen;
use App\Entity\Restaurant;
use App\Entity\RestaurantType;
use App\Model\RestaurantFilterVariants;
use App\Model\RestaurantList;
use App\Model\RestaurantListingElement;
use App\Model\RestaurantType as RestaurantTypeModel;
use App\Model\File;
        Collection $restaurants,
        Collection $restaurantTypes,
        Collection $kitchens,
        int $page,
        int $limit,
        int $count
    ): RestaurantList {
        return new RestaurantList(
            new Pagination($page, ceil($count / $limit), $limit),
            new Collection(RestaurantListingElement::class, array_map(
                function (Restaurant $restaurant) {
                    return self::mapToListElement($restaurant);
                }, $restaurants->toArray())),
            new RestaurantFilterVariants(
                new Collection(
                    RestaurantTypeModel::class, array_map(
                        function (RestaurantType $restaurantType) {
                            return self::mapToRestaurantType($restaurantType);
                        }, $restaurantTypes->toArray()
                    )
                ),
                new Collection(
                    KitchenType::class, array_map(
                    function (Kitchen $kitchen) {
                        return self::mapToKitchenType($kitchen);
                    }, $kitchens->toArray()
    public static function mapToListElement(Restaurant $restaurant): RestaurantListingElement
    {
        return new RestaurantListingElement(
            $restaurant->getId(),
            $restaurant->getName(),
            $restaurant->getCode(),
            FileMapper::mapToFile($restaurant->getFile()),
    public static function mapToDetailElement(Restaurant $restaurant, Collection $gallery): RestaurantDetailElement
    {
        return new RestaurantDetailElement(
            $restaurant->getId(),
            $restaurant->getName(),
            $restaurant->getCode(),
            implode(',', $restaurant->getCoordinates()),
            $restaurant->getCheckPrice(),
            $restaurant->getCheckInfo(),
            new Collection(
                KitchenType::class, array_map(
                function (Kitchen $kitchen) {
                    return self::mapToKitchenType($kitchen);
                }, $restaurant->getKitchen()->toArray()),
            ),
            new Collection("string", $restaurant->getPhone()),
            new Collection("string", $restaurant->getEmail()),
            new Collection("string", $restaurant->getAddress()),
            self::mapToTag(
                new Collection(
                    Tags::class,
                    $restaurant->getTags()->toArray()
                )
            ),
            FileMapper::mapToFile($restaurant->getFile()),
            self::mapToGallery($gallery),
            $restaurant->getSeo()?->getTitle(),
            $restaurant->getSeo()?->getDescription(),
            $restaurant->getSeo()?->getKeywords()
    public static function mapToRestaurantType(RestaurantType $restaurantType): RestaurantTypeModel
    {
        return new RestaurantTypeModel(
            $restaurantType->getId(),
            $restaurantType->getName(),
        );
    }

    public static function mapToKitchenType(Kitchen $kitchen): KitchenType
    {
        return new KitchenType(
            $kitchen->getId(),
            $kitchen->getName()
        );
    }
    public static function mapToTag(Collection $tags): Collection
        return new Collection(Tag::class, array_map(
            function (Tags $tag) {
                return new Tag(
                    $tag->getName(),
                    new Collection("string", $tag->getList())
                );
            }, $tags->toArray())
        );
    public static function mapToGallery(Collection $gallery): Collection
        return new Collection(File::class, array_map(
            function (Gallery $galleryOne) {
                return FileMapper::mapToFile($galleryOne->getFile());
            }, $gallery->toArray())
        );