src/Entity/Feed/Advert.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Feed;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Symfony\Component\Validator\Constraints as Assert;
  6. /**
  7.  * Advert
  8.  *
  9.  * @ORM\Table(name="tam_adverts")
  10.  * @ORM\Entity(repositoryClass="App\Repository\Feed\AdvertRepository")
  11.  * @ORM\HasLifecycleCallbacks
  12.  */
  13. class Advert
  14. {
  15.     /**
  16.      * @var int
  17.      *
  18.      * @ORM\Column(name="id", type="integer")
  19.      * @ORM\Id
  20.      * @ORM\GeneratedValue(strategy="IDENTITY")
  21.      */
  22.     private $id;
  23.     
  24.     /**
  25.      * @ORM\OneToOne(targetEntity="App\Entity\Feed\FeedElement", inversedBy="advert", cascade={"persist", "remove"})
  26.      * @ORM\JoinColumn(name="feed_element", referencedColumnName="id",  onDelete="CASCADE", nullable=false)
  27.      */
  28.     private $feedElement;
  29.     
  30.     /**
  31.      * @var \App\Entity\Product
  32.      *
  33.      * @ORM\ManyToOne(targetEntity="\App\Entity\Product", fetch="EAGER", inversedBy="adverts")
  34.      * @ORM\JoinColumns({
  35.      *   @ORM\JoinColumn(name="product", referencedColumnName="id", onDelete="SET NULL")
  36.      * })
  37.      */
  38.     private $product;
  39.     
  40.     /**
  41.      * @var float
  42.      *
  43.      * @ORM\Column(name="rate_currency", type="float", precision=5, scale=2, nullable=true)
  44.      */
  45.     private $rateCurrency;
  46.     
  47.     /**
  48.      * @var \DateTime
  49.      *
  50.      * @ORM\Column(name="date_begin", type="date", nullable=true)
  51.      */
  52.     private $dateBegin;
  53.     
  54.     /**
  55.      * @var \DateTime
  56.      *
  57.      * @ORM\Column(name="date_end", type="date", nullable=true)
  58.      */
  59.     private $dateEnd;
  60.     
  61.     /**
  62.      * @var \DateTime
  63.      *
  64.      * @ORM\Column(name="date_begin_publication", type="date", nullable=false)
  65.      */
  66.     private $dateBeginPublication;
  67.     
  68.     /**
  69.      * @var \DateTime
  70.      *
  71.      * @ORM\Column(name="date_end_publication", type="date", nullable=false)
  72.      */
  73.     private $dateEndPublication;
  74.     
  75.     /**
  76.      * @var string
  77.      *
  78.      * @ORM\Column(name="link_url", type="string", length=255, nullable=true)
  79.      */
  80.     private $linkUrl;
  81.     
  82.     
  83.     public function __construct()
  84.     {
  85.        
  86.         $this->dateBeginPublication = new \DateTime();
  87.     }
  88.     /**
  89.      * Get id
  90.      *
  91.      * @return int
  92.      */
  93.     public function getId()
  94.     {
  95.         return $this->id;
  96.     }
  97.     
  98.     /**
  99.      * Set feedElement
  100.      *
  101.      * @param FeedElement $feedElement
  102.      *
  103.      * @return Advert
  104.      */
  105.     public function setFeedElement($feedElement)
  106.     {
  107.         $this->feedElement $feedElement;
  108.         $feedElement->setAdvert($this);
  109.         return $this;
  110.     }
  111.     /**
  112.      * Get feedElement
  113.      *
  114.      * @return FeedElement
  115.      */
  116.     public function getFeedElement()
  117.     {
  118.         return $this->feedElement;
  119.     }
  120.     
  121.     /**
  122.      * Set product
  123.      *
  124.      * @param Product $product
  125.      *
  126.      * @return Advert
  127.      */
  128.     public function setProduct($product)
  129.     {
  130.         $this->product $product;
  131.         return $this;
  132.     }
  133.     /**
  134.      * Get product
  135.      *
  136.      * @return Advert
  137.      */
  138.     public function getProduct()
  139.     {
  140.         return $this->product;
  141.     }
  142.     
  143.     /**
  144.      * Set rateCurrency
  145.      *
  146.      * @param float $rateCurrency
  147.      *
  148.      * @return Advert
  149.      */
  150.     public function setRateCurrency($rateCurrency)
  151.     {
  152.         if($rateCurrency == "")
  153.             $this->rateCurrency null;
  154.         else
  155.             $this->rateCurrency str_replace(",""."$rateCurrency);
  156.         return $this;
  157.     }
  158.     /**
  159.      * Get rateCurrency
  160.      *
  161.      * @return float
  162.      */
  163.     public function getRateCurrency()
  164.     {
  165.         return $this->rateCurrency;
  166.     }
  167.     
  168.     /**
  169.      * Set dateBegin
  170.      *
  171.      * @param \DateTime $dateBegin
  172.      *
  173.      * @return Advert
  174.      */
  175.     public function setDateBegin($dateBegin)
  176.     {
  177.         $this->dateBegin $dateBegin;
  178.         return $this;
  179.     }
  180.     /**
  181.      * Get dateBegin
  182.      *
  183.      * @return \DateTime
  184.      */
  185.     public function getDateBegin()
  186.     {
  187.         return $this->dateBegin;
  188.     }
  189.     
  190.     /**
  191.      * Set dateEnd
  192.      *
  193.      * @param \DateTime $dateEnd
  194.      *
  195.      * @return Advert
  196.      */
  197.     public function setDateEnd($dateEnd)
  198.     {
  199.         $this->dateEnd $dateEnd;
  200.         return $this;
  201.     }
  202.     /**
  203.      * Get dateEnd
  204.      *
  205.      * @return \DateTime
  206.      */
  207.     public function getDateEnd()
  208.     {
  209.         return $this->dateEnd;
  210.     }
  211.     
  212.     /**
  213.      * Set dateBeginPublication
  214.      *
  215.      * @param \DateTime $dateBeginPublication
  216.      *
  217.      * @return Advert
  218.      */
  219.     public function setDateBeginPublication($dateBeginPublication)
  220.     {
  221.         $this->dateBeginPublication $dateBeginPublication;
  222.         return $this;
  223.     }
  224.     /**
  225.      * Get dateBeginPublication
  226.      *
  227.      * @return \DateTime
  228.      */
  229.     public function getDateBeginPublication()
  230.     {
  231.         return $this->dateBeginPublication;
  232.     }
  233.     
  234.     /**
  235.      * Set dateEndPublication
  236.      *
  237.      * @param \DateTime $dateEndPublication
  238.      *
  239.      * @return Advert
  240.      */
  241.     public function setDateEndPublication($dateEndPublication)
  242.     {
  243.         $this->dateEndPublication $dateEndPublication;
  244.         return $this;
  245.     }
  246.     /**
  247.      * Get dateEndPublication
  248.      *
  249.      * @return \DateTime
  250.      */
  251.     public function getDateEndPublication()
  252.     {
  253.         return $this->dateEndPublication;
  254.     }
  255.     
  256.     /**
  257.      * Set linkUrl
  258.      *
  259.      * @param string $linkUrl
  260.      *
  261.      * @return Advert
  262.      */
  263.     public function setLinkUrl($linkUrl)
  264.     {
  265.         $this->linkUrl $linkUrl;
  266.         return $this;
  267.     }
  268.     /**
  269.      * Get linkUrl
  270.      *
  271.      * @return string
  272.      */
  273.     public function getLinkUrl()
  274.     {
  275.         return $this->linkUrl;
  276.     }
  277.         
  278.     
  279.     /***********************
  280.      * Lifecycle Callbacks
  281.      ***********************/
  282.      
  283.     /**
  284.      *
  285.      * @ORM\PrePersist()
  286.      * @ORM\PreUpdate()
  287.      */
  288.     public function preUpdate()
  289.     {
  290.         //$this->setDateUpdated(new \DateTime());
  291.     }
  292.     
  293.     
  294.     /***********************
  295.      * OTHER FUNCTION
  296.      ***********************/
  297.      
  298.      
  299.      
  300.      public function getArrayForJson($schemeAndBaseURL$friend false){
  301.         $array = array();
  302.         $array['id'] = $this->getId();
  303.         if($this->getDateBegin()){
  304.             $array['dateBegin'] = $this->getDateBegin()->format("Y-m-d\TH:i:sP");
  305.         }
  306.         if($this->getDateEnd()){
  307.             $array['dateEnd'] = $this->getDateEnd()->format("Y-m-d\TH:i:sP");
  308.         }
  309.         $array['dateBeginPublication'] = $this->getDateBeginPublication()->format("Y-m-d\TH:i:sP");
  310.         $array['dateEndPublication'] = $this->getDateEndPublication()->format("Y-m-d\TH:i:sP");
  311.         $array['linkUrl'] = $this->getLinkUrl();
  312.         
  313.         return $array;
  314.         
  315.     }
  316.     
  317.     
  318. }