src/Entity/Banner.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\BannerRepository;
  4. use DateTime;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Gedmo\Mapping\Annotation as Gedmo;
  7. use Gedmo\Timestampable\Traits\TimestampableEntity;
  8. use Gedmo\Translatable\Translatable;
  9. use Symfony\Component\HttpFoundation\File\File;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. use Symfony\Component\Serializer\Annotation\Ignore;
  12. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  13. use Doctrine\Common\Collections\ArrayCollection;
  14. use App\Entity\Translation\BannerTranslation;
  15. use Symfony\Component\Validator\Constraints as Assert;
  16. /**
  17.  * @ORM\Entity(repositoryClass=BannerRepository::class)
  18.  * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false,hardDelete=false)
  19.  * @Gedmo\TranslationEntity(class="App\Entity\Translation\BannerTranslation")
  20.  * @Vich\Uploadable
  21.  */
  22. class Banner implements Translatable
  23. {
  24.     use TimestampableEntity;
  25.     use SetTranslationsTrait;
  26.     public const FIELDS = [
  27.         'title',
  28.         'url'
  29.      ];
  30.     public const FIELDS_NO_FALLBACK = [
  31.         'url'
  32.     ];
  33.     /**
  34.      * @ORM\Id
  35.      * @ORM\GeneratedValue
  36.      * @ORM\Column(type="integer")
  37.      * @Groups("banner:list", "banner:item")
  38.      */
  39.     private $id;
  40.     /**
  41.      * @ORM\Column(type="string", length=255)
  42.      * @Gedmo\Translatable
  43.      * @Groups("banner:list", "banner:item")
  44.      */
  45.     private ?string $title;
  46.     /**
  47.      * @var string | null
  48.      * @Ignore()
  49.      */
  50.     private ?string $titleEn null;
  51.     /**
  52.      * @var string | null
  53.      * @Ignore()
  54.      */
  55.     private ?string $titleCa null;
  56.     /**
  57.      * @ORM\Column(type="boolean")
  58.      * @Groups("banner:list", "banner:item")
  59.      */
  60.     private bool $enabled;
  61.     /**
  62.      * @ORM\Column(type="string", length=255, nullable=true)
  63.      * @Groups("banner:list", "banner:item")
  64.      */
  65.     private ?string $navigate;
  66.     /**
  67.      * @var string
  68.      * @Groups("banner:list", "banner:item")
  69.      */
  70.     private $image;
  71.     /**
  72.      * @ORM\Column(type="string")
  73.      * @Groups("banner:list", "banner:item")
  74.      * @var string|null
  75.      *
  76.      */
  77.     private ?string $imageName null;
  78.     /**
  79.      * @ORM\Column(type="integer")
  80.      *
  81.      * @var int|null
  82.      * @Ignore()
  83.      */
  84.     private ?int $imageSize null;
  85.     /**
  86.      * @ORM\Column(type="string", length=255, nullable=true)
  87.      * @Gedmo\Translatable
  88.      * @Groups("banner:list", "banner:item")
  89.      */
  90.     private ?string $url null;
  91.     /**
  92.      * @var string | null
  93.      * @Ignore()
  94.      */
  95.     private ?string $urlEn null;
  96.     /**
  97.      * @var string | null
  98.      * @Ignore()
  99.      */
  100.     private ?string $urlCa null;
  101.     /**
  102.     * @ORM\OneToMany(
  103.     *   targetEntity="App\Entity\Translation\BannerTranslation",
  104.     *   mappedBy="object",
  105.     *   cascade={"persist", "remove"}
  106.     * )
  107.      * @Ignore()
  108.     */
  109.     private $translations;
  110.     /**
  111.      * @Assert\File(
  112.      *     mimeTypes = {"image/jpeg", "image/gif", "image/png", "image/jpg"},
  113.      *     mimeTypesMessage = "Wrong file type (jpeg,gif,png,jpg)"
  114.      * )
  115.      * @Vich\UploadableField(mapping="banner", fileNameProperty="imageName", size="imageSize")
  116.      * @var File|null
  117.      * @Ignore()
  118.      */
  119.     private ?File $imageFile null;
  120.     /**
  121.      * @ORM\Column(type="datetime", nullable=true)
  122.      * @var DateTime|null
  123.      */
  124.     protected ?DateTime $deletedAt;
  125.     /**
  126.      * @ORM\Column(type="string", nullable=true)
  127.      * @var string|null
  128.      * @Ignore()
  129.      */
  130.     private ?string $imageNameEn null;
  131.     /**
  132.      * @ORM\Column(type="integer", nullable=true)
  133.      *
  134.      * @var int|null
  135.      * @Ignore()
  136.      */
  137.     private ?int $imageSizeEn;
  138.     /**
  139.      * @Assert\File(
  140.      *     mimeTypes = {"image/jpeg", "image/gif", "image/png", "image/jpg"},
  141.      *     mimeTypesMessage = "Wrong file type (jpeg,gif,png,jpg)"
  142.      * )
  143.      * @Vich\UploadableField(mapping="banner", fileNameProperty="imageNameEn", size="imageSizeEn")
  144.      * @var File|null
  145.      * @Ignore()
  146.      */
  147.     private ?File $imageFileEn null;
  148.     /**
  149.      * @ORM\Column(type="string", nullable=true)
  150.      * @var string|null
  151.      * @Ignore()
  152.      */
  153.     private ?string $imageNameCa null;
  154.     /**
  155.      * @ORM\Column(type="integer", nullable=true)
  156.      *
  157.      * @var int|null
  158.      * @Ignore()
  159.      */
  160.     private ?int $imageSizeCa;
  161.     /**
  162.      * @Assert\File(
  163.      *     mimeTypes = {"image/jpeg", "image/gif", "image/png", "image/jpg"},
  164.      *     mimeTypesMessage = "Wrong file type (jpeg,gif,png,jpg)"
  165.      * )
  166.      * @Vich\UploadableField(mapping="banner", fileNameProperty="imageNameCa", size="imageSizeCa")
  167.      * @var File|null
  168.      * @Ignore()
  169.      */
  170.     private ?File $imageFileCa null;
  171.     /**
  172.      * @ORM\Column(type="string", length=100, nullable=true)
  173.      */
  174.     private ?string $buttonName;
  175.     /**
  176.      * Set or clear the deleted at timestamp.
  177.      *
  178.      * @param DateTime|null $deletedAt
  179.      * @return self
  180.      */
  181.     public function setDeletedAt(?DateTime $deletedAt null): self
  182.     {
  183.         $this->deletedAt $deletedAt;
  184.         return $this;
  185.     }
  186.     /**
  187.      * Get the deleted at timestamp value. Will return null if
  188.      * the entity has not been soft deleted.
  189.      *
  190.      * @return DateTime|null
  191.      */
  192.     public function getDeletedAt(): ?DateTime
  193.     {
  194.         return $this->deletedAt;
  195.     }
  196.     /**
  197.      * Banner constructor.
  198.      */
  199.     public function __construct()
  200.     {
  201.         $this->image $this;
  202.         $this->enabled true;
  203.         $this->translations = new ArrayCollection();
  204.     }
  205.     public function getId(): ?int
  206.     {
  207.         return $this->id;
  208.     }
  209.     public function getTitle(): ?string
  210.     {
  211.         return $this->title;
  212.     }
  213.     public function setTitle(string $title): self
  214.     {
  215.         $this->title $title;
  216.         return $this;
  217.     }
  218.     /**
  219.      * @return string | null
  220.      */
  221.     public function getTitleEn(): ?string
  222.     {
  223.         return $this->titleEn;
  224.     }
  225.     /**
  226.      * @param string|null $titleEn
  227.      *
  228.      * @return $this
  229.      */
  230.     public function setTitleEn(?string $titleEn): self
  231.     {
  232.         $this->titleEn $titleEn;
  233.         return $this;
  234.     }
  235.     /**
  236.      * @return string|null
  237.      */
  238.     public function getTitleCa(): ?string
  239.     {
  240.         return $this->titleCa;
  241.     }
  242.     /**
  243.      * @param string|null $titleCa
  244.      *
  245.      * @return $this
  246.      */
  247.     public function setTitleCa(?string $titleCa): self
  248.     {
  249.         $this->titleCa $titleCa;
  250.         return $this;
  251.     }
  252.     public function getEnabled(): ?bool
  253.     {
  254.         return $this->enabled;
  255.     }
  256.     public function setEnabled(bool $enabled): self
  257.     {
  258.         $this->enabled $enabled;
  259.         return $this;
  260.     }
  261.     public function getNavigate(): ?string
  262.     {
  263.         return $this->navigate;
  264.     }
  265.     public function setNavigate(?string $navigate): self
  266.     {
  267.         $this->navigate $navigate;
  268.         return $this;
  269.     }
  270.     /**
  271.      * @Gedmo\Locale
  272.      * Used locale to override Translation listener`s locale
  273.      * this is not a mapped field of entity metadata, just a simple property
  274.      */
  275.     private $locale;
  276.     /**
  277.      * @ORM\Column(type="string", length=255, nullable=true)
  278.      */
  279.     private ?string $bannerType;
  280.     public function setTranslatableLocale($locale): void
  281.     {
  282.         $this->locale $locale;
  283.     }
  284.     public function getUrl(): ?string
  285.     {
  286.         return $this->url;
  287.     }
  288.     public function setUrl(?string $url): self
  289.     {
  290.         $this->url $url;
  291.         return $this;
  292.     }
  293.     /**
  294.      * @param File|null $imageFile
  295.      */
  296.     public function setImageFile(?File $imageFile null): void
  297.     {
  298.         $this->imageFile $imageFile;
  299.         if (null !== $imageFile) {
  300.             $this->updatedAt = new \DateTimeImmutable();
  301.         }
  302.     }
  303.     public function getImageFile(): ?File
  304.     {
  305.         return $this->imageFile;
  306.     }
  307.     public function setImageName(?string $imageName): void
  308.     {
  309.         $this->imageName $imageName;
  310.     }
  311.     public function getImageName(): ?string
  312.     {
  313.         return $this->imageName;
  314.     }
  315.     public function setImageSize(?int $imageSize): void
  316.     {
  317.         $this->imageSize $imageSize;
  318.     }
  319.     public function getImageSize(): ?int
  320.     {
  321.         return $this->imageSize;
  322.     }
  323.     public function getTranslations()
  324.     {
  325.         return $this->translations;
  326.     }
  327.     public function addTranslation(BannerTranslation $t): void
  328.     {
  329.         if (!$this->translations->contains($t)) {
  330.             $this->translations[] = $t;
  331.             $t->setObject($this);
  332.         }
  333.     }
  334.     public function getBannerType(): ?string
  335.     {
  336.         if($this->bannerType === null)
  337.             return 'banner';
  338.         return $this->bannerType;
  339.     }
  340.     public function setBannerType(?string $bannerType): self
  341.     {
  342.         $this->bannerType $bannerType;
  343.         return $this;
  344.     }
  345.     /**
  346.      * @param File|null $imageFileEn
  347.      */
  348.     public function setImageFileEn(?File $imageFileEn null): void
  349.     {
  350.         $this->imageFileEn $imageFileEn;
  351.         if (null !== $imageFileEn) {
  352.             $this->updatedAt = new \DateTimeImmutable();
  353.         }
  354.     }
  355.     public function getImageFileEn(): ?File
  356.     {
  357.         return $this->imageFileEn;
  358.     }
  359.     public function setImageNameEn(?string $imageNameEn): self
  360.     {
  361.         $this->imageNameEn $imageNameEn;
  362.         return $this;
  363.     }
  364.     public function getImageNameEn(): ?string
  365.     {
  366.         return $this->imageNameEn;
  367.     }
  368.     public function setImageSizeEn(?int $imageSizeEn): self
  369.     {
  370.         $this->imageSizeEn $imageSizeEn;
  371.         return $this;
  372.     }
  373.     public function getImageSizeEn(): ?int
  374.     {
  375.         return $this->imageSizeEn;
  376.     }
  377.     /**
  378.      * @param File|null $imageFileCa
  379.      */
  380.     public function setImageFileCa(?File $imageFileCa null): void
  381.     {
  382.         $this->imageFileCa $imageFileCa;
  383.         if (null !== $imageFileCa) {
  384.             $this->updatedAt = new \DateTimeImmutable();
  385.         }
  386.     }
  387.     public function getImageFileCa(): ?File
  388.     {
  389.         return $this->imageFileCa;
  390.     }
  391.     public function setImageNameCa(?string $imageNameCa): self
  392.     {
  393.         $this->imageNameCa $imageNameCa;
  394.         return $this;
  395.     }
  396.     public function getImageNameCa(): ?string
  397.     {
  398.         return $this->imageNameCa;
  399.     }
  400.     public function setImageSizeCa(?int $imageSizeCa): self
  401.     {
  402.         $this->imageSizeCa $imageSizeCa;
  403.         return $this;
  404.     }
  405.     public function getImageSizeCa(): ?int
  406.     {
  407.         return $this->imageSizeCa;
  408.     }
  409.     public function getButtonName(): ?string
  410.     {
  411.         return $this->buttonName;
  412.     }
  413.     public function setButtonName(?string $buttonName): self
  414.     {
  415.         $this->buttonName $buttonName;
  416.         return $this;
  417.     }
  418.     public function __toString(): string
  419.     {
  420.         // Return a string representation of the banner.
  421.         // You can use any combination of properties to create a meaningful string.
  422.         return $this->getTitle() ?? 'Banner';
  423.     }
  424.     /**
  425.      * @return string | null
  426.      */
  427.     public function getUrlEn(): ?string
  428.     {
  429.         return $this->urlEn;
  430.     }
  431.     /**
  432.      * @param string | null $urlEn
  433.      */
  434.     public function setUrlEn(?string $urlEn): void
  435.     {
  436.         $this->urlEn $urlEn;
  437.     }
  438.     /**
  439.      * @return string | null
  440.      */
  441.     public function getUrlCa(): ?string
  442.     {
  443.         return $this->urlCa;
  444.     }
  445.     /**
  446.      * @param string | null $urlCa
  447.      */
  448.     public function setUrlCa(?string $urlCa): void
  449.     {
  450.         $this->urlCa $urlCa;
  451.     }
  452. }