Files
sterivein/local/modules/RibClient/Loop/RibClient.php
2020-11-19 15:36:28 +01:00

77 lines
2.6 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: 16/04/2019 00:00
*/
namespace RibClient\Loop;
use RibClient\Model\RibClientQuery;
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;
/**
* @method int getCustomerId()
*/
class RibClient extends BaseLoop implements PropelSearchLoopInterface
{
/**
* @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection
*/
protected function getArgDefinitions()
{
return new ArgumentCollection(
Argument::createIntTypeArgument('customer_id', null, true),
Argument::createAnyTypeArgument('order_date', '')
);
}
public function buildModelCriteria()
{
return RibClientQuery::create()->filterByCustomerId($this->getCustomerId());
}
/**
* @param LoopResult $loopResult
* @return LoopResult
* @throws \Exception
*/
public function parseResults(LoopResult $loopResult)
{
$orderDate = \DateTime::createFromFormat('Y-m-d', $this->getOrderDate());
/** @var \RibClient\Model\RibClient $item */
foreach ($loopResult->getResultDataCollection() as $item) {
$loopResultRow = new LoopResultRow($item);
$loopResultRow
->set('ID' , $item->getId())
->set('ECHEANCE' , $item->getIban())
;
// Calculer la date de paiement
if (false !== $orderDate) {
$datePaiement = $orderDate->add(new \DateInterval("P" . $item->getEcheance() . "D"));
$loopResultRow->set('DATE_PAIEMENT' , $datePaiement);
}
$loopResult->addRow($loopResultRow);
}
return $loopResult;
}
}