diff --git a/src/Entity/Blog.php b/src/Entity/Blog.php new file mode 100644 index 0000000..30eebfe --- /dev/null +++ b/src/Entity/Blog.php @@ -0,0 +1,214 @@ +section = new ArrayCollection(); + } + + public function getId(): ?int + { + return $this->id; + } + + public function getTitle(): ?string + { + return $this->title; + } + + public function setTitle(string $title): self + { + $this->title = $title; + + return $this; + } + + public function getTeaser(): ?string + { + return $this->teaser; + } + + public function setTeaser(?string $teaser): self + { + $this->teaser = $teaser; + + return $this; + } + + public function getTeaserImage(): ?string + { + return $this->teaserImage; + } + + public function setTeaserImage(?string $teaserImage): self + { + $this->teaserImage = $teaserImage; + + return $this; + } + + public function getContent(): ?string + { + return $this->content; + } + + public function setContent(string $content): self + { + $this->content = $content; + + return $this; + } + + public function getAuthor(): ?User + { + return $this->author; + } + + public function setAuthor(?User $author): self + { + $this->author = $author; + + return $this; + } + + /** + * @return Collection|Section[] + */ + public function getSection(): Collection + { + return $this->section; + } + + public function addSection(Section $section): self + { + if (!$this->section->contains($section)) { + $this->section[] = $section; + } + + return $this; + } + + public function removeSection(Section $section): self + { + $this->section->removeElement($section); + + return $this; + } + + public function getCreatedAt(): ?\DateTimeInterface + { + return $this->createdAt; + } + + public function setCreatedAt(\DateTimeInterface $createdAt): self + { + $this->createdAt = $createdAt; + + return $this; + } + + public function getEditedAt(): ?\DateTimeInterface + { + return $this->editedAt; + } + + public function setEditedAt(?\DateTimeInterface $editedAt): self + { + $this->editedAt = $editedAt; + + return $this; + } + + public function getEditedBy(): ?User + { + return $this->editedBy; + } + + public function setEditedBy(?User $editedBy): self + { + $this->editedBy = $editedBy; + + return $this; + } + + public function getEditReason(): ?string + { + return $this->editReason; + } + + public function setEditReason(?string $editReason): self + { + $this->editReason = $editReason; + + return $this; + } +} diff --git a/src/Entity/Section.php b/src/Entity/Section.php index 5d7af8b..37216af 100644 --- a/src/Entity/Section.php +++ b/src/Entity/Section.php @@ -3,6 +3,8 @@ namespace App\Entity; use App\Repository\SectionRepository; +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; /** @@ -32,6 +34,16 @@ class Section */ private $teaserImage; + /** + * @ORM\ManyToMany(targetEntity=Blog::class, mappedBy="section") + */ + private $blogs; + + public function __construct() + { + $this->blogs = new ArrayCollection(); + } + public function getId(): ?int { return $this->id; @@ -72,4 +84,31 @@ class Section return $this; } + + /** + * @return Collection|Blog[] + */ + public function getBlogs(): Collection + { + return $this->blogs; + } + + public function addBlog(Blog $blog): self + { + if (!$this->blogs->contains($blog)) { + $this->blogs[] = $blog; + $blog->addSection($this); + } + + return $this; + } + + public function removeBlog(Blog $blog): self + { + if ($this->blogs->removeElement($blog)) { + $blog->removeSection($this); + } + + return $this; + } } diff --git a/src/Entity/User.php b/src/Entity/User.php index 6792c54..479add4 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -3,6 +3,8 @@ namespace App\Entity; use App\Repository\UserRepository; +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Security\Core\User\UserInterface; @@ -59,6 +61,16 @@ class User implements UserInterface */ private $lastLoginAt; + /** + * @ORM\OneToMany(targetEntity=Blog::class, mappedBy="author") + */ + private $blogs; + + public function __construct() + { + $this->blogs = new ArrayCollection(); + } + public function getId(): ?int { return $this->id; @@ -194,4 +206,34 @@ class User implements UserInterface return $this; } + + /** + * @return Collection|Blog[] + */ + public function getBlogs(): Collection + { + return $this->blogs; + } + + public function addBlog(Blog $blog): self + { + if (!$this->blogs->contains($blog)) { + $this->blogs[] = $blog; + $blog->setAuthor($this); + } + + return $this; + } + + public function removeBlog(Blog $blog): self + { + if ($this->blogs->removeElement($blog)) { + // set the owning side to null (unless already changed) + if ($blog->getAuthor() === $this) { + $blog->setAuthor(null); + } + } + + return $this; + } } diff --git a/src/Repository/BlogRepository.php b/src/Repository/BlogRepository.php new file mode 100644 index 0000000..2398b11 --- /dev/null +++ b/src/Repository/BlogRepository.php @@ -0,0 +1,50 @@ +createQueryBuilder('b') + ->andWhere('b.exampleField = :val') + ->setParameter('val', $value) + ->orderBy('b.id', 'ASC') + ->setMaxResults(10) + ->getQuery() + ->getResult() + ; + } + */ + + /* + public function findOneBySomeField($value): ?Blog + { + return $this->createQueryBuilder('b') + ->andWhere('b.exampleField = :val') + ->setParameter('val', $value) + ->getQuery() + ->getOneOrNullResult() + ; + } + */ +} diff --git a/src/Security/AppAuthenticator.php b/src/Security/AppAuthenticator.php index 74352cd..3ef67ca 100644 --- a/src/Security/AppAuthenticator.php +++ b/src/Security/AppAuthenticator.php @@ -175,23 +175,10 @@ class AppAuthenticator extends AbstractFormLoginAuthenticator implements Passwor } /* -section: - -title, -description, -teaserImage - blog: -title, -teaser, -teaserImage -content, -autor => user, -section => section, -createdAt, -editedAt, + editedby => user editreason