113 lines
3.9 KiB
PHP
113 lines
3.9 KiB
PHP
<?php
|
|
/*************************************************************************************/
|
|
/* Copyright (c) Franck Allimant, CQFDev */
|
|
/* email : thelia@cqfdev.fr */
|
|
/* web : http://www.cqfdev.fr */
|
|
/* */
|
|
/* For the full copyright and license information, please view the LICENSE */
|
|
/* file that was distributed with this source code. */
|
|
/*************************************************************************************/
|
|
|
|
/**
|
|
* Created by Franck Allimant, CQFDev <franck@cqfdev.fr>
|
|
* Date: 13/06/2019 16:01
|
|
*/
|
|
namespace Beds24\Loop;
|
|
|
|
use Beds24\Beds24;
|
|
use Beds24\Beds24\Beds24Request;
|
|
use Beds24\Model\Base\Beds24ProductInfoQuery;
|
|
use Thelia\Core\HttpFoundation\Session\Session;
|
|
use Thelia\Core\Template\Element\ArraySearchLoopInterface;
|
|
use Thelia\Core\Template\Element\BaseLoop;
|
|
use Thelia\Core\Template\Element\LoopResult;
|
|
use Thelia\Core\Template\Element\LoopResultRow;
|
|
use Thelia\Core\Template\Loop\Argument\Argument;
|
|
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
|
|
|
|
|
/**
|
|
* @method string getRoomId()
|
|
* @method int getProductId()
|
|
*/
|
|
class RoomDescription extends BaseLoop implements ArraySearchLoopInterface
|
|
{
|
|
/**
|
|
* @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection
|
|
*/
|
|
protected function getArgDefinitions()
|
|
{
|
|
return new ArgumentCollection(
|
|
Argument::createIntTypeArgument('room_id'),
|
|
Argument::createIntTypeArgument('product_id')
|
|
);
|
|
}
|
|
|
|
|
|
public function buildArray()
|
|
{
|
|
$roomId = $this->getRoomId();
|
|
|
|
// Si un ID produit est fourni, trouver le Room ID associée (on écrase celui fourni !)
|
|
if (null !== $productId = $this->getProductId()) {
|
|
if (null === $roomInfo = Beds24ProductInfoQuery::create()->findOneByProductId($productId)) {
|
|
return [];
|
|
} else {
|
|
$roomId = $roomInfo->getRoomId();
|
|
}
|
|
}
|
|
|
|
/** @var Session $session */
|
|
$session = $this->requestStack->getCurrentRequest()->getSession();
|
|
|
|
$api = new Beds24Request();
|
|
|
|
$responseArray = $api->getRoomDescription($roomId, $session->getLang()->getCode());
|
|
|
|
if ($api->hasError($responseArray)) {
|
|
return [];
|
|
}
|
|
|
|
$result = [];
|
|
/*
|
|
foreach ($responseArray as $item) {
|
|
}
|
|
*/
|
|
// print_r($result);
|
|
|
|
return $result;
|
|
}
|
|
|
|
public function parseResults(LoopResult $loopResult)
|
|
{
|
|
foreach ($loopResult->getResultDataCollection() as $item) {
|
|
$loopResultRow = new LoopResultRow($item);
|
|
|
|
$checkIn = \DateTime::createFromFormat("Ymd", $item['checkIn']);
|
|
$checkOut = \DateTime::createFromFormat("Ymd", $item['checkOut']);
|
|
$remise = Beds24::getRemiseDuree($checkIn, $checkOut, $nbJours);
|
|
$prixRemise = round($item['price'] * (1 - $remise), 2);
|
|
|
|
$loopResultRow
|
|
->set('ROOM_ID', $item['roomId'])
|
|
->set('PRODUCT_ID', $item['productId'])
|
|
->set('PROP_ID', $item['propId'])
|
|
->set('ROOMS_AVAIL', $item['roomsavail'])
|
|
->set('PRICE', $item['price'])
|
|
->set('PRICE_REMISE', $prixRemise)
|
|
->set('REMISE', $remise * 100)
|
|
->set('NB_JOURS', $nbJours)
|
|
->set('CHECK_IN', $checkIn)
|
|
->set('CHECK_OUT', $checkOut)
|
|
->set('LAST_NIGHT', \DateTime::createFromFormat("Ymd", $item['lastNight']))
|
|
->set('NUM_ADULTS', $item['numAdult'])
|
|
->set('NUM_CHILDREN', $item['numChildren'])
|
|
;
|
|
|
|
$loopResult->addRow($loopResultRow);
|
|
}
|
|
|
|
return $loopResult;
|
|
}
|
|
}
|