Files

93 lines
2.7 KiB
PHP

<?php
namespace PointRetrait\Loop;
use PlanificationLivraison\PlanificationLivraison;
use PointRetrait\Model\PdrScheduleQuery;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
/**
* Class ScheduleLoop
* @package PointRetrait\Loop
*/
class ScheduleLoop extends BaseLoop implements PropelSearchLoopInterface
{
public $countable = false;
public $timestampable = false;
public $versionable = false;
/**
* @param LoopResult $loopResult
*
* @return LoopResult
*/
public function parseResults(LoopResult $loopResult)
{
$theDate = '';
foreach ($loopResult->getResultDataCollection() as $pdr_schedule) {
if (null === $this->getClickAndCollect()) {
$theDate = PlanificationLivraison::calculateRelativeDate($pdr_schedule->getDay(), null);
}
else {
$newDate = PlanificationLivraison::calculateRelativeDate(null, $this->getPlaceId());
if ($theDate == '' || $newDate < $theDate)
$theDate = $newDate;
}
$loopResultRow = new LoopResultRow($pdr_schedule);
$loopResultRow
->set("ID", $pdr_schedule->getId())
->set("PLACE_ID", $pdr_schedule->getIdPlace())
->set("DAY", $pdr_schedule->getDay())
->set("DAY_LABEL", PlanificationLivraison::getDayLabel($pdr_schedule->getDay()))
->set("BEGIN", $pdr_schedule->getBeginTime())
->set("END", $pdr_schedule->getEndTime())
->set("CALCULATED_DAY", PlanificationLivraison::getDayLabel(($theDate->format('w') - 1) % 6) . ' ' . $theDate->format(PlanificationLivraison::FORMAT_DATES))
;
$loopResult->addRow($loopResultRow);
}
return $loopResult;
}
/**
* @inheritdoc
*/
protected function getArgDefinitions()
{
return new ArgumentCollection(
Argument::createIntListTypeArgument('id'),
Argument::createIntListTypeArgument('place_id'),
Argument::createBooleanTypeArgument('click_and_collect', null)
);
}
/**
* @inheritdoc
*/
public function buildModelCriteria()
{
$places = PdrScheduleQuery::create();
if (null != $id = $this->getId()) {
$places->filterById($id);
}
if (null != $id = $this->getPlaceId()) {
$places->filterByIdPlace($id);
}
return $places->orderByDay()->orderByBeginTime();
}
}