src/Controller/StudioController.php line 37

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Model\DataObject\User;
  4. use App\Service\HourBooked;
  5. use App\Service\PriceCalculator;
  6. use Carbon\Carbon;
  7. use Doctrine\DBAL\Query\QueryBuilder;
  8. use phpDocumentor\Reflection\DocBlock\Tags\Var_;
  9. use Pimcore\Controller\FrontendController;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Contracts\Translation\TranslatorInterface;
  12. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. use Pimcore\Model\WebsiteSetting;
  15. use Pimcore\Model\DataObject;
  16. use Pimcore\Model\DataObject\Booking;
  17. use Pimcore\Model\DataObject\EquipmentCategory;
  18. use Pimcore\Model\DataObject\Order;
  19. use Pimcore\Model\DataObject\Place;
  20. use Pimcore\Model\DataObject\Studio;
  21. use Pimcore\Model\Document\PageSnippet;
  22. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  23. use ValueError;
  24. use Symfony\Component\Security\Core\Security as FrontSecurity;
  25. class StudioController extends FrontendController
  26. {
  27.     /**
  28.      * @Template
  29.      * @param Request $request
  30.      * @route("/{_locale}/studios", name="studioList",methods={"GET", "POST"})
  31.      * @return array
  32.      */
  33.     public function listAction(Request $requestFrontSecurity $security)
  34.     {
  35.         if($request->get("reset") && $request->get("reset") == 1){
  36.             $session $request->getSession();
  37.             $session->set("searchparams", []);
  38.         }
  39.         $studiosCateg = new DataObject\StudioSuperCategory\Listing();
  40.         $studiosCateg->setOrderKey('order');
  41.         $studiosCateg->setOrder('asc');
  42.         $studiosCateg->load();
  43.         $studios = new DataObject\Studio\Listing();
  44.         //$studios->setOrderKey('');
  45.         //$studios->setKey('');
  46.         $studios->load();
  47.         $locations = new Place\Listing();
  48.         $locations->load();
  49.         $orders = [];
  50.         $securityUser $security->getUser();
  51.         if ($securityUser) {
  52.             $user User::getByUsername($securityUser->getUserIdentifier())->load()[0];
  53.             if($user){
  54.                 if($user->getStatus() == "rejected"){
  55.                     return $this->redirectToRoute("suspendedRoute");
  56.                 }
  57.                 $orders = new Order\Listing();
  58.                 $orders->setCondition("linkedUser__id = ".$user->getId()." AND (status like 'new')");
  59.                 $orders->load();
  60.             }
  61.         }
  62.         $displayCalendar 0;
  63.         return  [
  64.             'studios' => $studios,
  65.             'studioCategories' => $studiosCateg,
  66.             'locations' => $locations,
  67.             'orders' => $orders,
  68.             'displayCalendar' => $displayCalendar,
  69.             'detailstudio' => 0,
  70.             'language' => $request->getLocale()
  71.         ];
  72.     }
  73.     /**
  74.      * @route("/{_locale}/api/studios", name="studiosapi", methods={"GET"})
  75.      */
  76.     public function getStudioListAction(Request $request)
  77.     {
  78.         $session $request->getSession();
  79.         $allParams $request->query->all();
  80.         $session->set("searchparams"$allParams);
  81.         $checkDate Carbon::parse($allParams['sDate']);
  82.         $checkDate->setHour(intval($allParams['sHour']));
  83.         $checkNow Carbon::now()->subHour();
  84.         if($checkDate->timestamp >= $checkNow->timestamp){
  85.             $availabilities true;
  86.             $studioList = new Studio\Listing();
  87.             $studioList->onCreateQueryBuilder(function (QueryBuilder $queryBuilder) use ($allParams) {
  88.                 $queryBuilder->andWhere("(maintenance IS NULL OR maintenance = 0)");
  89.                 $originalTable $queryBuilder->getQueryParts()['from'][0]['table'];
  90.                 $tabStudCats = array();
  91.                 try {
  92.                     if (array_key_exists('studTypes'$allParams)) {
  93.                         if ($allParams['studTypes'] != '') {
  94.                             $tabStudCats explode(","$allParams['studTypes']);
  95.                         }
  96.                     }
  97.                 } catch (ValueError $e) {
  98.                 }
  99.                 if (array_key_exists('souscategories'$allParams) && $allParams['souscategories']) {
  100.                     $studCatSQL '(categorie__id = ' $allParams['souscategories'] . ')';
  101.                     $queryBuilder->andWhere($studCatSQL);
  102.                 }else{
  103.                     if (count($tabStudCats)) {
  104.                         $studCatSQL '';
  105.                         foreach ($tabStudCats as $key => $studcat) {
  106.                             $supCat DataObject\StudioSuperCategory::getById($studcat);
  107.                             if($supCat){
  108.                                 if ($key != 0) {
  109.                                     $studCatSQL .= ' OR ';
  110.                                 }
  111.                                 if(count($supCat->getCategories()) > 1){
  112.                                     $studCatSQL .= "(";
  113.                                     foreach($supCat->getCategories() as $key2 => $sCateg){
  114.                                         if ($key2 != 0) {
  115.                                             $studCatSQL .= ' OR ';
  116.                                         }
  117.                                         $sCategId $sCateg->getId();
  118.                                         $studCatSQL .= '(categorie__id = ' $sCategId ')';
  119.                                     }
  120.                                     $studCatSQL .= ")";
  121.                                 }else{
  122.                                     $sCategId $supCat->getCategories()[0]->getId();
  123.                                     $studCatSQL .= '(categorie__id = ' $sCategId ')';
  124.                                 }
  125.                             }
  126.                         }
  127.                         if($studCatSQL){
  128.                             $queryBuilder->andWhere($studCatSQL);
  129.                         }
  130.                     }
  131.                 }
  132.                 if (array_key_exists('sDate'$allParams)) {
  133.                     $startDate Carbon::parse($allParams['sDate']);
  134.                     $endDate Carbon::parse($allParams['sDate']);
  135.                     $startDate->setHour(intval($allParams['sHour']));
  136.                     $endDate->setHour(intval($allParams['sHour']));
  137.                     $endDate->addHours(intval($allParams['sDuration']));
  138.                     $sqlOrder "SELECT count(booking.o_id)
  139.                     FROM object_" Booking::classId() . " booking
  140.                     JOIN object_" Order::classId() . " ord ON ord.o_id = booking.order__id
  141.                     WHERE booking.bookedStudio__id = " $originalTable ".o_id AND ord.status NOT IN ('abandonned', 'canceled', 'temporary')
  142.                     AND ((booking.bookedStart BETWEEN " $startDate->timestamp+" AND " $endDate->timestamp-"
  143.                         OR booking.bookedEnd BETWEEN " $startDate->timestamp+" AND " $endDate->timestamp-") OR (booking.bookedStart <= " $startDate->timestamp " AND booking.bookedEnd >= " $endDate->timestamp "))";
  144.                     //@TODO : Pour studios ayant des réservations pour l'heure dispo choisie : $queryBuilder->andWhere("(" . $sqlOrder . ") > 0");
  145.                     // Recopier le reste
  146.                     // Ajouter le paramètre $tabStud['availability'] = $infos;
  147.                     // Array merger en resetant les ID
  148.                     $queryBuilder->andWhere("(" $sqlOrder ") = 0");
  149.                     if($startDate->day != $endDate->day){
  150.                         $endDateQuery 24+$endDate->hour;
  151.                     }else{
  152.                         $endDateQuery $endDate->hour;
  153.                     }
  154.                     $hoursWhere "(".$startDate->hour " BETWEEN " $originalTable ".openingHour AND " $originalTable ".closingHour";
  155.                     $hoursWhere .= " AND ".$endDateQuery " BETWEEN " $originalTable ".openingHour AND " $originalTable ".closingHour)";
  156.                     $hoursWhere .= " OR (".$originalTable ".openingHour = 0 AND " $originalTable ".closingHour = 24)";
  157.                     $queryBuilder->andWhere($hoursWhere);
  158.                     /*if ($startDate->day != $endDate->day) {
  159.                         $queryBuilder->andWhere($originalTable . ".openingHour = 0");
  160.                         $queryBuilder->andWhere($originalTable . ".closingHour = 23");
  161.                     }*/
  162.                     $sqlClosedHours "SELECT count(clHour.o_id) FROM object_collection_closedHours_" Studio::classId() . " clHour"
  163.                         " WHERE " $originalTable ".o_id = clHour.o_id"
  164.                         " AND (" $startDate->timestamp " BETWEEN clHour.closedStart AND clHour.closedEnd"
  165.                         " OR " $endDate->timestamp " BETWEEN clHour.closedStart AND clHour.closedEnd"
  166.                         " OR clHour.closedStart BETWEEN " $startDate->timestamp " AND " $endDate->timestamp
  167.                         " OR clHour.closedEnd BETWEEN " $startDate->timestamp " AND " $endDate->timestamp ")";
  168.                     $queryBuilder->andWhere("(" $sqlClosedHours ") = 0");
  169.                     $queryBuilder->andWhere("place__id = " $allParams['sLocation']);
  170.                 }
  171.             });
  172.             $studioList->setOrderKey("OrderPlace");
  173.             $studioList->setOrder("ASC");
  174.             //Limite de studios
  175.             //$studioList->setLimit(2);
  176.             $studioList->setLocale($request->getLocale());
  177.             $studioList->load();
  178.             $tabStudios = array();
  179.             foreach ($studioList as $studio) {
  180.                 $tabStud = array();
  181.                 $tabStud['id'] = $studio->getId();
  182.                 //$tabStud['detailURL'] = $this->generateUrl("studioDetail", ["slug" => $studio->getSlug()], UrlGeneratorInterface::ABSOLUTE_URL);
  183.                 $gear "";
  184.                 if ($studio->getEquipments()) {
  185.                     foreach ($studio->getEquipments() as $equipment) {
  186.                         if($equipment->getEquipment()):
  187.                             $gear .= $equipment->getQty() . "&nbsp;x&nbsp; " $equipment->getEquipment()->getName() . "<br/>";
  188.                         endif;
  189.                     }
  190.                 }
  191.                 $tabStud['gear'] = $gear;
  192.                 $tabStud['infos'] = $studio->getInfos();
  193.                 $tabStud['shortInfos'] = $studio->getShortInfos();
  194.                 $tabStud['maxPersons'] = $studio->getMaxPersons();
  195.                 $tabStud['title'] = $studio->getTitle();
  196.                 $tabStud['titleTranslated'] = $studio->getTitleTranslated();
  197.                 $tabStud['image'] = $studio->getImage()->getThumbnail("studio-thumb")->getHtml(['imgAttributes' => ['uk-cover' => null]]);
  198.                 $tabStud['defaultPrice'] = $studio->getDefaultPrice()->getAmount() * 100;
  199.                 $tabStud['availability'] = 1;
  200.                 $tabStud['language'] = $request->getLocale();
  201.                 //CSS
  202.                 $tabStud['cssFontSizeTitle'] = $studio->getCssFontSizeTitle();
  203.                 $tabStud['cssFontSizeTitleDetail'] = $studio->getCssFontSizeTitleDetail();
  204.                 // Ajout des promoLeft et right en haut du studio
  205.                 $pricingRule $studio->getCategorie()->getPricingGrid();
  206.                 $tabStud['promoLeft'] = $pricingRule->getPromoLeft();
  207.                 $tabStud['promoRight'] = $pricingRule->getPromoRight();
  208.                 $promoLeftSize "apk-f-13";
  209.                 if($pricingRule->getPromoLeftSize()) {
  210.                     $promoLeftSize $pricingRule->getPromoLeftSize();
  211.                 }
  212.                 $tabStud['promoLeftSize'] = $promoLeftSize;
  213.                 $promoRightSize "apk-f-13";
  214.                 if($pricingRule->getPromoRightSize()) {
  215.                     $promoRightSize $pricingRule->getPromoRightSize();
  216.                 }
  217.                 $tabStud['promoRightSize'] = $promoRightSize;
  218.                 $tabStud['placeLock'] = $studio->getPlace()->getLockReservation() ? 0;
  219.                 $tabStud['lockText'] = $studio->getPlace()->getLockText($request->getLocale());
  220.                 array_push($tabStudios$tabStud);
  221.             }
  222.         }else{
  223.             $tabStudios = array();
  224.         }
  225.         if(!$tabStudios){
  226.             // Ajouter le paramètre $tabStud['availability'] = $infos;
  227.             // Array merger en resetant les ID
  228.             //////// AFFICHAGE DES STUDIOS NON DISPONIBLES /////////
  229.             $availabilities false;
  230.             $studioListUnavailable = new Studio\Listing();
  231.             $studioListUnavailable->onCreateQueryBuilder(function (QueryBuilder $queryBuilder) use ($allParams) {
  232.                 $queryBuilder->andWhere("(maintenance IS NULL OR maintenance = 0)");
  233.                 $originalTable $queryBuilder->getQueryParts()['from'][0]['table'];
  234.                 $tabStudCats = array();
  235.                 try {
  236.                     if (array_key_exists('studTypes'$allParams)) {
  237.                         if ($allParams['studTypes'] != '') {
  238.                             $tabStudCats explode(","$allParams['studTypes']);
  239.                         }
  240.                     }
  241.                 } catch (ValueError $e) {
  242.                 }
  243.                 if (array_key_exists('souscategories'$allParams) && $allParams['souscategories']) {
  244.                     $studCatSQL '(categorie__id = ' $allParams['souscategories'] . ')';
  245.                     $queryBuilder->andWhere($studCatSQL);
  246.                 }else{
  247.                     if (count($tabStudCats)) {
  248.                         $studCatSQL '';
  249.                         foreach ($tabStudCats as $key => $studcat) {
  250.                             $supCat DataObject\StudioSuperCategory::getById($studcat);
  251.                             if ($key != 0) {
  252.                                 $studCatSQL .= ' OR ';
  253.                             }
  254.                             if(count($supCat->getCategories()) > 1){
  255.                                 $studCatSQL .= "(";
  256.                                 foreach($supCat->getCategories() as $key2 => $sCateg){
  257.                                     if ($key2 != 0) {
  258.                                         $studCatSQL .= ' OR ';
  259.                                     }
  260.                                     $sCategId $sCateg->getId();
  261.                                     $studCatSQL .= '(categorie__id = ' $sCategId ')';
  262.                                 }
  263.                                 $studCatSQL .= ")";
  264.                             }else{
  265.                                 $sCategId $supCat->getCategories()[0]->getId();
  266.                                 $studCatSQL .= '(categorie__id = ' $sCategId ')';
  267.                             }
  268.                         }
  269.                         $queryBuilder->andWhere($studCatSQL);
  270.                     }
  271.                 }
  272.                 if (array_key_exists('sDate'$allParams)) {
  273.                     $startDate Carbon::parse($allParams['sDate']);
  274.                     $endDate Carbon::parse($allParams['sDate']);
  275.                     $startDate->setHour(intval($allParams['sHour']));
  276.                     $endDate->setHour(intval($allParams['sHour']));
  277.                     $endDate->addHours(intval($allParams['sDuration']));
  278.                     $sqlOrder "SELECT count(booking.o_id)
  279.                     FROM object_" Booking::classId() . " booking
  280.                     JOIN object_" Order::classId() . " ord ON ord.o_id = booking.order__id
  281.                     WHERE booking.bookedStudio__id = " $originalTable ".o_id AND ord.status NOT IN ('abandonned', 'canceled', 'temporary')
  282.                     AND ((booking.bookedStart NOT BETWEEN " $startDate->timestamp+" AND " $endDate->timestamp-"
  283.                         OR booking.bookedEnd NOT BETWEEN " $startDate->timestamp+" AND " $endDate->timestamp-") OR (booking.bookedStart <= " $startDate->timestamp " AND booking.bookedEnd >= " $endDate->timestamp "))";
  284.                     $open $startDate->hour " NOT BETWEEN " $originalTable ".openingHour AND " $originalTable ".closingHour";
  285.                     $close $endDate->hour " NOT BETWEEN " $originalTable ".openingHour AND " $originalTable ".closingHour";
  286.                     $sqlClosedHours "SELECT count(clHour.o_id) FROM object_collection_closedHours_" Studio::classId() . " clHour"
  287.                         " WHERE " $originalTable ".o_id = clHour.o_id"
  288.                         " AND (" $startDate->timestamp " NOT BETWEEN clHour.closedStart AND clHour.closedEnd"
  289.                         " OR " $endDate->timestamp " NOT BETWEEN clHour.closedStart AND clHour.closedEnd"
  290.                         " OR clHour.closedStart NOT BETWEEN " $startDate->timestamp " AND " $endDate->timestamp
  291.                         " OR clHour.closedEnd NOT BETWEEN " $startDate->timestamp " AND " $endDate->timestamp ")";
  292.                     $queryBuilder->andWhere("(($sqlOrder) > 0) OR ($open OR $close) OR (($sqlClosedHours) > 0)");
  293.                     $queryBuilder->andWhere("place__id = " $allParams['sLocation']);
  294.                 }
  295.             });
  296.             $studioListUnavailable->setOrderKey("OrderPlace");
  297.             $studioListUnavailable->setOrder("ASC");
  298.             $studioListUnavailable->setLocale($request->getLocale());
  299.             $studioListUnavailable $studioListUnavailable->load();
  300.             //On ne réinitialise pas l'array
  301.             //$tabStudios = array();
  302.             foreach ($studioListUnavailable as $studio) {
  303.                 $tabStud = array();
  304.                 $tabStud['id'] = $studio->getId();
  305.                 //$tabStud['detailURL'] = $this->generateUrl("studioDetail", ["slug" => $studio->getSlug()], UrlGeneratorInterface::ABSOLUTE_URL);
  306.                 $gear "";
  307.                 if ($studio->getEquipments()) {
  308.                     foreach ($studio->getEquipments() as $equipment) {
  309.                         if($equipment->getEquipment()):
  310.                             $gear .= $equipment->getQty() . "&nbsp;x&nbsp; " $equipment->getEquipment()->getName() . "<br/>";
  311.                         endif;
  312.                     }
  313.                 }
  314.                 $tabStud['gear'] = $gear;
  315.                 $tabStud['infos'] = $studio->getInfos();
  316.                 $tabStud['shortInfos'] = $studio->getShortInfos();
  317.                 $tabStud['maxPersons'] = $studio->getMaxPersons();
  318.                 $tabStud['title'] = $studio->getTitle();
  319.                 $tabStud['titleTranslated'] = $studio->getTitleTranslated();
  320.                 $tabStud['image'] = $studio->getImage()->getThumbnail("studio-thumb")->getHtml(['imgAttributes' => ['uk-cover' => null]]);
  321.                 $tabStud['defaultPrice'] = $studio->getDefaultPrice()->getAmount() * 100;
  322.                 $tabStud['availability'] = 0;
  323.                 $tabStud['language'] = $request->getLocale();
  324.                 //CSS
  325.                 $tabStud['cssFontSizeTitle'] = $studio->getCssFontSizeTitle();
  326.                 $tabStud['cssFontSizeTitleDetail'] = $studio->getCssFontSizeTitleDetail();
  327.                 // Ajout des promoLeft et right en haut du studio
  328.                 $pricingRule $studio->getCategorie()->getPricingGrid();
  329.                 $tabStud['promoLeft'] = $pricingRule->getPromoLeft();
  330.                 $tabStud['promoRight'] = $pricingRule->getPromoRight();
  331.                 $promoLeftSize "apk-f-13";
  332.                 if($pricingRule->getPromoLeftSize()) {
  333.                     $promoLeftSize $pricingRule->getPromoLeftSize();
  334.                 }
  335.                 $tabStud['promoLeftSize'] = $promoLeftSize;
  336.                 $promoRightSize "apk-f-13";
  337.                 if($pricingRule->getPromoRightSize()) {
  338.                     $promoRightSize $pricingRule->getPromoRightSize();
  339.                 }
  340.                 $tabStud['promoRightSize'] = $promoRightSize;
  341.                 array_push($tabStudios$tabStud);
  342.             }
  343.         }
  344.         return $this->json(array("status" => "OK""studios" => $tabStudios'available' => $availabilities));
  345.     }
  346.     /**
  347.      *  @route("/{_locale}/supercategory/{id}/subcategs", name="getSubCategories", methods={"GET"})
  348.      */
  349.     public function getSubCategories(Request $request)
  350.     {
  351.         $categ DataObject\StudioSuperCategory::getById($request->get("id"));
  352.         if(!$categ){
  353.             return $this->json(array("status" => "OK""scateg" => [], "count" => 0));
  354.         }
  355.         $scategs $categ->getCategories();
  356.         $returnArray = [];
  357.         foreach ($scategs as $scateg){
  358.             $returnArray[] = [
  359.               "id" => $scateg->getId(),
  360.               "title" => $scateg->getTitle($request->getLocale()),
  361.             ];
  362.         }
  363.         return $this->json(array("status" => "OK""scateg" => $returnArray"count" => count($returnArray)));
  364.     }
  365.     /**
  366.      *  @route("/studio/{studio}/daysofweek/{day}", name="getDaysOfWeek", methods={"GET"})
  367.      */
  368.     public function getDaysOfWeek(Request $request)
  369.     {
  370.         $days = [];
  371.         $today Carbon::now();
  372.         $today->setHours(1);
  373.         $currentDay Carbon::parse($request->get("day"))->startOfWeek();
  374.         $currentDay->setHours(4);
  375.         $studio Studio::getById($request->get('studio'));
  376.         for ($i 0$i 7$i++) {
  377.             $dayIso $currentDay->format('Y-m-d');
  378.             $isAv $currentDay->gte($today);
  379.             if ($isAv) {
  380.                 $totalHourOpened = ($studio->getClosingHour() - $studio->getOpeningHour()) + 1;
  381.                 $nbBookHours 0;
  382.                 for ($h $studio->getOpeningHour(); $h <= $studio->getClosingHour(); $h++) {
  383.                     if (HourBooked::check($studio$currentDay$h)) {
  384.                         $nbBookHours++;
  385.                     }
  386.                 }
  387.                 if ($nbBookHours == $totalHourOpened) {
  388.                     $isAv false;
  389.                 }
  390.             }
  391.             $tab = ["timestamp" => $dayIso"available" => $isAv];
  392.             array_push($days$tab);
  393.             $currentDay->addDays(1);
  394.         }
  395.         return $this->json($days);
  396.     }
  397.     /**
  398.      * @route("/{_locale}/studio/{studio}/date/{date}/hours/{hour}/{duration}", name="availableHoursOfDaysByStudio", methods={"GET"})
  399.      */
  400.     public function availableHoursOfDaysByStudio(Request $request$hour null$duration null)
  401.     {
  402.         $studio Studio::getById($request->get("studio"));
  403.         $rawDate $request->get('date');
  404.         $date Carbon::parse($rawDate);
  405.         if(!$hour){
  406.             $hour 0;
  407.         }else{
  408.             $hour = (int) $request->get('hour');
  409.         }
  410.         if(!$duration){
  411.             $duration 1;
  412.         }else{
  413.             $duration = (int) $request->get('duration');
  414.         }
  415.         $now Carbon::now();
  416.         $tabAvailableHours = array();
  417.         for ($i 0$i 24$i++) {
  418.             $tmpDate Carbon::parse($rawDate);
  419.             $tmpDate->setHour($hour);
  420.             $math $hour+$i;
  421.             if($i){
  422.                 $tmpDate->addHours($i);
  423.             }
  424.             $tabHour = array();
  425.             $hourStatus 'closed';
  426.             if($math >= $studio->getClosingHour() && $math >= 24){
  427.                 $math $math 24;
  428.             }
  429.             if ($math >= $studio->getOpeningHour() && $math $studio->getClosingHour()) {
  430.                 $isClosed false;
  431.                 if ($studio->getClosedHours()) {
  432.                     foreach ($studio->getClosedHours() as $clHour) {
  433.                         if ($tmpDate->gte($clHour->getClosedStart()) && $tmpDate->lte($clHour->getClosedEnd())) {
  434.                             $hourStatus 'specialclosed';
  435.                             $isClosed true;
  436.                         }
  437.                     }
  438.                 }
  439.                 if (!$isClosed) {
  440.                     if (($now->diffInDays($date) == 0) && ($now->day == $tmpDate->day)) {
  441.                         if ($math >= $now->hour) {
  442.                             $hourStatus = (HourBooked::check($studio$tmpDate$i)) ? 'booked' 'available';
  443.                         } else {
  444.                             $hourStatus 'past';
  445.                         }
  446.                     } else {
  447.                         $hourStatus = (HourBooked::check($studio$tmpDate$i)) ? 'booked' 'available';
  448.                     }
  449.                 }
  450.             }
  451.             $tabHour['status'] = $hourStatus;
  452.             // Send price as x100
  453.             // TODO check for 'pack price of hours' in PriceCalculator
  454.             //$tabHour['price'] = PriceCalculator::getPriceForHour($studio, $date, $i) * 100;
  455.             //$date->setHour($i);
  456.             $tabHour['display'] = $tmpDate->clone()->format("G");
  457.             $tabHour['timestamp'] = $tmpDate->toIso8601String();
  458.             array_push($tabAvailableHours$tabHour);
  459.         }
  460.         $originalGrid = [
  461.             array_values($studio->getCategorie()->getPricingGrid()->getLundiPricingGrid()->getData()),
  462.             array_values($studio->getCategorie()->getPricingGrid()->getMardiPricingGrid()->getData()),
  463.             array_values($studio->getCategorie()->getPricingGrid()->getMercrediPricingGrid()->getData()),
  464.             array_values($studio->getCategorie()->getPricingGrid()->getJeudiPricingGrid()->getData()),
  465.             array_values($studio->getCategorie()->getPricingGrid()->getVendrediPricingGrid()->getData()),
  466.             array_values($studio->getCategorie()->getPricingGrid()->getSamediPricingGrid()->getData()),
  467.             array_values($studio->getCategorie()->getPricingGrid()->getDimanchePricingGrid()->getData())
  468.         ];
  469.         $object $studio->getCategorie()->getPricingGrid();
  470.         $pHcClean = (float)str_replace(",""."$object->getPrixHC());
  471.         $hcPrix $pHcClean*100;
  472.         $hpPrix array_values($object->getGeneralPriceGrid()->getData());
  473.         $gridHp = [];
  474.         foreach ($hpPrix as $price){
  475.             $key = (int) $price["hour"];
  476.             $pHpClean = (float)str_replace(",""."$price["price"]);
  477.             $gridHp[$key] = $pHpClean*100;
  478.         }
  479.         $grid = [];
  480.         foreach ($originalGrid as $key => $dayGrid){
  481.             $grid["$key"] = array();
  482.             foreach($dayGrid as $key2 => $prices){
  483.                 $grid["$key"]["$key2"] = [
  484.                     "full" => (int) $prices["full"]
  485.                 ];
  486.             }
  487.         }
  488.         $promoLeftSize "apk-f-13";
  489.         if($object->getPromoLeftSize()) {
  490.             $promoLeftSize $object->getPromoLeftSize();
  491.         }
  492.         $promoRightSize "apk-f-13";
  493.         if($object->getPromoRightSize()) {
  494.             $promoRightSize $object->getPromoRightSize();
  495.         }
  496.         $count 0;
  497.         $checkedHours = [];
  498.         $unavailability 0;
  499.         $price 0.0;
  500.         $fullCount 0;
  501.         $hollowCount 0;
  502.         while ($count $duration){
  503.             if($count == 12){
  504.                 break;
  505.             }
  506.             $setHour $hour+$count;
  507.             $tmpDate Carbon::parse($rawDate)->setHour($setHour);
  508.             $checkedHours[] = $tmpDate->toIso8601String();
  509.             $h $tmpDate->clone()->format("H");
  510.             foreach ($tabAvailableHours as $availableH){
  511.                 $checkH = (int) $availableH["display"];
  512.                 if(($checkH == $h) && $availableH["status"] != "available"){
  513.                     $unavailability 1;
  514.                     break;
  515.                 }
  516.             }
  517.             $d = ((int) $tmpDate->clone()->format("N"))-1;
  518.             $pHoursGrid $grid[$d];
  519.             $status $pHoursGrid[((int) $h)]["full"];
  520.             if($status){
  521.                 $fullCount++;
  522.             }else{
  523.                 $hollowCount++;
  524.             }
  525.             $count++;
  526.         }
  527.         if($count $object->getPromoThreshold()){
  528.             $lowPrice = (float)$hollowCount*$hcPrix;
  529.             $highPrice 0.0;
  530.             if($fullCount 0){
  531.                 $hpPrice $gridHp[$fullCount];
  532.                 $highPrice = (float)$fullCount*$hpPrice;
  533.             }
  534.             $totalPrice = (float)$highPrice+$lowPrice;
  535.             $totalIfFullHours $gridHp[$count]*$count;
  536.             if($totalPrice $totalIfFullHours){
  537.                 $totalPrice = (float)$totalIfFullHours;
  538.             }
  539.             $price round($totalPrice1);
  540.         }else{
  541.             $promClean = (float) str_replace(",""."$object->getPromoPrice());
  542.             $price $promClean*100;
  543.         }
  544.         return $this->json(array(
  545.             "status" => "OK",
  546.             "hours" => $tabAvailableHours,
  547.             "grid" => $grid,
  548.             "prixHc" => $hcPrix,
  549.             "prixHp" => $gridHp,
  550.             "promoLeft" => $object->getPromoLeft(),
  551.             "promoRight" => $object->getPromoRight(),
  552.             "promoLeftSize" => $promoLeftSize,
  553.             "promoRightSize" => $promoRightSize,
  554.             "promoThreshold" => $object->getPromoThreshold(),
  555.             "promoPrice" => (float) $object->getPromoPrice()*100,
  556.             "hourUnavailable" => $unavailability,
  557.             "price" => $price,
  558.             "countHours" => $count,
  559.             "checkedHours" => $checkedHours
  560.         ));
  561.     }
  562.     /**
  563.      * @route("/studio/{studio}/pricegrid", name="priceGridByStudio", methods={"GET"})
  564.      */
  565.     public function priceGridByStudio(Request $request)
  566.     {
  567.         $studio Studio::getById($request->get("studio"));
  568.         $pricegrid array_values($studio->getCategorie()->getPricingGrid()->getPricingGrid()->getData());
  569.         $object $studio->getCategorie()->getPricingGrid();
  570.         $grid = [];
  571.         foreach ($pricegrid as $key => $prices){
  572.             $grid["$key"] = [
  573.                 "price" => (float) $prices["price"]*100,
  574.                 "full" => (int) $prices["full"]
  575.             ];
  576.         }
  577.         return $this->json(array("status" => "OK""grid" => $grid"promoLeft" => $object->getPromoLeft(), "promoRight" => $object->getPromoRight() ));
  578.     }
  579.     /**
  580.      * @route("/categories/matching", name="matchingCategories", methods={"GET"})
  581.      */
  582.     public function matchingCategoriesAction(Request $request)
  583.     {
  584.         $categories DataObject\StudioSuperCategory::getList();
  585.         $matchArray = [];
  586.         foreach($categories as $category){
  587.             if(!isset($matchArray[$category->getId()])){
  588.                 $matchArray[$category->getId()] = [];
  589.             }
  590.             $similars $category->getMatchedCategories();
  591.             foreach ($similars as $similar){
  592.                 $place $similar->getPlace();
  593.                 $matchArray[$category->getId()][$place->getId()] = $similar->getId();
  594.             }
  595.         }
  596.         return $this->json(array("status" => "OK""match" => $matchArray));
  597.     }
  598. }