src/Entity/News.php line 26

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