Initial commit
This commit is contained in:
115
local/modules/Beds24.old/Beds24/SearchParameters.php
Normal file
115
local/modules/Beds24.old/Beds24/SearchParameters.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<?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: 19/06/2019 17:34
|
||||
*/
|
||||
|
||||
namespace Beds24\Beds24;
|
||||
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Core\HttpFoundation\Session\Session;
|
||||
|
||||
class SearchParameters
|
||||
{
|
||||
const SESSION_VAR_NAME = 'beds24.search-parameters';
|
||||
|
||||
/** @var Session */
|
||||
protected $session;
|
||||
|
||||
/**
|
||||
* SearchParameters constructor.
|
||||
* @param Request|\Symfony\Component\HttpFoundation\Request $request
|
||||
*/
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
$this->session = $request->getSession();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $startDate
|
||||
* @param \DateTime $endDate
|
||||
* @param int $adultCount
|
||||
* @param int $childCount
|
||||
* @return SearchParameters
|
||||
*/
|
||||
public function setSearchParameters(\DateTime $startDate, \DateTime $endDate, $adultCount, $childCount)
|
||||
{
|
||||
$this->session->set(self::SESSION_VAR_NAME, [
|
||||
'start_date' => $startDate,
|
||||
'end_date' => $endDate,
|
||||
'adultCount' => $adultCount,
|
||||
'childCount' => $childCount
|
||||
]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getSearchParameters()
|
||||
{
|
||||
if (! $this->session->has(self::SESSION_VAR_NAME)) {
|
||||
// Set default values
|
||||
// $startDate = new \DateTime("next monday");
|
||||
// $endDate = new \DateTime("next monday + 4 days");
|
||||
$startDate = new \DateTime("today");
|
||||
$endDate = new \DateTime("today + 1 days");
|
||||
|
||||
$this->setSearchParameters($startDate, $endDate, 1, 0);
|
||||
}
|
||||
|
||||
return $this->session->get(self::SESSION_VAR_NAME);
|
||||
}
|
||||
|
||||
public function clearSearchParameters()
|
||||
{
|
||||
$this->session->remove(self::SESSION_VAR_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime()
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getStartDate()
|
||||
{
|
||||
return $this->getSearchParameters()['start_date'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime()
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getEndDate()
|
||||
{
|
||||
return $this->getSearchParameters()['end_date'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getAdultCount()
|
||||
{
|
||||
return $this->getSearchParameters()['adultCount'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getChildCount()
|
||||
{
|
||||
return $this->getSearchParameters()['childCount'];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user