src/Entity/Discount.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\DiscountRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Gedmo\Mapping\Annotation as Gedmo;
  7. use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity;
  8. use Gedmo\Timestampable\Traits\TimestampableEntity;
  9. use Gedmo\Translatable\Translatable;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Symfony\Component\HttpFoundation\File\File;
  12. use Symfony\Component\HttpFoundation\File\UploadedFile;
  13. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  14. use Symfony\Component\Serializer\Annotation\Groups;
  15. use Symfony\Component\Serializer\Annotation\Ignore;
  16. use App\Entity\Translation\DiscountTranslation;
  17. use App\Entity\UsersDiscounts;
  18. use Symfony\Component\Validator\Constraints as Assert;
  19. /**
  20.  * @ORM\Entity(repositoryClass=DiscountRepository::class)
  21.  * @Gedmo\TranslationEntity(class="App\Entity\Translation\DiscountTranslation")
  22.  * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false,hardDelete=false)
  23.  * @Vich\Uploadable
  24.  */
  25. class Discount implements Translatable
  26. {
  27.     use TimestampableEntity;
  28.     use SetTranslationsTrait;
  29.     public const FIELDS = [
  30.         'title',
  31.         'description'
  32.      ];
  33.     /**
  34.      * @ORM\Id
  35.      * @ORM\GeneratedValue
  36.      * @ORM\Column(type="integer")
  37.      * @Groups("discount:list", "discount:item")
  38.      */
  39.     private $id;
  40.     /**
  41.      * @ORM\Column(type="string", length=255)
  42.      * @Gedmo\Translatable
  43.      * @Groups("discount:list", "discount:item")
  44.      */
  45.     private $title;
  46.     /**
  47.      * @var string
  48.      * @Ignore()
  49.      */
  50.     private $titleEn;
  51.     /**
  52.      * @var string
  53.      * @Ignore()
  54.      */
  55.     private $titleCa;
  56.     /**
  57.      * @ORM\Column(type="text")
  58.      * @Groups("discount:list", "discount:item")
  59.      * @Gedmo\Translatable
  60.      */
  61.     private $description;
  62.     /**
  63.      * @var string
  64.      * @Ignore()
  65.      */
  66.     private $descriptionEn;
  67.     /**
  68.      * @var string
  69.      * @Ignore()
  70.      */
  71.     private $descriptionCa;
  72.     /**
  73.      * @ORM\Column(type="string", length=255, nullable=true)
  74.      * @Groups("discount:list", "discount:item")
  75.      */
  76.     private $url;
  77.     /**
  78.      * @ORM\Column(type="integer")
  79.      * @Ignore()
  80.      */
  81.     private $ticketsNumber;
  82.     /**
  83.      * @Assert\File(
  84.      *     mimeTypes = {"image/jpeg", "image/gif", "image/png", "image/jpg"},
  85.      *     mimeTypesMessage = "Wrong file type (jpeg,gif,png,jpg)"
  86.      * )
  87.      * @Vich\UploadableField(mapping="discount", fileNameProperty="imageName", size="imageSize")
  88.      * @var File|null
  89.      * @Ignore()
  90.      */
  91.     private $imageFile;
  92.     /**
  93.      * @Gedmo\Locale
  94.      */
  95.     private $locale;
  96.     /**
  97.      * @ORM\Column(type="string")
  98.      *
  99.      * @var string|null
  100.      * @Groups("discount:list", "discount:item")
  101.      *
  102.      */
  103.     private $imageName;
  104.     /**
  105.      * @ORM\Column(type="integer")
  106.      *
  107.      * @var int|null
  108.      * @Ignore()
  109.      */
  110.     private $imageSize;
  111.     /**
  112.      * @var \DateTime
  113.      * @ORM\Column(type="datetime")
  114.      * @Groups("discount:list", "discount:item")
  115.      */
  116.     private $expirationDate;
  117.     /**
  118.     * @ORM\OneToMany(
  119.     *   targetEntity="App\Entity\Translation\DiscountTranslation",
  120.     *   mappedBy="object",
  121.     *   cascade={"persist", "remove"}
  122.     * )
  123.      * @Ignore()
  124.     */
  125.     private $translations;
  126.     /**
  127.      * @ORM\Column(type="datetime", nullable=true)
  128.      * @var \DateTime|null
  129.      */
  130.     protected $deletedAt;
  131.     /**
  132.      * @ORM\OneToMany(targetEntity=Award::class, mappedBy="discount")
  133.      */
  134.     private $awards;
  135.     /**
  136.      * Set or clear the deleted at timestamp.
  137.      *
  138.      * @return self
  139.      */
  140.     public function setDeletedAt(\DateTime $deletedAt null)
  141.     {
  142.         $this->deletedAt $deletedAt;
  143.         return $this;
  144.     }
  145.     /**
  146.      * Get the deleted at timestamp value. Will return null if
  147.      * the entity has not been soft deleted.
  148.      *
  149.      * @return \DateTime|null
  150.      */
  151.     public function getDeletedAt()
  152.     {
  153.         return $this->deletedAt;
  154.     }
  155.     public function __construct()
  156.     {
  157.         $this->expirationDate = new \DateTimeImmutable('+1 week');
  158.         $this->translations = new ArrayCollection();
  159.         $this->awards = new ArrayCollection();
  160.     }
  161.     public function getId(): ?int
  162.     {
  163.         return $this->id;
  164.     }
  165.     public function getTitle(): ?string
  166.     {
  167.         return $this->title;
  168.     }
  169.     public function setTitle(string $title): self
  170.     {
  171.         $this->title $title;
  172.         return $this;
  173.     }
  174.     /**
  175.      * @return mixed
  176.      */
  177.     public function getTitleEn()
  178.     {
  179.         return $this->titleEn;
  180.     }
  181.     /**
  182.      * @param string|null $titleEn
  183.      *
  184.      * @return $this
  185.      */
  186.     public function setTitleEn(?string $titleEn): self
  187.     {
  188.         $this->titleEn $titleEn;
  189.         return $this;
  190.     }
  191.     /**
  192.      * @return mixed
  193.      */
  194.     public function getTitleCa()
  195.     {
  196.         return $this->titleCa;
  197.     }
  198.     /**
  199.      * @param string|null $titleCa
  200.      *
  201.      * @return $this
  202.      */
  203.     public function setTitleCa(?string $titleCa): self
  204.     {
  205.         $this->titleCa $titleCa;
  206.         return $this;
  207.     }
  208.     public function getDescription(): ?string
  209.     {
  210.         return $this->description;
  211.     }
  212.     public function setDescription(string $description): self
  213.     {
  214.         $this->description $description;
  215.         return $this;
  216.     }
  217.     public function getTicketsNumber(): ?int
  218.     {
  219.         return $this->ticketsNumber;
  220.     }
  221.     public function setTicketsNumber(int $ticketsNumber): self
  222.     {
  223.         $this->ticketsNumber $ticketsNumber;
  224.         return $this;
  225.     }
  226.     public function setTranslatableLocale($locale)
  227.     {
  228.         $this->locale $locale;
  229.     }
  230.     /**
  231.      * @param File|UploadedFile|null $imageFile
  232.      */
  233.     public function setImageFile(?File $imageFile null): void
  234.     {
  235.         $this->imageFile $imageFile;
  236.         if (null !== $imageFile) {
  237.             $this->updatedAt = new \DateTimeImmutable();
  238.         }
  239.     }
  240.     public function getImageFile(): ?File
  241.     {
  242.         return $this->imageFile;
  243.     }
  244.     public function setImageName(?string $imageName): void
  245.     {
  246.         $this->imageName $imageName;
  247.     }
  248.     public function getImageName(): ?string
  249.     {
  250.         return $this->imageName;
  251.     }
  252.     public function setImageSize(?int $imageSize): void
  253.     {
  254.         $this->imageSize $imageSize;
  255.     }
  256.     public function getImageSize(): ?int
  257.     {
  258.         return $this->imageSize;
  259.     }
  260.     public function getExpirationDate(): ?\DateTimeInterface
  261.     {
  262.         return $this->expirationDate;
  263.     }
  264.     public function setExpirationDate(\DateTimeInterface $expirationDate): self
  265.     {
  266.         $this->expirationDate $expirationDate;
  267.         return $this;
  268.     }
  269.     public function getTranslations()
  270.     {
  271.         return $this->translations;
  272.     }
  273.     public function addTranslation(DiscountTranslation $t)
  274.     {
  275.         if (!$this->translations->contains($t)) {
  276.             $this->translations[] = $t;
  277.             $t->setObject($this);
  278.         }
  279.     }
  280.     /**
  281.      * @return Collection|Award[]
  282.      */
  283.     public function getAwards(): Collection
  284.     {
  285.         return $this->awards;
  286.     }
  287.     public function addAward(Award $award): self
  288.     {
  289.         if (!$this->awards->contains($award)) {
  290.             $this->awards[] = $award;
  291.             $award->setDiscount($this);
  292.         }
  293.         return $this;
  294.     }
  295.     public function removeAward(Award $award): self
  296.     {
  297.         if ($this->awards->removeElement($award)) {
  298.             // set the owning side to null (unless already changed)
  299.             if ($award->getDiscount() === $this) {
  300.                 $award->setDiscount(null);
  301.             }
  302.         }
  303.         return $this;
  304.     }
  305.     /**
  306.      * @return mixed
  307.      */
  308.     public function getUrl()
  309.     {
  310.         return $this->url;
  311.     }
  312.     /**
  313.      * @param mixed $url
  314.      */
  315.     public function setUrl($url): void
  316.     {
  317.         $this->url $url;
  318.     }
  319.     /**
  320.      * @return string|null
  321.      */
  322.     public function getDescriptionCa(): ?string
  323.     {
  324.         return $this->descriptionCa;
  325.     }
  326.     /**
  327.      * @param string|null $descriptionCa
  328.      */
  329.     public function setDescriptionCa(?string $descriptionCa): void
  330.     {
  331.         $this->descriptionCa $descriptionCa;
  332.     }
  333.     /**
  334.      * @return string |null
  335.      */
  336.     public function getDescriptionEn(): ?string
  337.     {
  338.         return $this->descriptionEn;
  339.     }
  340.     /**
  341.      * @param string|null $descriptionEn
  342.      */
  343.     public function setDescriptionEn(?string $descriptionEn): void
  344.     {
  345.         $this->descriptionEn $descriptionEn;
  346.     }
  347. }