added Blog entity

This commit is contained in:
tracer 2021-05-30 18:18:30 +02:00
parent aeaaae7bf5
commit 32e8e11882
5 changed files with 346 additions and 14 deletions

214
src/Entity/Blog.php Normal file
View File

@ -0,0 +1,214 @@
<?php
namespace App\Entity;
use App\Repository\BlogRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=BlogRepository::class)
*/
class Blog
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $title;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $teaser;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $teaserImage;
/**
* @ORM\Column(type="text")
*/
private $content;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="blogs")
* @ORM\JoinColumn(nullable=false)
*/
private $author;
/**
* @ORM\ManyToMany(targetEntity=Section::class, inversedBy="blogs")
*/
private $section;
/**
* @ORM\Column(type="datetime")
*/
private $createdAt;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $editedAt;
/**
* @ORM\ManyToOne(targetEntity=User::class)
*/
private $editedBy;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $editReason;
public function __construct()
{
$this->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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -0,0 +1,50 @@
<?php
namespace App\Repository;
use App\Entity\Blog;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @method Blog|null find($id, $lockMode = null, $lockVersion = null)
* @method Blog|null findOneBy(array $criteria, array $orderBy = null)
* @method Blog[] findAll()
* @method Blog[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class BlogRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Blog::class);
}
// /**
// * @return Blog[] Returns an array of Blog objects
// */
/*
public function findByExampleField($value)
{
return $this->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()
;
}
*/
}

View File

@ -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