src/Entity/Promotions/NationalPromotion.php line 33

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Promotions;
  3. use App\Annotation\SiteAware;
  4. use App\Entity\AbstractBase;
  5. use App\Entity\Garages\Garage;
  6. use App\Entity\Interfaces\Image2Interface;
  7. use App\Entity\Interfaces\ImageInterface;
  8. use App\Entity\Interfaces\SiteInterface;
  9. use App\Entity\MediaLibrary\CooperativeMedia;
  10. use App\Entity\Traits\HasImage2Trait;
  11. use App\Entity\Traits\HasImageTrait;
  12. use App\Entity\Traits\NameTrait;
  13. use App\Entity\Traits\PublishedTrait;
  14. use App\Entity\Traits\SiteTrait;
  15. use App\Repository\Promotions\NationalPromotionRepository;
  16. use DateTime;
  17. use Doctrine\Common\Collections\ArrayCollection;
  18. use Doctrine\Common\Collections\Collection;
  19. use Doctrine\ORM\Mapping as ORM;
  20. use Gedmo\Mapping\Annotation as Gedmo;
  21. use Symfony\Component\HttpFoundation\File\File;
  22. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  23. /**
  24.  * @ORM\Table(name="vulco_national_promotion_v2", indexes={@ORM\Index(name="national_promotion_v2_site_idx", columns={"site"})})
  25.  * @ORM\Entity(repositoryClass=NationalPromotionRepository::class)
  26.  * @Gedmo\SoftDeleteable(fieldName="removedAt", timeAware=false)
  27.  * @SiteAware(siteFieldName="site")
  28.  * @Vich\Uploadable
  29.  */
  30. class NationalPromotion extends AbstractBase implements ImageInterfaceImage2InterfaceSiteInterface
  31. {
  32.     use HasImageTrait;
  33.     use HasImage2Trait;
  34.     use NameTrait;
  35.     use SiteTrait;
  36.     use PublishedTrait;
  37.     /**
  38.      * @ORM\Column(type="string", length=255, nullable=false)
  39.      */
  40.     private string $name;
  41.     /**
  42.      * @ORM\Column(type="datetime")
  43.      */
  44.     private \DateTimeInterface $begin;
  45.     /**
  46.      * @ORM\Column(type="datetime")
  47.      */
  48.     private \DateTimeInterface $end;
  49.     /**
  50.      * @ORM\Column(type="text", length=10000, nullable=true)
  51.      */
  52.     private ?string $link null;
  53.     /**
  54.      * @Vich\UploadableField(mapping="national_promotion_image", fileNameProperty="imageName")
  55.      */
  56.     private ?File $image null;
  57.     /**
  58.      * @Vich\UploadableField(mapping="national_promotion_image", fileNameProperty="image2Name")
  59.      */
  60.     private ?File $image2 null;
  61.     /**
  62.      * @ORM\ManyToOne(targetEntity="App\Entity\MediaLibrary\CooperativeMedia")
  63.      * @ORM\JoinColumn(name="cooperative_media_id", referencedColumnName="id")
  64.      */
  65.     private ?CooperativeMedia $cooperativeMedia null;
  66.     /**
  67.      * @ORM\ManyToMany(targetEntity="App\Entity\Garages\Garage", cascade={"persist"})
  68.      *
  69.      * @ORM\JoinTable(name="vulco_national_promotion_v2_garage",
  70.      *     joinColumns={@ORM\JoinColumn(name="national_promotion_id", referencedColumnName="id")},
  71.      *     inverseJoinColumns={@ORM\JoinColumn(name="garage_id", referencedColumnName="id")}
  72.      * )
  73.      */
  74.     private ?Collection $garages;
  75.     public function __construct()
  76.     {
  77.         $this->garages = new ArrayCollection();
  78.     }
  79.     public function getBegin(): \DateTimeInterface
  80.     {
  81.         return $this->begin;
  82.     }
  83.     public function setBegin(\DateTimeInterface $begin): self
  84.     {
  85.         $this->begin $begin;
  86.         return $this;
  87.     }
  88.     public function getEnd(): \DateTimeInterface
  89.     {
  90.         return $this->end;
  91.     }
  92.     public function setEnd(\DateTimeInterface $end): self
  93.     {
  94.         $this->end $end;
  95.         return $this;
  96.     }
  97.     public function getLink(): ?string
  98.     {
  99.         return $this->link;
  100.     }
  101.     public function setLink(?string $link): self
  102.     {
  103.         $this->link $link;
  104.         return $this;
  105.     }
  106.     public function getGarages(): ?Collection
  107.     {
  108.         return $this->garages;
  109.     }
  110.     public function setGarages(?Collection $garages): self
  111.     {
  112.         $this->garages $garages;
  113.         return $this;
  114.     }
  115.     public function addGarage(Garage $garage): self
  116.     {
  117.         if (!$this->garages->contains($garage)) {
  118.             $this->garages->add($garage);
  119.         }
  120.         return $this;
  121.     }
  122.     public function removeGarage(Garage $garage): self
  123.     {
  124.         if ($this->garages->contains($garage)) {
  125.             $this->garages->removeElement($garage);
  126.         }
  127.         return $this;
  128.     }
  129.     public function getCooperativeMedia(): ?CooperativeMedia
  130.     {
  131.         return $this->cooperativeMedia;
  132.     }
  133.     public function setCooperativeMedia(?CooperativeMedia $cooperativeMedia): self
  134.     {
  135.         $this->cooperativeMedia $cooperativeMedia;
  136.         return $this;
  137.     }
  138.     public function isActive(): bool
  139.     {
  140.         $now = new \DateTime();
  141.         $nowStr $now->format('d-m-Y');
  142.         if ($this->getBegin()) {
  143.             $beginStr $this->getBegin()->format('d-m-Y');
  144.         } else {
  145.             return false;
  146.         }
  147.         if ($this->getEnd()) {
  148.             $endStr $this->getEnd()->format('d-m-Y');
  149.         } else {
  150.             return false;
  151.         }
  152.         return strtotime($beginStr) <= strtotime($nowStr) && strtotime($nowStr) <= strtotime($endStr) && $this->isPublished();
  153.     }
  154. }