src/Entity/BlogPost.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\CommonTrait;
  4. use App\Repository\BlogPostRepository;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  7. use Symfony\Component\HttpFoundation\File\File;
  8. use Vich\UploaderBundle\Entity\File as EmbeddedFile;
  9. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  10. use Symfony\Component\HttpFoundation\File\UploadedFile;
  11. /**
  12.  * @ORM\Entity(repositoryClass=BlogPostRepository::class)
  13.  * @ORM\HasLifecycleCallbacks()
  14.  * @ORM\Table(name="blog_post")
  15.  * @UniqueEntity({"uuid"})
  16.  */
  17. #[Vich\Uploadable]
  18. class BlogPost
  19. {
  20.     use CommonTrait;
  21.     /**
  22.      * @ORM\Column(type="string", length=255)
  23.      */
  24.     private $title;
  25.     /**
  26.      * @ORM\Column(type="text", nullable=true)
  27.      */
  28.     private $text;
  29.     /**
  30.      * @ORM\Column(type="string", length=255, nullable=true)
  31.      */
  32.     private $author;
  33.     /**
  34.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  35.      *
  36.      *
  37.      * @var File|null
  38.      */
  39.     #[Vich\UploadableField(mapping'blog_main'fileNameProperty'mainImageFile.name'size'mainImageFile.size'mimeType'mainImageFile.mimeType'originalName'mainImageFile.originalName'dimensions'mainImageFile.dimensions')]
  40.     private $mainImage;
  41.     /**
  42.      * @ORM\Embedded(class="Vich\UploaderBundle\Entity\File")
  43.      *
  44.      * @var EmbeddedFile
  45.      */
  46.     private $mainImageFile;
  47.     /**
  48.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  49.      *
  50.      *
  51.      * @var File|null
  52.      */
  53.     #[Vich\UploadableField(mapping'blog_big'fileNameProperty'bigImageFile.name'size'bigImageFile.size'mimeType'bigImageFile.mimeType'originalName'bigImageFile.originalName'dimensions'bigImageFile.dimensions')]
  54.     private $bigImage;
  55.     /**
  56.      * @ORM\Embedded(class="Vich\UploaderBundle\Entity\File")
  57.      *
  58.      * @var EmbeddedFile
  59.      */
  60.     private $bigImageFile;
  61.     public function __construct()
  62.     {
  63.         $this->bigImageFile = new EmbeddedFile();
  64.         $this->mainImageFile = new EmbeddedFile();
  65.     }
  66.     public function getTitle(): ?string
  67.     {
  68.         return $this->title;
  69.     }
  70.     public function setTitle(string $title): self
  71.     {
  72.         $this->title $title;
  73.         return $this;
  74.     }
  75.     public function getText(): ?string
  76.     {
  77.         return $this->text;
  78.     }
  79.     public function setText(?string $text): self
  80.     {
  81.         $this->text $text;
  82.         return $this;
  83.     }
  84.     public function getAuthor(): ?string
  85.     {
  86.         return $this->author;
  87.     }
  88.     public function setAuthor(?string $author): self
  89.     {
  90.         $this->author $author;
  91.         return $this;
  92.     }
  93.     public function setMainImage(?File $mainImage null)
  94.     {
  95.         $this->mainImage $mainImage;
  96.         if (null !== $mainImage) {
  97.             // It is required that at least one field changes if you are using doctrine
  98.             // otherwise the event listeners won't be called and the file is lost
  99.             $this->updatedAt = new \DateTimeImmutable();
  100.         }
  101.     }
  102.     public function getMainImage(): ?File
  103.     {
  104.         return $this->mainImage;
  105.     }
  106.     public function setMainImageFile(EmbeddedFile $image): void
  107.     {
  108.         $this->mainImageFile $image;
  109.     }
  110.     public function getMainImageFile(): ?EmbeddedFile
  111.     {
  112.         return $this->mainImageFile;
  113.     }
  114.     public function setBigImage(?File $bigImage null)
  115.     {
  116.         $this->bigImage $bigImage;
  117.         if (null !== $bigImage) {
  118.             // It is required that at least one field changes if you are using doctrine
  119.             // otherwise the event listeners won't be called and the file is lost
  120.             $this->updatedAt = new \DateTimeImmutable();
  121.         }
  122.     }
  123.     public function getBigImage(): ?File
  124.     {
  125.         return $this->bigImage;
  126.     }
  127.     public function setBigImageFile(EmbeddedFile $image): void
  128.     {
  129.         $this->bigImageFile $image;
  130.     }
  131.     public function getBigImageFile(): ?EmbeddedFile
  132.     {
  133.         return $this->bigImageFile;
  134.     }
  135. }