modiefied CRUD

This commit is contained in:
tracer 2021-05-30 18:52:04 +02:00
parent 0284accaea
commit a4c49f1347
7 changed files with 432 additions and 260 deletions

View File

@ -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()
];
}
}

View File

@ -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'),
];
}
}

View File

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

View File

@ -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'),
];
}
*/
}

View File

@ -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'),
];
}
*/
}

View File

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

View File

@ -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;
/** /**
@ -71,12 +72,17 @@ class User implements UserInterface
*/ */
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 __toString()
{
return $this->username;
}
public function getId(): ?int public function getId(): ?int
{ {
return $this->id; return $this->id;