73 lines
2.0 KiB
PHP
73 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace PlanificationLivraison\Loop;
|
|
|
|
use DateTime;
|
|
use PlanificationLivraison\Model\OrderDeliveryScheduleQuery;
|
|
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 ScheduledDeliveriesLoop
|
|
* @package PlanificationLivraison\Loop
|
|
*/
|
|
class ScheduledDeliveriesLoop extends BaseLoop implements PropelSearchLoopInterface
|
|
{
|
|
public $countable = true;
|
|
|
|
|
|
/**
|
|
* @param LoopResult $loopResult
|
|
*
|
|
* @return LoopResult
|
|
*/
|
|
public function parseResults(LoopResult $loopResult)
|
|
{
|
|
foreach ($loopResult->getResultDataCollection() as $deliveries) {
|
|
|
|
$loopResultRow = new LoopResultRow($deliveries);
|
|
|
|
$delta = date_diff($deliveries->getDueDeliveryTimeStart(), new DateTime("now"));
|
|
|
|
$loopResultRow
|
|
->set("ORDER_ID", $deliveries->getOrderId())
|
|
->set("START_DATE", $deliveries->getDueDeliveryTimeStart())
|
|
->set("END_DATE", $deliveries->getDueDeliveryTimeEnd())
|
|
->set("DELTA", $delta->days)
|
|
->set("SCHEDULE_ID", $deliveries->getScheduleId())
|
|
;
|
|
$loopResult->addRow($loopResultRow);
|
|
}
|
|
return $loopResult;
|
|
}
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
protected function getArgDefinitions()
|
|
{
|
|
return new ArgumentCollection(
|
|
Argument::createEnumListTypeArgument('order', [
|
|
'date',
|
|
'date-reverse'
|
|
], 'date')
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public function buildModelCriteria()
|
|
{
|
|
$deliveries = OrderDeliveryScheduleQuery::create();
|
|
$deliveries->filterByDueDeliveryTimeStart(array('min' => time()))->find();
|
|
|
|
return $deliveries->orderByDueDeliveryTimeStart();
|
|
}
|
|
|
|
}
|