Newer
Older
<?php
namespace App\Mapper;
use App\Entity\Kitchen;
use App\Entity\Restaurant;
use App\Entity\RestaurantType;
use App\Model\Pagination;
use App\Model\RestaurantDetailElement;
use App\Model\RestaurantFilterVariants;
use App\Model\RestaurantList;
use App\Model\RestaurantListingElement;
use App\Model\RestaurantType as RestaurantTypeModel;
use Ramsey\Collection\Collection;
public static function mapToRestaurantList(
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(),
self::mapToRestaurantType($restaurant->getTypeId()),
$restaurant->getSite()
);
}
public static function mapToDetailElement(Restaurant $restaurant, Collection $gallery): RestaurantDetailElement
{
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("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())
);