<?php
namespace App\Controller;
use App\Model\DataObject\User;
use App\Service\HourBooked;
use App\Service\PriceCalculator;
use Carbon\Carbon;
use Doctrine\DBAL\Query\QueryBuilder;
use phpDocumentor\Reflection\DocBlock\Tags\Var_;
use Pimcore\Controller\FrontendController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Contracts\Translation\TranslatorInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Routing\Annotation\Route;
use Pimcore\Model\WebsiteSetting;
use Pimcore\Model\DataObject;
use Pimcore\Model\DataObject\Booking;
use Pimcore\Model\DataObject\EquipmentCategory;
use Pimcore\Model\DataObject\Order;
use Pimcore\Model\DataObject\Place;
use Pimcore\Model\DataObject\Studio;
use Pimcore\Model\Document\PageSnippet;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use ValueError;
use Symfony\Component\Security\Core\Security as FrontSecurity;
class StudioController extends FrontendController
{
/**
* @Template
* @param Request $request
* @route("/{_locale}/studios", name="studioList",methods={"GET", "POST"})
* @return array
*/
public function listAction(Request $request, FrontSecurity $security)
{
if($request->get("reset") && $request->get("reset") == 1){
$session = $request->getSession();
$session->set("searchparams", []);
}
$studiosCateg = new DataObject\StudioSuperCategory\Listing();
$studiosCateg->setOrderKey('order');
$studiosCateg->setOrder('asc');
$studiosCateg->load();
$studios = new DataObject\Studio\Listing();
//$studios->setOrderKey('');
//$studios->setKey('');
$studios->load();
$locations = new Place\Listing();
$locations->load();
$orders = [];
$securityUser = $security->getUser();
if ($securityUser) {
$user = User::getByUsername($securityUser->getUserIdentifier())->load()[0];
if($user){
if($user->getStatus() == "rejected"){
return $this->redirectToRoute("suspendedRoute");
}
$orders = new Order\Listing();
$orders->setCondition("linkedUser__id = ".$user->getId()." AND (status like 'new')");
$orders->load();
}
}
$displayCalendar = 0;
return [
'studios' => $studios,
'studioCategories' => $studiosCateg,
'locations' => $locations,
'orders' => $orders,
'displayCalendar' => $displayCalendar,
'detailstudio' => 0,
'language' => $request->getLocale()
];
}
/**
* @route("/{_locale}/api/studios", name="studiosapi", methods={"GET"})
*/
public function getStudioListAction(Request $request)
{
$session = $request->getSession();
$allParams = $request->query->all();
$session->set("searchparams", $allParams);
$checkDate = Carbon::parse($allParams['sDate']);
$checkDate->setHour(intval($allParams['sHour']));
$checkNow = Carbon::now()->subHour();
if($checkDate->timestamp >= $checkNow->timestamp){
$availabilities = true;
$studioList = new Studio\Listing();
$studioList->onCreateQueryBuilder(function (QueryBuilder $queryBuilder) use ($allParams) {
$queryBuilder->andWhere("(maintenance IS NULL OR maintenance = 0)");
$originalTable = $queryBuilder->getQueryParts()['from'][0]['table'];
$tabStudCats = array();
try {
if (array_key_exists('studTypes', $allParams)) {
if ($allParams['studTypes'] != '') {
$tabStudCats = explode(",", $allParams['studTypes']);
}
}
} catch (ValueError $e) {
}
if (array_key_exists('souscategories', $allParams) && $allParams['souscategories']) {
$studCatSQL = '(categorie__id = ' . $allParams['souscategories'] . ')';
$queryBuilder->andWhere($studCatSQL);
}else{
if (count($tabStudCats)) {
$studCatSQL = '';
foreach ($tabStudCats as $key => $studcat) {
$supCat = DataObject\StudioSuperCategory::getById($studcat);
if($supCat){
if ($key != 0) {
$studCatSQL .= ' OR ';
}
if(count($supCat->getCategories()) > 1){
$studCatSQL .= "(";
foreach($supCat->getCategories() as $key2 => $sCateg){
if ($key2 != 0) {
$studCatSQL .= ' OR ';
}
$sCategId = $sCateg->getId();
$studCatSQL .= '(categorie__id = ' . $sCategId . ')';
}
$studCatSQL .= ")";
}else{
$sCategId = $supCat->getCategories()[0]->getId();
$studCatSQL .= '(categorie__id = ' . $sCategId . ')';
}
}
}
if($studCatSQL){
$queryBuilder->andWhere($studCatSQL);
}
}
}
if (array_key_exists('sDate', $allParams)) {
$startDate = Carbon::parse($allParams['sDate']);
$endDate = Carbon::parse($allParams['sDate']);
$startDate->setHour(intval($allParams['sHour']));
$endDate->setHour(intval($allParams['sHour']));
$endDate->addHours(intval($allParams['sDuration']));
$sqlOrder = "SELECT count(booking.o_id)
FROM object_" . Booking::classId() . " booking
JOIN object_" . Order::classId() . " ord ON ord.o_id = booking.order__id
WHERE booking.bookedStudio__id = " . $originalTable . ".o_id AND ord.status NOT IN ('abandonned', 'canceled', 'temporary')
AND ((booking.bookedStart BETWEEN " . $startDate->timestamp+1 . " AND " . $endDate->timestamp-1 . "
OR booking.bookedEnd BETWEEN " . $startDate->timestamp+1 . " AND " . $endDate->timestamp-1 . ") OR (booking.bookedStart <= " . $startDate->timestamp . " AND booking.bookedEnd >= " . $endDate->timestamp . "))";
//@TODO : Pour studios ayant des réservations pour l'heure dispo choisie : $queryBuilder->andWhere("(" . $sqlOrder . ") > 0");
// Recopier le reste
// Ajouter le paramètre $tabStud['availability'] = $infos;
// Array merger en resetant les ID
$queryBuilder->andWhere("(" . $sqlOrder . ") = 0");
if($startDate->day != $endDate->day){
$endDateQuery = 24+$endDate->hour;
}else{
$endDateQuery = $endDate->hour;
}
$hoursWhere = "(".$startDate->hour . " BETWEEN " . $originalTable . ".openingHour AND " . $originalTable . ".closingHour";
$hoursWhere .= " AND ".$endDateQuery . " BETWEEN " . $originalTable . ".openingHour AND " . $originalTable . ".closingHour)";
$hoursWhere .= " OR (".$originalTable . ".openingHour = 0 AND " . $originalTable . ".closingHour = 24)";
$queryBuilder->andWhere($hoursWhere);
/*if ($startDate->day != $endDate->day) {
$queryBuilder->andWhere($originalTable . ".openingHour = 0");
$queryBuilder->andWhere($originalTable . ".closingHour = 23");
}*/
$sqlClosedHours = "SELECT count(clHour.o_id) FROM object_collection_closedHours_" . Studio::classId() . " clHour"
. " WHERE " . $originalTable . ".o_id = clHour.o_id"
. " AND (" . $startDate->timestamp . " BETWEEN clHour.closedStart AND clHour.closedEnd"
. " OR " . $endDate->timestamp . " BETWEEN clHour.closedStart AND clHour.closedEnd"
. " OR clHour.closedStart BETWEEN " . $startDate->timestamp . " AND " . $endDate->timestamp
. " OR clHour.closedEnd BETWEEN " . $startDate->timestamp . " AND " . $endDate->timestamp . ")";
$queryBuilder->andWhere("(" . $sqlClosedHours . ") = 0");
$queryBuilder->andWhere("place__id = " . $allParams['sLocation']);
}
});
$studioList->setOrderKey("OrderPlace");
$studioList->setOrder("ASC");
//Limite de studios
//$studioList->setLimit(2);
$studioList->setLocale($request->getLocale());
$studioList->load();
$tabStudios = array();
foreach ($studioList as $studio) {
$tabStud = array();
$tabStud['id'] = $studio->getId();
//$tabStud['detailURL'] = $this->generateUrl("studioDetail", ["slug" => $studio->getSlug()], UrlGeneratorInterface::ABSOLUTE_URL);
$gear = "";
if ($studio->getEquipments()) {
foreach ($studio->getEquipments() as $equipment) {
if($equipment->getEquipment()):
$gear .= $equipment->getQty() . " x " . $equipment->getEquipment()->getName() . "<br/>";
endif;
}
}
$tabStud['gear'] = $gear;
$tabStud['infos'] = $studio->getInfos();
$tabStud['shortInfos'] = $studio->getShortInfos();
$tabStud['maxPersons'] = $studio->getMaxPersons();
$tabStud['title'] = $studio->getTitle();
$tabStud['titleTranslated'] = $studio->getTitleTranslated();
$tabStud['image'] = $studio->getImage()->getThumbnail("studio-thumb")->getHtml(['imgAttributes' => ['uk-cover' => null]]);
$tabStud['defaultPrice'] = $studio->getDefaultPrice()->getAmount() * 100;
$tabStud['availability'] = 1;
$tabStud['language'] = $request->getLocale();
//CSS
$tabStud['cssFontSizeTitle'] = $studio->getCssFontSizeTitle();
$tabStud['cssFontSizeTitleDetail'] = $studio->getCssFontSizeTitleDetail();
// Ajout des promoLeft et right en haut du studio
$pricingRule = $studio->getCategorie()->getPricingGrid();
$tabStud['promoLeft'] = $pricingRule->getPromoLeft();
$tabStud['promoRight'] = $pricingRule->getPromoRight();
$promoLeftSize = "apk-f-13";
if($pricingRule->getPromoLeftSize()) {
$promoLeftSize = $pricingRule->getPromoLeftSize();
}
$tabStud['promoLeftSize'] = $promoLeftSize;
$promoRightSize = "apk-f-13";
if($pricingRule->getPromoRightSize()) {
$promoRightSize = $pricingRule->getPromoRightSize();
}
$tabStud['promoRightSize'] = $promoRightSize;
$tabStud['placeLock'] = $studio->getPlace()->getLockReservation() ? 1 : 0;
$tabStud['lockText'] = $studio->getPlace()->getLockText($request->getLocale());
array_push($tabStudios, $tabStud);
}
}else{
$tabStudios = array();
}
if(!$tabStudios){
// Ajouter le paramètre $tabStud['availability'] = $infos;
// Array merger en resetant les ID
//////// AFFICHAGE DES STUDIOS NON DISPONIBLES /////////
$availabilities = false;
$studioListUnavailable = new Studio\Listing();
$studioListUnavailable->onCreateQueryBuilder(function (QueryBuilder $queryBuilder) use ($allParams) {
$queryBuilder->andWhere("(maintenance IS NULL OR maintenance = 0)");
$originalTable = $queryBuilder->getQueryParts()['from'][0]['table'];
$tabStudCats = array();
try {
if (array_key_exists('studTypes', $allParams)) {
if ($allParams['studTypes'] != '') {
$tabStudCats = explode(",", $allParams['studTypes']);
}
}
} catch (ValueError $e) {
}
if (array_key_exists('souscategories', $allParams) && $allParams['souscategories']) {
$studCatSQL = '(categorie__id = ' . $allParams['souscategories'] . ')';
$queryBuilder->andWhere($studCatSQL);
}else{
if (count($tabStudCats)) {
$studCatSQL = '';
foreach ($tabStudCats as $key => $studcat) {
$supCat = DataObject\StudioSuperCategory::getById($studcat);
if ($key != 0) {
$studCatSQL .= ' OR ';
}
if(count($supCat->getCategories()) > 1){
$studCatSQL .= "(";
foreach($supCat->getCategories() as $key2 => $sCateg){
if ($key2 != 0) {
$studCatSQL .= ' OR ';
}
$sCategId = $sCateg->getId();
$studCatSQL .= '(categorie__id = ' . $sCategId . ')';
}
$studCatSQL .= ")";
}else{
$sCategId = $supCat->getCategories()[0]->getId();
$studCatSQL .= '(categorie__id = ' . $sCategId . ')';
}
}
$queryBuilder->andWhere($studCatSQL);
}
}
if (array_key_exists('sDate', $allParams)) {
$startDate = Carbon::parse($allParams['sDate']);
$endDate = Carbon::parse($allParams['sDate']);
$startDate->setHour(intval($allParams['sHour']));
$endDate->setHour(intval($allParams['sHour']));
$endDate->addHours(intval($allParams['sDuration']));
$sqlOrder = "SELECT count(booking.o_id)
FROM object_" . Booking::classId() . " booking
JOIN object_" . Order::classId() . " ord ON ord.o_id = booking.order__id
WHERE booking.bookedStudio__id = " . $originalTable . ".o_id AND ord.status NOT IN ('abandonned', 'canceled', 'temporary')
AND ((booking.bookedStart NOT BETWEEN " . $startDate->timestamp+1 . " AND " . $endDate->timestamp-1 . "
OR booking.bookedEnd NOT BETWEEN " . $startDate->timestamp+1 . " AND " . $endDate->timestamp-1 . ") OR (booking.bookedStart <= " . $startDate->timestamp . " AND booking.bookedEnd >= " . $endDate->timestamp . "))";
$open = $startDate->hour . " NOT BETWEEN " . $originalTable . ".openingHour AND " . $originalTable . ".closingHour";
$close = $endDate->hour . " NOT BETWEEN " . $originalTable . ".openingHour AND " . $originalTable . ".closingHour";
$sqlClosedHours = "SELECT count(clHour.o_id) FROM object_collection_closedHours_" . Studio::classId() . " clHour"
. " WHERE " . $originalTable . ".o_id = clHour.o_id"
. " AND (" . $startDate->timestamp . " NOT BETWEEN clHour.closedStart AND clHour.closedEnd"
. " OR " . $endDate->timestamp . " NOT BETWEEN clHour.closedStart AND clHour.closedEnd"
. " OR clHour.closedStart NOT BETWEEN " . $startDate->timestamp . " AND " . $endDate->timestamp
. " OR clHour.closedEnd NOT BETWEEN " . $startDate->timestamp . " AND " . $endDate->timestamp . ")";
$queryBuilder->andWhere("(($sqlOrder) > 0) OR ($open OR $close) OR (($sqlClosedHours) > 0)");
$queryBuilder->andWhere("place__id = " . $allParams['sLocation']);
}
});
$studioListUnavailable->setOrderKey("OrderPlace");
$studioListUnavailable->setOrder("ASC");
$studioListUnavailable->setLocale($request->getLocale());
$studioListUnavailable = $studioListUnavailable->load();
//On ne réinitialise pas l'array
//$tabStudios = array();
foreach ($studioListUnavailable as $studio) {
$tabStud = array();
$tabStud['id'] = $studio->getId();
//$tabStud['detailURL'] = $this->generateUrl("studioDetail", ["slug" => $studio->getSlug()], UrlGeneratorInterface::ABSOLUTE_URL);
$gear = "";
if ($studio->getEquipments()) {
foreach ($studio->getEquipments() as $equipment) {
if($equipment->getEquipment()):
$gear .= $equipment->getQty() . " x " . $equipment->getEquipment()->getName() . "<br/>";
endif;
}
}
$tabStud['gear'] = $gear;
$tabStud['infos'] = $studio->getInfos();
$tabStud['shortInfos'] = $studio->getShortInfos();
$tabStud['maxPersons'] = $studio->getMaxPersons();
$tabStud['title'] = $studio->getTitle();
$tabStud['titleTranslated'] = $studio->getTitleTranslated();
$tabStud['image'] = $studio->getImage()->getThumbnail("studio-thumb")->getHtml(['imgAttributes' => ['uk-cover' => null]]);
$tabStud['defaultPrice'] = $studio->getDefaultPrice()->getAmount() * 100;
$tabStud['availability'] = 0;
$tabStud['language'] = $request->getLocale();
//CSS
$tabStud['cssFontSizeTitle'] = $studio->getCssFontSizeTitle();
$tabStud['cssFontSizeTitleDetail'] = $studio->getCssFontSizeTitleDetail();
// Ajout des promoLeft et right en haut du studio
$pricingRule = $studio->getCategorie()->getPricingGrid();
$tabStud['promoLeft'] = $pricingRule->getPromoLeft();
$tabStud['promoRight'] = $pricingRule->getPromoRight();
$promoLeftSize = "apk-f-13";
if($pricingRule->getPromoLeftSize()) {
$promoLeftSize = $pricingRule->getPromoLeftSize();
}
$tabStud['promoLeftSize'] = $promoLeftSize;
$promoRightSize = "apk-f-13";
if($pricingRule->getPromoRightSize()) {
$promoRightSize = $pricingRule->getPromoRightSize();
}
$tabStud['promoRightSize'] = $promoRightSize;
array_push($tabStudios, $tabStud);
}
}
return $this->json(array("status" => "OK", "studios" => $tabStudios, 'available' => $availabilities));
}
/**
* @route("/{_locale}/supercategory/{id}/subcategs", name="getSubCategories", methods={"GET"})
*/
public function getSubCategories(Request $request)
{
$categ = DataObject\StudioSuperCategory::getById($request->get("id"));
if(!$categ){
return $this->json(array("status" => "OK", "scateg" => [], "count" => 0));
}
$scategs = $categ->getCategories();
$returnArray = [];
foreach ($scategs as $scateg){
$returnArray[] = [
"id" => $scateg->getId(),
"title" => $scateg->getTitle($request->getLocale()),
];
}
return $this->json(array("status" => "OK", "scateg" => $returnArray, "count" => count($returnArray)));
}
/**
* @route("/studio/{studio}/daysofweek/{day}", name="getDaysOfWeek", methods={"GET"})
*/
public function getDaysOfWeek(Request $request)
{
$days = [];
$today = Carbon::now();
$today->setHours(1);
$currentDay = Carbon::parse($request->get("day"))->startOfWeek();
$currentDay->setHours(4);
$studio = Studio::getById($request->get('studio'));
for ($i = 0; $i < 7; $i++) {
$dayIso = $currentDay->format('Y-m-d');
$isAv = $currentDay->gte($today);
if ($isAv) {
$totalHourOpened = ($studio->getClosingHour() - $studio->getOpeningHour()) + 1;
$nbBookHours = 0;
for ($h = $studio->getOpeningHour(); $h <= $studio->getClosingHour(); $h++) {
if (HourBooked::check($studio, $currentDay, $h)) {
$nbBookHours++;
}
}
if ($nbBookHours == $totalHourOpened) {
$isAv = false;
}
}
$tab = ["timestamp" => $dayIso, "available" => $isAv];
array_push($days, $tab);
$currentDay->addDays(1);
}
return $this->json($days);
}
/**
* @route("/{_locale}/studio/{studio}/date/{date}/hours/{hour}/{duration}", name="availableHoursOfDaysByStudio", methods={"GET"})
*/
public function availableHoursOfDaysByStudio(Request $request, $hour = null, $duration = null)
{
$studio = Studio::getById($request->get("studio"));
$rawDate = $request->get('date');
$date = Carbon::parse($rawDate);
if(!$hour){
$hour = 0;
}else{
$hour = (int) $request->get('hour');
}
if(!$duration){
$duration = 1;
}else{
$duration = (int) $request->get('duration');
}
$now = Carbon::now();
$tabAvailableHours = array();
for ($i = 0; $i < 24; $i++) {
$tmpDate = Carbon::parse($rawDate);
$tmpDate->setHour($hour);
$math = $hour+$i;
if($i){
$tmpDate->addHours($i);
}
$tabHour = array();
$hourStatus = 'closed';
if($math >= $studio->getClosingHour() && $math >= 24){
$math = $math - 24;
}
if ($math >= $studio->getOpeningHour() && $math < $studio->getClosingHour()) {
$isClosed = false;
if ($studio->getClosedHours()) {
foreach ($studio->getClosedHours() as $clHour) {
if ($tmpDate->gte($clHour->getClosedStart()) && $tmpDate->lte($clHour->getClosedEnd())) {
$hourStatus = 'specialclosed';
$isClosed = true;
}
}
}
if (!$isClosed) {
if (($now->diffInDays($date) == 0) && ($now->day == $tmpDate->day)) {
if ($math >= $now->hour) {
$hourStatus = (HourBooked::check($studio, $tmpDate, $i)) ? 'booked' : 'available';
} else {
$hourStatus = 'past';
}
} else {
$hourStatus = (HourBooked::check($studio, $tmpDate, $i)) ? 'booked' : 'available';
}
}
}
$tabHour['status'] = $hourStatus;
// Send price as x100
// TODO check for 'pack price of hours' in PriceCalculator
//$tabHour['price'] = PriceCalculator::getPriceForHour($studio, $date, $i) * 100;
//$date->setHour($i);
$tabHour['display'] = $tmpDate->clone()->format("G");
$tabHour['timestamp'] = $tmpDate->toIso8601String();
array_push($tabAvailableHours, $tabHour);
}
$originalGrid = [
array_values($studio->getCategorie()->getPricingGrid()->getLundiPricingGrid()->getData()),
array_values($studio->getCategorie()->getPricingGrid()->getMardiPricingGrid()->getData()),
array_values($studio->getCategorie()->getPricingGrid()->getMercrediPricingGrid()->getData()),
array_values($studio->getCategorie()->getPricingGrid()->getJeudiPricingGrid()->getData()),
array_values($studio->getCategorie()->getPricingGrid()->getVendrediPricingGrid()->getData()),
array_values($studio->getCategorie()->getPricingGrid()->getSamediPricingGrid()->getData()),
array_values($studio->getCategorie()->getPricingGrid()->getDimanchePricingGrid()->getData())
];
$object = $studio->getCategorie()->getPricingGrid();
$pHcClean = (float)str_replace(",", ".", $object->getPrixHC());
$hcPrix = $pHcClean*100;
$hpPrix = array_values($object->getGeneralPriceGrid()->getData());
$gridHp = [];
foreach ($hpPrix as $price){
$key = (int) $price["hour"];
$pHpClean = (float)str_replace(",", ".", $price["price"]);
$gridHp[$key] = $pHpClean*100;
}
$grid = [];
foreach ($originalGrid as $key => $dayGrid){
$grid["$key"] = array();
foreach($dayGrid as $key2 => $prices){
$grid["$key"]["$key2"] = [
"full" => (int) $prices["full"]
];
}
}
$promoLeftSize = "apk-f-13";
if($object->getPromoLeftSize()) {
$promoLeftSize = $object->getPromoLeftSize();
}
$promoRightSize = "apk-f-13";
if($object->getPromoRightSize()) {
$promoRightSize = $object->getPromoRightSize();
}
$count = 0;
$checkedHours = [];
$unavailability = 0;
$price = 0.0;
$fullCount = 0;
$hollowCount = 0;
while ($count < $duration){
if($count == 12){
break;
}
$setHour = $hour+$count;
$tmpDate = Carbon::parse($rawDate)->setHour($setHour);
$checkedHours[] = $tmpDate->toIso8601String();
$h = $tmpDate->clone()->format("H");
foreach ($tabAvailableHours as $availableH){
$checkH = (int) $availableH["display"];
if(($checkH == $h) && $availableH["status"] != "available"){
$unavailability = 1;
break;
}
}
$d = ((int) $tmpDate->clone()->format("N"))-1;
$pHoursGrid = $grid[$d];
$status = $pHoursGrid[((int) $h)]["full"];
if($status){
$fullCount++;
}else{
$hollowCount++;
}
$count++;
}
if($count < $object->getPromoThreshold()){
$lowPrice = (float)$hollowCount*$hcPrix;
$highPrice = 0.0;
if($fullCount > 0){
$hpPrice = $gridHp[$fullCount];
$highPrice = (float)$fullCount*$hpPrice;
}
$totalPrice = (float)$highPrice+$lowPrice;
$totalIfFullHours = $gridHp[$count]*$count;
if($totalPrice > $totalIfFullHours){
$totalPrice = (float)$totalIfFullHours;
}
$price = round($totalPrice, 1);
}else{
$promClean = (float) str_replace(",", ".", $object->getPromoPrice());
$price = $promClean*100;
}
return $this->json(array(
"status" => "OK",
"hours" => $tabAvailableHours,
"grid" => $grid,
"prixHc" => $hcPrix,
"prixHp" => $gridHp,
"promoLeft" => $object->getPromoLeft(),
"promoRight" => $object->getPromoRight(),
"promoLeftSize" => $promoLeftSize,
"promoRightSize" => $promoRightSize,
"promoThreshold" => $object->getPromoThreshold(),
"promoPrice" => (float) $object->getPromoPrice()*100,
"hourUnavailable" => $unavailability,
"price" => $price,
"countHours" => $count,
"checkedHours" => $checkedHours
));
}
/**
* @route("/studio/{studio}/pricegrid", name="priceGridByStudio", methods={"GET"})
*/
public function priceGridByStudio(Request $request)
{
$studio = Studio::getById($request->get("studio"));
$pricegrid = array_values($studio->getCategorie()->getPricingGrid()->getPricingGrid()->getData());
$object = $studio->getCategorie()->getPricingGrid();
$grid = [];
foreach ($pricegrid as $key => $prices){
$grid["$key"] = [
"price" => (float) $prices["price"]*100,
"full" => (int) $prices["full"]
];
}
return $this->json(array("status" => "OK", "grid" => $grid, "promoLeft" => $object->getPromoLeft(), "promoRight" => $object->getPromoRight() ));
}
/**
* @route("/categories/matching", name="matchingCategories", methods={"GET"})
*/
public function matchingCategoriesAction(Request $request)
{
$categories = DataObject\StudioSuperCategory::getList();
$matchArray = [];
foreach($categories as $category){
if(!isset($matchArray[$category->getId()])){
$matchArray[$category->getId()] = [];
}
$similars = $category->getMatchedCategories();
foreach ($similars as $similar){
$place = $similar->getPlace();
$matchArray[$category->getId()][$place->getId()] = $similar->getId();
}
}
return $this->json(array("status" => "OK", "match" => $matchArray));
}
}