Implement basic wishlist
This commit is contained in:
parent
d80d667e0d
commit
f2dd4da50b
9 changed files with 315 additions and 0 deletions
|
@ -4,6 +4,7 @@ namespace App\Controller\Admin;
|
|||
|
||||
use App\Entity\User;
|
||||
use App\Entity\Offering;
|
||||
use App\Entity\Wish;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
|
||||
|
@ -32,5 +33,6 @@ class DashboardController extends AbstractDashboardController
|
|||
yield MenuItem::linktoDashboard('Dashboard', 'fa fa-home');
|
||||
yield MenuItem::linkToCrud('User', 'fas fa-user', User::class);
|
||||
yield MenuItem::linkToCrud('Offering', 'fas fa-seedling', Offering::class);
|
||||
yield MenuItem::linkToCrud('Wish', 'fas fa-star', Wish::class);
|
||||
}
|
||||
}
|
||||
|
|
24
src/Controller/Admin/WishCrudController.php
Normal file
24
src/Controller/Admin/WishCrudController.php
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Entity\Wish;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
|
||||
|
||||
class WishCrudController extends AbstractCrudController
|
||||
{
|
||||
public static function getEntityFqcn(): string
|
||||
{
|
||||
return Wish::class;
|
||||
}
|
||||
|
||||
public function configureFields(string $pageName): iterable
|
||||
{
|
||||
return [
|
||||
yield AssociationField::new('byUser'),
|
||||
yield TextField::new('title'),
|
||||
];
|
||||
}
|
||||
}
|
|
@ -2,12 +2,27 @@
|
|||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Wish;
|
||||
use App\Form\WishFormType;
|
||||
|
||||
use App\Repository\WishRepository;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Twig\Environment;
|
||||
|
||||
class UserController extends AbstractController
|
||||
{
|
||||
private $entityManager;
|
||||
|
||||
public function __construct(EntityManagerInterface $entityManager)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
|
||||
#[Route('/user', name: 'user_page')]
|
||||
public function user(): Response
|
||||
{
|
||||
|
@ -15,4 +30,30 @@ class UserController extends AbstractController
|
|||
'user' => $this->getUser(),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/wishlist', name: 'wishlist')]
|
||||
public function wishlist(Request $request, WishRepository $wishRepository): Response
|
||||
{
|
||||
$wish = new Wish();
|
||||
$form = $this->createForm(WishFormType::class, $wish);
|
||||
$user = $this->getUser();
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$wish->setByUser($user);
|
||||
|
||||
$this->entityManager->persist($wish);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->addFlash("success", "Successfully added the new offering!");
|
||||
return $this->redirectToRoute('wishlist');
|
||||
}
|
||||
|
||||
return $this->render('user/wish.html.twig', [
|
||||
'user' => $this->getUser(),
|
||||
'wishes' => $wishRepository->findByUser($user),
|
||||
'wish_form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue