modiefied CRUD
This commit is contained in:
parent
0284accaea
commit
a4c49f1347
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller\Admin;
|
||||||
|
|
||||||
|
use App\Entity\Blog;
|
||||||
|
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
|
||||||
|
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
|
||||||
|
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
|
||||||
|
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
|
||||||
|
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
|
||||||
|
|
||||||
|
class BlogCrudController extends AbstractCrudController
|
||||||
|
{
|
||||||
|
public static function getEntityFqcn(): string
|
||||||
|
{
|
||||||
|
return Blog::class;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configureFields(string $pageName): iterable
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
AssociationField::new('author')
|
||||||
|
->autocomplete(),
|
||||||
|
TextField::new('title'),
|
||||||
|
TextEditorField::new('teaser'),
|
||||||
|
TextEditorField::new('content'),
|
||||||
|
DateTimeField::new('createdAt'),
|
||||||
|
AssociationField::new('editedBy')
|
||||||
|
->autocomplete()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller\Admin;
|
||||||
|
|
||||||
|
use App\Entity\Comment;
|
||||||
|
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
|
||||||
|
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
|
||||||
|
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
|
||||||
|
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
|
||||||
|
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
|
||||||
|
|
||||||
|
class CommentCrudController extends AbstractCrudController
|
||||||
|
{
|
||||||
|
public static function getEntityFqcn(): string
|
||||||
|
{
|
||||||
|
return Comment::class;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configureFields(string $pageName): iterable
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
AssociationField::new('author')
|
||||||
|
->autocomplete(),
|
||||||
|
AssociationField::new('blog')
|
||||||
|
->autocomplete(),
|
||||||
|
TextField::new('title'),
|
||||||
|
TextEditorField::new('content'),
|
||||||
|
DateTimeField::new('createdAt'),
|
||||||
|
AssociationField::new('editedBy')
|
||||||
|
->autocomplete(),
|
||||||
|
DateTimeField::new('editedAt'),
|
||||||
|
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller\Admin;
|
||||||
|
|
||||||
|
use App\Entity\Section;
|
||||||
|
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
|
||||||
|
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
|
||||||
|
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
use App\Entity\User;
|
||||||
|
use App\Entity\Blog;
|
||||||
|
use App\Entity\Comment;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class DashboardController
|
||||||
|
* @package App\Controller\Admin
|
||||||
|
*/
|
||||||
|
class DashboardController extends AbstractDashboardController
|
||||||
|
{
|
||||||
|
#[Route('/admin', name: 'admin')]
|
||||||
|
public function index(): Response
|
||||||
|
{
|
||||||
|
return parent::index();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configureDashboard(): Dashboard
|
||||||
|
{
|
||||||
|
return Dashboard::new()
|
||||||
|
->setTitle('24unix');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configureMenuItems(): iterable
|
||||||
|
{
|
||||||
|
yield MenuItem::linktoRoute('Back to the website', 'fas fa-home', 'blog');
|
||||||
|
yield MenuItem::linktoDashboard('Dashboard', 'fas fa-tachometer-alt');
|
||||||
|
yield MenuItem::linkToCrud('User', 'fas fa-user', User::class);
|
||||||
|
yield MenuItem::linkToCrud('Sections', 'fas fa-book', Section::class);
|
||||||
|
yield MenuItem::linkToCrud('Blogs', 'fas fa-blog', Blog::class);
|
||||||
|
yield MenuItem::linkToCrud('Comments', 'fas fa-comments', Comment::class);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller\Admin;
|
||||||
|
|
||||||
|
use App\Entity\Section;
|
||||||
|
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
|
||||||
|
|
||||||
|
class SectionCrudController extends AbstractCrudController
|
||||||
|
{
|
||||||
|
public static function getEntityFqcn(): string
|
||||||
|
{
|
||||||
|
return Section::class;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
public function configureFields(string $pageName): iterable
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
IdField::new('id'),
|
||||||
|
TextField::new('title'),
|
||||||
|
TextEditorField::new('description'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller\Admin;
|
||||||
|
|
||||||
|
use App\Entity\User;
|
||||||
|
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
|
||||||
|
|
||||||
|
class UserCrudController extends AbstractCrudController
|
||||||
|
{
|
||||||
|
public static function getEntityFqcn(): string
|
||||||
|
{
|
||||||
|
return User::class;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
public function configureFields(string $pageName): iterable
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
IdField::new('id'),
|
||||||
|
TextField::new('title'),
|
||||||
|
TextEditorField::new('description'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
|
@ -68,7 +68,7 @@ class Blog
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="string", length=255, nullable=true)
|
* @ORM\Column(type="string", length=255, nullable=true)
|
||||||
*/
|
*/
|
||||||
private $editReason;
|
private ?string $editReason;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\OneToMany(targetEntity=Comment::class, mappedBy="blog")
|
* @ORM\OneToMany(targetEntity=Comment::class, mappedBy="blog")
|
||||||
|
@ -81,6 +81,12 @@ class Blog
|
||||||
$this->comments = new ArrayCollection();
|
$this->comments = new ArrayCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
return $this->title;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getId(): ?int
|
public function getId(): ?int
|
||||||
{
|
{
|
||||||
return $this->id;
|
return $this->id;
|
||||||
|
|
|
@ -6,6 +6,7 @@ use App\Repository\UserRepository;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use JetBrains\PhpStorm\Pure;
|
||||||
use Symfony\Component\Security\Core\User\UserInterface;
|
use Symfony\Component\Security\Core\User\UserInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,263 +14,268 @@ use Symfony\Component\Security\Core\User\UserInterface;
|
||||||
*/
|
*/
|
||||||
class User implements UserInterface
|
class User implements UserInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @ORM\Id
|
* @ORM\Id
|
||||||
* @ORM\GeneratedValue
|
* @ORM\GeneratedValue
|
||||||
* @ORM\Column(type="integer")
|
* @ORM\Column(type="integer")
|
||||||
*/
|
*/
|
||||||
private $id;
|
private $id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="string", length=180, unique=true)
|
* @ORM\Column(type="string", length=180, unique=true)
|
||||||
*/
|
*/
|
||||||
private $username;
|
private $username;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="json")
|
* @ORM\Column(type="json")
|
||||||
*/
|
*/
|
||||||
private $roles = [];
|
private $roles = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string The hashed password
|
* @var string The hashed password
|
||||||
* @ORM\Column(type="string")
|
* @ORM\Column(type="string")
|
||||||
*/
|
*/
|
||||||
private $password;
|
private $password;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="string", length=255, nullable=true)
|
* @ORM\Column(type="string", length=255, nullable=true)
|
||||||
*/
|
*/
|
||||||
private $firstName;
|
private $firstName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="string", length=255, nullable=true)
|
* @ORM\Column(type="string", length=255, nullable=true)
|
||||||
*/
|
*/
|
||||||
private $lastName;
|
private $lastName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="string", length=255)
|
* @ORM\Column(type="string", length=255)
|
||||||
*/
|
*/
|
||||||
private $email;
|
private $email;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="datetime")
|
* @ORM\Column(type="datetime")
|
||||||
*/
|
*/
|
||||||
private $createdAt;
|
private $createdAt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="datetime", nullable=true)
|
* @ORM\Column(type="datetime", nullable=true)
|
||||||
*/
|
*/
|
||||||
private $lastLoginAt;
|
private $lastLoginAt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\OneToMany(targetEntity=Blog::class, mappedBy="author")
|
* @ORM\OneToMany(targetEntity=Blog::class, mappedBy="author")
|
||||||
*/
|
*/
|
||||||
private $blogs;
|
private $blogs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\OneToMany(targetEntity=Comment::class, mappedBy="author")
|
* @ORM\OneToMany(targetEntity=Comment::class, mappedBy="author")
|
||||||
*/
|
*/
|
||||||
private $comments;
|
private $comments;
|
||||||
|
|
||||||
public function __construct()
|
#[Pure] public function __construct()
|
||||||
{
|
{
|
||||||
$this->blogs = new ArrayCollection();
|
$this->blogs = new ArrayCollection();
|
||||||
$this->comments = new ArrayCollection();
|
$this->comments = new ArrayCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getId(): ?int
|
public function __toString()
|
||||||
{
|
{
|
||||||
return $this->id;
|
return $this->username;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getId(): ?int
|
||||||
* A visual identifier that represents this user.
|
{
|
||||||
*
|
return $this->id;
|
||||||
* @see UserInterface
|
}
|
||||||
*/
|
|
||||||
public function getUsername(): string
|
/**
|
||||||
{
|
* A visual identifier that represents this user.
|
||||||
return (string) $this->username;
|
*
|
||||||
}
|
* @see UserInterface
|
||||||
|
*/
|
||||||
public function setUsername(string $username): self
|
public function getUsername(): string
|
||||||
{
|
{
|
||||||
$this->username = $username;
|
return (string)$this->username;
|
||||||
|
}
|
||||||
return $this;
|
|
||||||
}
|
public function setUsername(string $username): self
|
||||||
|
{
|
||||||
/**
|
$this->username = $username;
|
||||||
* @see UserInterface
|
|
||||||
*/
|
return $this;
|
||||||
public function getRoles(): array
|
}
|
||||||
{
|
|
||||||
$roles = $this->roles;
|
/**
|
||||||
// guarantee every user at least has ROLE_USER
|
* @see UserInterface
|
||||||
$roles[] = 'ROLE_USER';
|
*/
|
||||||
|
public function getRoles(): array
|
||||||
return array_unique($roles);
|
{
|
||||||
}
|
$roles = $this->roles;
|
||||||
|
// guarantee every user at least has ROLE_USER
|
||||||
public function setRoles(array $roles): self
|
$roles[] = 'ROLE_USER';
|
||||||
{
|
|
||||||
$this->roles = $roles;
|
return array_unique($roles);
|
||||||
|
}
|
||||||
return $this;
|
|
||||||
}
|
public function setRoles(array $roles): self
|
||||||
|
{
|
||||||
/**
|
$this->roles = $roles;
|
||||||
* @see UserInterface
|
|
||||||
*/
|
return $this;
|
||||||
public function getPassword(): string
|
}
|
||||||
{
|
|
||||||
return $this->password;
|
/**
|
||||||
}
|
* @see UserInterface
|
||||||
|
*/
|
||||||
public function setPassword(string $password): self
|
public function getPassword(): string
|
||||||
{
|
{
|
||||||
$this->password = $password;
|
return $this->password;
|
||||||
|
}
|
||||||
return $this;
|
|
||||||
}
|
public function setPassword(string $password): self
|
||||||
|
{
|
||||||
/**
|
$this->password = $password;
|
||||||
* Returning a salt is only needed, if you are not using a modern
|
|
||||||
* hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
|
return $this;
|
||||||
*
|
}
|
||||||
* @see UserInterface
|
|
||||||
*/
|
/**
|
||||||
public function getSalt(): ?string
|
* Returning a salt is only needed, if you are not using a modern
|
||||||
{
|
* hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
|
||||||
return null;
|
*
|
||||||
}
|
* @see UserInterface
|
||||||
|
*/
|
||||||
/**
|
public function getSalt(): ?string
|
||||||
* @see UserInterface
|
{
|
||||||
*/
|
return null;
|
||||||
public function eraseCredentials()
|
}
|
||||||
{
|
|
||||||
// If you store any temporary, sensitive data on the user, clear it here
|
/**
|
||||||
// $this->plainPassword = null;
|
* @see UserInterface
|
||||||
}
|
*/
|
||||||
|
public function eraseCredentials()
|
||||||
public function getFirstName(): ?string
|
{
|
||||||
{
|
// If you store any temporary, sensitive data on the user, clear it here
|
||||||
return $this->firstName;
|
// $this->plainPassword = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setFirstName(?string $firstName): self
|
public function getFirstName(): ?string
|
||||||
{
|
{
|
||||||
$this->firstName = $firstName;
|
return $this->firstName;
|
||||||
|
}
|
||||||
return $this;
|
|
||||||
}
|
public function setFirstName(?string $firstName): self
|
||||||
|
{
|
||||||
public function getLastName(): ?string
|
$this->firstName = $firstName;
|
||||||
{
|
|
||||||
return $this->lastName;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setLastName(?string $lastName): self
|
public function getLastName(): ?string
|
||||||
{
|
{
|
||||||
$this->lastName = $lastName;
|
return $this->lastName;
|
||||||
|
}
|
||||||
return $this;
|
|
||||||
}
|
public function setLastName(?string $lastName): self
|
||||||
|
{
|
||||||
public function getEmail(): ?string
|
$this->lastName = $lastName;
|
||||||
{
|
|
||||||
return $this->email;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setEmail(string $email): self
|
public function getEmail(): ?string
|
||||||
{
|
{
|
||||||
$this->email = $email;
|
return $this->email;
|
||||||
|
}
|
||||||
return $this;
|
|
||||||
}
|
public function setEmail(string $email): self
|
||||||
|
{
|
||||||
public function getCreatedAt(): ?\DateTimeInterface
|
$this->email = $email;
|
||||||
{
|
|
||||||
return $this->createdAt;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setCreatedAt(\DateTimeInterface $createdAt): self
|
public function getCreatedAt(): ?\DateTimeInterface
|
||||||
{
|
{
|
||||||
$this->createdAt = $createdAt;
|
return $this->createdAt;
|
||||||
|
}
|
||||||
return $this;
|
|
||||||
}
|
public function setCreatedAt(\DateTimeInterface $createdAt): self
|
||||||
|
{
|
||||||
public function getLastLoginAt(): ?\DateTimeInterface
|
$this->createdAt = $createdAt;
|
||||||
{
|
|
||||||
return $this->lastLoginAt;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setLastLoginAt(?\DateTimeInterface $lastLoginAt): self
|
public function getLastLoginAt(): ?\DateTimeInterface
|
||||||
{
|
{
|
||||||
$this->lastLoginAt = $lastLoginAt;
|
return $this->lastLoginAt;
|
||||||
|
}
|
||||||
return $this;
|
|
||||||
}
|
public function setLastLoginAt(?\DateTimeInterface $lastLoginAt): self
|
||||||
|
{
|
||||||
/**
|
$this->lastLoginAt = $lastLoginAt;
|
||||||
* @return Collection|Blog[]
|
|
||||||
*/
|
return $this;
|
||||||
public function getBlogs(): Collection
|
}
|
||||||
{
|
|
||||||
return $this->blogs;
|
/**
|
||||||
}
|
* @return Collection|Blog[]
|
||||||
|
*/
|
||||||
public function addBlog(Blog $blog): self
|
public function getBlogs(): Collection
|
||||||
{
|
{
|
||||||
if (!$this->blogs->contains($blog)) {
|
return $this->blogs;
|
||||||
$this->blogs[] = $blog;
|
}
|
||||||
$blog->setAuthor($this);
|
|
||||||
}
|
public function addBlog(Blog $blog): self
|
||||||
|
{
|
||||||
return $this;
|
if (!$this->blogs->contains($blog)) {
|
||||||
}
|
$this->blogs[] = $blog;
|
||||||
|
$blog->setAuthor($this);
|
||||||
public function removeBlog(Blog $blog): self
|
}
|
||||||
{
|
|
||||||
if ($this->blogs->removeElement($blog)) {
|
return $this;
|
||||||
// set the owning side to null (unless already changed)
|
}
|
||||||
if ($blog->getAuthor() === $this) {
|
|
||||||
$blog->setAuthor(null);
|
public function removeBlog(Blog $blog): self
|
||||||
}
|
{
|
||||||
}
|
if ($this->blogs->removeElement($blog)) {
|
||||||
|
// set the owning side to null (unless already changed)
|
||||||
return $this;
|
if ($blog->getAuthor() === $this) {
|
||||||
}
|
$blog->setAuthor(null);
|
||||||
|
}
|
||||||
/**
|
}
|
||||||
* @return Collection|Comment[]
|
|
||||||
*/
|
return $this;
|
||||||
public function getComments(): Collection
|
}
|
||||||
{
|
|
||||||
return $this->comments;
|
/**
|
||||||
}
|
* @return Collection|Comment[]
|
||||||
|
*/
|
||||||
public function addComment(Comment $comment): self
|
public function getComments(): Collection
|
||||||
{
|
{
|
||||||
if (!$this->comments->contains($comment)) {
|
return $this->comments;
|
||||||
$this->comments[] = $comment;
|
}
|
||||||
$comment->setAuthor($this);
|
|
||||||
}
|
public function addComment(Comment $comment): self
|
||||||
|
{
|
||||||
return $this;
|
if (!$this->comments->contains($comment)) {
|
||||||
}
|
$this->comments[] = $comment;
|
||||||
|
$comment->setAuthor($this);
|
||||||
public function removeComment(Comment $comment): self
|
}
|
||||||
{
|
|
||||||
if ($this->comments->removeElement($comment)) {
|
return $this;
|
||||||
// set the owning side to null (unless already changed)
|
}
|
||||||
if ($comment->getAuthor() === $this) {
|
|
||||||
$comment->setAuthor(null);
|
public function removeComment(Comment $comment): self
|
||||||
}
|
{
|
||||||
}
|
if ($this->comments->removeElement($comment)) {
|
||||||
|
// set the owning side to null (unless already changed)
|
||||||
return $this;
|
if ($comment->getAuthor() === $this) {
|
||||||
}
|
$comment->setAuthor(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue