94 lines
3.2 KiB
PHP
94 lines
3.2 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: 17/06/2019 13:03
|
|
*/
|
|
namespace Beds24\Controller\Front;
|
|
|
|
use Beds24\Beds24\Beds24Request;
|
|
use Beds24\Beds24\SearchParameters;
|
|
use Beds24\Model\Base\Beds24ProductInfoQuery;
|
|
use Thelia\Controller\Front\BaseFrontController;
|
|
use Thelia\Log\Tlog;
|
|
|
|
/**
|
|
* @author Franck Allimant <franck@cqfdev.fr>
|
|
*/
|
|
class SearchController extends BaseFrontController
|
|
{
|
|
public function searchAll()
|
|
{
|
|
return $this->search("ajax/home-search-results");
|
|
}
|
|
|
|
public function searchProduct($productId)
|
|
{
|
|
return $this->search("ajax/product-search-results", $productId);
|
|
}
|
|
|
|
public function search($resultTemplate, $productId = null)
|
|
{
|
|
$searchForm = $this->createForm('beds24.form.search');
|
|
|
|
try {
|
|
$form = $this->validateForm($searchForm, "POST");
|
|
|
|
// Get the form field values
|
|
$data = $form->getData();
|
|
|
|
$startDate = \DateTime::createFromFormat("Y-m-d", $data['start_date']);
|
|
$endDate = \DateTime::createFromFormat("Y-m-d", $data['end_date']);
|
|
|
|
$searchParameters = new SearchParameters($this->getRequest());
|
|
|
|
$searchParameters->setSearchParameters(
|
|
$startDate,
|
|
$endDate,
|
|
intval($data['adults']),
|
|
intval($data['children'])
|
|
);
|
|
|
|
$roomId = null;
|
|
|
|
if (null !== $productId) {
|
|
if (null !== $productInfo = Beds24ProductInfoQuery::create()->findOneByProductId($productId)) {
|
|
$roomId = $productInfo->getRoomId();
|
|
}
|
|
}
|
|
|
|
return $this->render(
|
|
$resultTemplate,
|
|
[
|
|
'startDate' => $searchParameters->getStartDate()->format("Y-m-d"),
|
|
'endDate' => $searchParameters->getEndDate()->format("Y-m-d"),
|
|
'adultCount' => $searchParameters->getAdultCount(),
|
|
'childCount' => $searchParameters->getChildCount(),
|
|
'product_id' => $productId,
|
|
'room_id' => $roomId,
|
|
'error' => ''
|
|
]
|
|
);
|
|
|
|
} catch (\Exception $ex) {
|
|
Tlog::getInstance()->addError($ex->getMessage(), $ex);
|
|
|
|
return $this->render(
|
|
$resultTemplate,
|
|
[
|
|
'product_id' => $productId,
|
|
'error' => $ex->getMessage()
|
|
]
|
|
);
|
|
}
|
|
}
|
|
}
|