src/Entity/BlogAuthor.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\BlogAuthorRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\HttpFoundation\File\File;
  8. use Symfony\Component\HttpFoundation\File\UploadedFile;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  11. /**
  12.  * @ORM\Entity(repositoryClass=BlogAuthorRepository::class)
  13.  * @Vich\Uploadable
  14.  */
  15. class BlogAuthor
  16. {
  17.     /**
  18.      * @ORM\Id()
  19.      * @ORM\GeneratedValue()
  20.      * @ORM\Column(type="integer")
  21.      */
  22.     private $id;
  23.     /**
  24.      * @ORM\Column(type="string", length=40)
  25.      */
  26.     private $firstname;
  27.     /**
  28.      * @ORM\Column(type="string", length=40)
  29.      */
  30.     private $lastname;
  31.     /**
  32.      * @ORM\Column(type="text")
  33.      */
  34.     private $description;
  35.     /**
  36.      * @var File
  37.      * @Assert\Image(
  38.      *     minWidth = 100,
  39.      *     maxWidth = 200,
  40.      *     minHeight = 100,
  41.      *     maxHeight = 200
  42.      * )
  43.      * @Vich\UploadableField(mapping="blog_author_image", fileNameProperty="filename")
  44.      */
  45.     private $imageFile;
  46.     /**
  47.      * @var string
  48.      * @ORM\Column(type="string", length=255, nullable=true)
  49.      */
  50.     private $filename;
  51.     /**
  52.      * @ORM\Column(type="string", length=255, nullable=true)
  53.      */
  54.     private $website;
  55.     /**
  56.      * @ORM\Column(type="string", length=255, nullable=true)
  57.      */
  58.     private $metaTitle;
  59.     /**
  60.      * @ORM\Column(type="string", length=255, nullable=true)
  61.      */
  62.     private $metaDescription;
  63.     /**
  64.      * @ORM\Column(type="text", nullable=true)
  65.      */
  66.     private $metaCustom;
  67.     /**
  68.      * @ORM\OneToMany(targetEntity="BlogPost", mappedBy="blogAuthor")
  69.      * @ORM\OrderBy({"createdAt" = "DESC"})
  70.      */
  71.     private $blogPosts;
  72.     /**
  73.      * @ORM\Column(type="datetime")
  74.      */
  75.     private $updatedAt;
  76.     public function __construct()
  77.     {
  78.         $this->blogPosts = new ArrayCollection();
  79.     }
  80.     public function getId(): ?int
  81.     {
  82.         return $this->id;
  83.     }
  84.     public function getFirstname(): ?string
  85.     {
  86.         return $this->firstname;
  87.     }
  88.     public function setFirstname(string $firstname): self
  89.     {
  90.         $this->firstname $firstname;
  91.         return $this;
  92.     }
  93.     public function getLastname(): ?string
  94.     {
  95.         return $this->lastname;
  96.     }
  97.     public function setLastname(string $lastname): self
  98.     {
  99.         $this->lastname $lastname;
  100.         return $this;
  101.     }
  102.     public function getFullName(): string
  103.     {
  104.         return ucfirst($this->firstname) . ' ' ucfirst($this->lastname);
  105.     }
  106.     public function getDescription(): ?string
  107.     {
  108.         return $this->description;
  109.     }
  110.     public function setDescription(string $description): self
  111.     {
  112.         $this->description $description;
  113.         return $this;
  114.     }
  115.     public function getWebsite(): ?string
  116.     {
  117.         return $this->website;
  118.     }
  119.     public function setWebsite(?string $website): self
  120.     {
  121.         $this->website $website;
  122.         return $this;
  123.     }
  124.     public function getMetaTitle(): ?string
  125.     {
  126.         return $this->metaTitle;
  127.     }
  128.     public function setMetaTitle(?string $metaTitle): self
  129.     {
  130.         $this->metaTitle $metaTitle;
  131.         return $this;
  132.     }
  133.     public function getMetaDescription(): ?string
  134.     {
  135.         return $this->metaDescription;
  136.     }
  137.     public function setMetaDescription(?string $metaDescription): self
  138.     {
  139.         $this->metaDescription $metaDescription;
  140.         return $this;
  141.     }
  142.     public function getMetaCustom(): ?string
  143.     {
  144.         return $this->metaCustom;
  145.     }
  146.     public function setMetaCustom(?string $metaCustom): self
  147.     {
  148.         $this->metaCustom $metaCustom;
  149.         return $this;
  150.     }
  151.     public function getFilename(): ?string
  152.     {
  153.         return $this->filename;
  154.     }
  155.     public function setFilename(string $filename=null): self
  156.     {
  157.         $this->filename $filename;
  158.         return $this;
  159.     }
  160.     public function setImageFile(?File $imageFile null)
  161.     {
  162.         $this->imageFile $imageFile;
  163.         if (null !== $imageFile) {
  164.             // It is required that at least one field changes if you are using doctrine
  165.             // otherwise the event listeners won't be called and the file is lost
  166.             $this->updatedAt = new \DateTimeImmutable();
  167.         }
  168.     }
  169.     public function getImageFile()
  170.     {
  171.         return $this->imageFile;
  172.     }
  173.     /**
  174.      * @return Collection|BlogPost[]
  175.      */
  176.     public function getBlogPosts(): Collection
  177.     {
  178.         return $this->blogPosts;
  179.     }
  180.     public function addBlogPost(BlogPost $blogPost): self
  181.     {
  182.         if (!$this->blogPosts->contains($blogPost)) {
  183.             $this->blogPosts[] = $blogPost;
  184.             $blogPost->setBlogAuthor($this);
  185.         }
  186.         return $this;
  187.     }
  188.     public function removeBlogPost(BlogPost $blogPost): self
  189.     {
  190.         if ($this->blogPosts->contains($blogPost)) {
  191.             $this->blogPosts->removeElement($blogPost);
  192.             // set the owning side to null (unless already changed)
  193.             if ($blogPost->getBlogAuthor() === $this) {
  194.                 $blogPost->setBlogAuthor(null);
  195.             }
  196.         }
  197.         return $this;
  198.     }
  199.     public function getUpdatedAt(): ?\DateTimeInterface
  200.     {
  201.         return $this->updatedAt;
  202.     }
  203.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  204.     {
  205.         $this->updatedAt $updatedAt;
  206.         return $this;
  207.     }
  208. }