Using Symfony2, my date will go one day from my controller to my branch template:
var_dump from the controller (in php) give me the correct date 04/19/2015 dump from the tween template give me 04/18/2015. It drives me crazy!
Controller code
public function displayAction($id)
{
$product = new Product();
$product = $this->getDoctrine()
->getRepository('PurchaseBundle:Product')
->find($id);
foreach($product->getContracts() as $key=>$contract) {
var_dump($contract);
}
$user = $this->get('security.context')->getToken()->getUser();
if (!$this->get('security.context')->getToken()->getUser()->canReadProvider($product->getProvider())) {
throw new AccessDeniedException();
}
$canWrite = $this->get('security.context')->getToken()->getUser()->canWriteProvider($product->getProvider());
return $this->render('PurchaseBundle:Product:display.html.twig', array(
'product'=>$product,
'contracts'=>$product->getContracts(),
'year'=>date('Y'),
'canWrite'=>$canWrite));
}
Twig Template Code
{% for contract in contracts %}
<tr>
<td colspan="5" class="table-2-content">
{{ dump(contract) }}
{% if contract.beginning and contract.end %}
{{contract.beginning|date('d/m/Y')}} au {{contract.end|date('d/m/Y')}}
{% else %}Date invalide{% endif %}
<br />
My contrat object has two start and end dates, the beginning is correct, the end becomes one day younger in the branch than in PHP ...
I also have another page to change this date, in which case both dates are correct.
I am using the old version of Symfony 2.0, Twig is also old, and php is 5.3, and I canβt completely upgrade it.
Product Essence:
<?php
namespace XXX\PurchaseBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Validator\Constraints as Assert;
class Product
{
protected $id;
protected $projectName;
protected $commercialName;
protected $sort;
protected $quotationValue;
protected $comment;
protected $quotationDate;
protected $ttm;
protected $provider;
protected $contracts;
protected $articles;
protected $productFeatures;
protected $classifications;
private $updated;
public function __construct() {
$this->classifications = new ArrayCollection();
$this->productFeatures = new ArrayCollection();
$this->contracts = new ArrayCollection();
$this->articles = new ArrayCollection();
$this->features = new ArrayCollection();
}
public function __toString()
{
return $this->getProjectName();
}
public function getId()
{
return $this->id;
}
public function setProjectName($projectName)
{
$this->projectName = $projectName;
}
public function getProjectName()
{
return $this->projectName;
}
public function setCommercialName($commercialName)
{
$this->commercialName = $commercialName;
}
public function getCommercialName()
{
return $this->commercialName;
}
public function setQuotationValue($quotationValue)
{
$this->quotationValue = $quotationValue;
}
public function getQuotationValue()
{
return (float) $this->quotationValue;
}
public function setComment($comment)
{
$this->comment = $comment;
}
public function getComment()
{
return $this->comment;
}
public function setQuotationDate($quotationDate)
{
$this->quotationDate = $quotationDate;
}
public function getQuotationDate()
{
return $this->quotationDate;
}
public function setProvider(\XXX\PurchaseBundle\Entity\Provider $provider)
{
$this->provider = $provider;
}
public function getProvider()
{
return $this->provider;
}
public function addClassification(\XXX\PurchaseBundle\Entity\Classification $classifications)
{
$this->classifications[] = $classifications;
}
public function removeClassification(\XXX\PurchaseBundle\Entity\Classification $classification)
{
$this->classifications->removeElement($classification);
}
public function getClassifications()
{
return $this->classifications;
}
public function getClassificationBudgetByPeriod($period)
{
if(!$period || strlen($period) != 7)
return '';
$array = explode(' ', $period);
foreach($this->getClassifications() as $classification) {
if($classification->getYear() == intval($array[1])) {
if($array[0] == 'Q1')
return $classification->getBudgetQ1();
if($array[0] == 'Q2')
return $classification->getBudgetQ2();
if($array[0] == 'Q3')
return $classification->getBudgetQ3();
if($array[0] == 'Q4')
return $classification->getBudgetQ4();
}
}
return '';
}
public function addContract(\XXX\PurchaseBundle\Entity\Contract $contracts)
{
$this->contracts[] = $contracts;
}
public function getContracts()
{
return $this->contracts;
}
public function getContractAt($period)
{
$s = $period[0];
$e = $period[1];
foreach($this->contracts as $contract) {
if(($contract->getEnd() >= $e and $contract->getBeginning() <= $e)
or ($contract->getEnd() < $e and $contract->getEnd() > $s)) {
return $contract;
}
}
return null;
}
public function addArticle(\XXX\PurchaseBundle\Entity\Article $articles)
{
$this->articles[] = $articles;
}
public function getArticles()
{
return $this->articles;
}
public function addProductFeature(\XXX\PurchaseBundle\Entity\ProductFeature $productFeatures)
{
$this->productFeatures[] = $productFeatures;
}
public function getProductFeatures()
{
return $this->productFeatures;
}
public function getProductFeatureByCode($code)
{
foreach($this->productFeatures as $pf) {
if($pf->getFeature()->getCode() == $code) {
return $pf;
}
}
return false;
}
public function setType($type)
{
$this->type = $type;
}
public function getType()
{
return $this->type;
}
public function setSort(\XXX\PurchaseBundle\Entity\ProductSort $sort)
{
$this->sort = $sort;
}
public function getSort()
{
return $this->sort;
}
public function setUpdated($updated)
{
$this->updated = $updated;
}
public function getUpdated()
{
return $this->updated;
}
public function setTtm($ttm)
{
$this->ttm = $ttm;
}
public function getTtm()
{
return $this->ttm;
}
}
Contract:
<?php
namespace XXX\PurchaseBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
class Contract
{
private $id;
private $billPrice;
private $supplierWeekPrice;
private $upchargeSav;
private $privateCopyingLevyValue;
private $d3e;
private $boatDiscount;
private $ecotaxe;
private $srelec;
private $otherTaxes;
private $beginning;
private $end;
protected $product;
protected $marketingFundRebate;
protected $XXXSecurisedRebate;
protected $XXXConditionalRebate;
protected $vodafoneSecurisedRebate;
protected $vodafoneConditionalRebate;
public function getId()
{
return $this->id;
}
public function setSupplierWeekPrice($supplierWeekPrice)
{
$this->supplierWeekPrice = $supplierWeekPrice;
}
public function getSupplierWeekPrice()
{
return (float) $this->supplierWeekPrice;
}
public function setUpchargeSav($upchargeSav)
{
$this->upchargeSav = $upchargeSav;
}
public function getUpchargeSav()
{
return (float) $this->upchargeSav;
}
public function setPrivateCopyingLevyValue($privateCopyingLevyValue)
{
$this->privateCopyingLevyValue = $privateCopyingLevyValue;
}
public function getPrivateCopyingLevyValue()
{
return (float) $this->privateCopyingLevyValue;
}
public function setD3e($d3e)
{
$this->d3e = $d3e;
}
public function getD3e()
{
return (float) $this->d3e;
}
public function setBoatDiscount($boatDiscount)
{
$this->boatDiscount = $boatDiscount;
}
public function getBoatDiscount()
{
return (float) $this->boatDiscount;
}
public function setOtherTaxes($otherTaxes)
{
$this->otherTaxes = $otherTaxes;
}
public function getOtherTaxes()
{
return (float) $this->otherTaxes;
}
public function setEcotaxe($ecotaxe)
{
$this->ecotaxe = $ecotaxe;
}
public function getEcotaxe()
{
return (float) $this->ecotaxe;
}
public function setScotaxe($srelec)
{
$this->srelec = $srelec;
}
public function getSrelec()
{
return (float) $this->srelec;
}
public function setBeginning($beginning)
{
$this->beginning = $beginning;
}
public function getBeginning()
{
return $this->beginning;
}
public function setEnd($end)
{
$this->end = $end;
}
public function getEnd()
{
return $this->end;
}
public function setProduct(\XXX\PurchaseBundle\Entity\Product $product)
{
$this->product = $product;
}
public function getProduct()
{
return $this->product;
}
public function setBillPrice($billPrice)
{
$this->billPrice = $billPrice;
}
public function getBillPrice()
{
return (float) $this->billPrice;
}
public function setMarketingFundRebate($marketingFundRebate)
{
$this->marketingFundRebate = $marketingFundRebate;
}
public function getMarketingFundRebate()
{
return $this->marketingFundRebate;
}
public function setXXXSecurisedRebate($XXXSecurisedRebate)
{
$this->XXXSecurisedRebate = $XXXSecurisedRebate;
}
public function getXXXSecurisedRebate()
{
return $this->XXXSecurisedRebate;
}
public function setXXXConditionalRebate($XXXConditionalRebate)
{
$this->XXXConditionalRebate = $XXXConditionalRebate;
}
public function getXXXConditionalRebate()
{
return $this->XXXConditionalRebate;
}
public function setVodafoneSecurisedRebate($vodafoneSecurisedRebate)
{
$this->vodafoneSecurisedRebate = $vodafoneSecurisedRebate;
}
public function getVodafoneSecurisedRebate()
{
return $this->vodafoneSecurisedRebate;
}
public function setVodafoneConditionalRebate($vodafoneConditionalRebate)
{
$this->vodafoneConditionalRebate = $vodafoneConditionalRebate;
}
public function getVodafoneConditionalRebate()
{
return $this->vodafoneConditionalRebate;
}
public function setSrelec($srelec)
{
$this->srelec = $srelec;
}
}
source
share