<?php
namespace App\Entity\Feed;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Advert
*
* @ORM\Table(name="tam_adverts")
* @ORM\Entity(repositoryClass="App\Repository\Feed\AdvertRepository")
* @ORM\HasLifecycleCallbacks
*/
class Advert
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Feed\FeedElement", inversedBy="advert", cascade={"persist", "remove"})
* @ORM\JoinColumn(name="feed_element", referencedColumnName="id", onDelete="CASCADE", nullable=false)
*/
private $feedElement;
/**
* @var \App\Entity\Product
*
* @ORM\ManyToOne(targetEntity="\App\Entity\Product", fetch="EAGER", inversedBy="adverts")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="product", referencedColumnName="id", onDelete="SET NULL")
* })
*/
private $product;
/**
* @var float
*
* @ORM\Column(name="rate_currency", type="float", precision=5, scale=2, nullable=true)
*/
private $rateCurrency;
/**
* @var \DateTime
*
* @ORM\Column(name="date_begin", type="date", nullable=true)
*/
private $dateBegin;
/**
* @var \DateTime
*
* @ORM\Column(name="date_end", type="date", nullable=true)
*/
private $dateEnd;
/**
* @var \DateTime
*
* @ORM\Column(name="date_begin_publication", type="date", nullable=false)
*/
private $dateBeginPublication;
/**
* @var \DateTime
*
* @ORM\Column(name="date_end_publication", type="date", nullable=false)
*/
private $dateEndPublication;
/**
* @var string
*
* @ORM\Column(name="link_url", type="string", length=255, nullable=true)
*/
private $linkUrl;
public function __construct()
{
$this->dateBeginPublication = new \DateTime();
}
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set feedElement
*
* @param FeedElement $feedElement
*
* @return Advert
*/
public function setFeedElement($feedElement)
{
$this->feedElement = $feedElement;
$feedElement->setAdvert($this);
return $this;
}
/**
* Get feedElement
*
* @return FeedElement
*/
public function getFeedElement()
{
return $this->feedElement;
}
/**
* Set product
*
* @param Product $product
*
* @return Advert
*/
public function setProduct($product)
{
$this->product = $product;
return $this;
}
/**
* Get product
*
* @return Advert
*/
public function getProduct()
{
return $this->product;
}
/**
* Set rateCurrency
*
* @param float $rateCurrency
*
* @return Advert
*/
public function setRateCurrency($rateCurrency)
{
if($rateCurrency == "")
$this->rateCurrency = null;
else
$this->rateCurrency = str_replace(",", ".", $rateCurrency);
return $this;
}
/**
* Get rateCurrency
*
* @return float
*/
public function getRateCurrency()
{
return $this->rateCurrency;
}
/**
* Set dateBegin
*
* @param \DateTime $dateBegin
*
* @return Advert
*/
public function setDateBegin($dateBegin)
{
$this->dateBegin = $dateBegin;
return $this;
}
/**
* Get dateBegin
*
* @return \DateTime
*/
public function getDateBegin()
{
return $this->dateBegin;
}
/**
* Set dateEnd
*
* @param \DateTime $dateEnd
*
* @return Advert
*/
public function setDateEnd($dateEnd)
{
$this->dateEnd = $dateEnd;
return $this;
}
/**
* Get dateEnd
*
* @return \DateTime
*/
public function getDateEnd()
{
return $this->dateEnd;
}
/**
* Set dateBeginPublication
*
* @param \DateTime $dateBeginPublication
*
* @return Advert
*/
public function setDateBeginPublication($dateBeginPublication)
{
$this->dateBeginPublication = $dateBeginPublication;
return $this;
}
/**
* Get dateBeginPublication
*
* @return \DateTime
*/
public function getDateBeginPublication()
{
return $this->dateBeginPublication;
}
/**
* Set dateEndPublication
*
* @param \DateTime $dateEndPublication
*
* @return Advert
*/
public function setDateEndPublication($dateEndPublication)
{
$this->dateEndPublication = $dateEndPublication;
return $this;
}
/**
* Get dateEndPublication
*
* @return \DateTime
*/
public function getDateEndPublication()
{
return $this->dateEndPublication;
}
/**
* Set linkUrl
*
* @param string $linkUrl
*
* @return Advert
*/
public function setLinkUrl($linkUrl)
{
$this->linkUrl = $linkUrl;
return $this;
}
/**
* Get linkUrl
*
* @return string
*/
public function getLinkUrl()
{
return $this->linkUrl;
}
/***********************
* Lifecycle Callbacks
***********************/
/**
*
* @ORM\PrePersist()
* @ORM\PreUpdate()
*/
public function preUpdate()
{
//$this->setDateUpdated(new \DateTime());
}
/***********************
* OTHER FUNCTION
***********************/
public function getArrayForJson($schemeAndBaseURL, $friend = false){
$array = array();
$array['id'] = $this->getId();
if($this->getDateBegin()){
$array['dateBegin'] = $this->getDateBegin()->format("Y-m-d\TH:i:sP");
}
if($this->getDateEnd()){
$array['dateEnd'] = $this->getDateEnd()->format("Y-m-d\TH:i:sP");
}
$array['dateBeginPublication'] = $this->getDateBeginPublication()->format("Y-m-d\TH:i:sP");
$array['dateEndPublication'] = $this->getDateEndPublication()->format("Y-m-d\TH:i:sP");
$array['linkUrl'] = $this->getLinkUrl();
return $array;
}
}