|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Controller\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use App\Repository\ItemRepository; |
|
6
|
|
|
use App\Repository\CollectionRepository; |
|
7
|
|
|
use Psr\Log\LoggerInterface; |
|
8
|
|
|
use Ramsey\Uuid\Uuid; |
|
9
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
11
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
12
|
|
|
use Symfony\Component\Messenger\MessageBusInterface; |
|
13
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
14
|
|
|
use Knp\Component\Pager\PaginatorInterface; |
|
15
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
|
16
|
|
|
use App\Command\RemoveItemFromCollectionCommand; |
|
17
|
|
|
|
|
18
|
|
|
class AdminCollectionItemsController extends AbstractController |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var MessageBusInterface |
|
22
|
|
|
*/ |
|
23
|
|
|
private $commandBus; |
|
24
|
|
|
/** |
|
25
|
|
|
* @var LoggerInterface |
|
26
|
|
|
*/ |
|
27
|
|
|
private $logger; |
|
28
|
|
|
/** |
|
29
|
|
|
* @var ItemRepository |
|
30
|
|
|
*/ |
|
31
|
|
|
private $repository; |
|
32
|
|
|
/** |
|
33
|
|
|
* @var CollectionRepository |
|
34
|
|
|
*/ |
|
35
|
|
|
private $collectionRepository; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @param MessageBusInterface $commandBus |
|
39
|
|
|
* @param LoggerInterface $logger |
|
40
|
|
|
* @param ItemRepository $repository |
|
41
|
|
|
* @param CollectionRepository $collectionRepository |
|
42
|
|
|
*/ |
|
43
|
|
|
public function __construct( |
|
44
|
|
|
MessageBusInterface $commandBus, |
|
45
|
|
|
LoggerInterface $logger, |
|
46
|
|
|
ItemRepository $repository, |
|
47
|
|
|
CollectionRepository $collectionRepository |
|
48
|
|
|
) |
|
49
|
|
|
{ |
|
50
|
|
|
$this->commandBus = $commandBus; |
|
51
|
|
|
$this->logger = $logger; |
|
52
|
|
|
$this->repository = $repository; |
|
53
|
|
|
$this->collectionRepository = $collectionRepository; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @Route("/admin/collection-items/{id}", name="admin_collection_items", methods={"GET"}) |
|
58
|
|
|
* @param PaginatorInterface $paginator |
|
59
|
|
|
* @param Request $request |
|
60
|
|
|
* @return Response |
|
61
|
|
|
*/ |
|
62
|
|
|
public function collectionItemsList(string $id, PaginatorInterface $paginator, Request $request): Response |
|
63
|
|
|
{ |
|
64
|
|
|
$collectionId = Uuid::fromString($id); |
|
65
|
|
|
$collection = $this->collectionRepository->getCollection($collectionId); |
|
66
|
|
|
return $this->render('admin/collection/items_list.html.twig', [ |
|
67
|
|
|
'collection' => $collection, |
|
68
|
|
|
'pagination' => $paginator->paginate( |
|
69
|
|
|
$this->repository->listAllItemsInCollection($collectionId), $request->query->getInt('page', 1),10) |
|
70
|
|
|
]); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* |
|
75
|
|
|
* @Route("/admin/delete/item-collection/{itemId}/{collectionId}", name="admin_delete_collection_item", methods={"GET"}) |
|
76
|
|
|
* @param string $itemId |
|
77
|
|
|
* @param string $collectionId |
|
78
|
|
|
* @param Request $rawRequest |
|
79
|
|
|
* @return Response|RedirectResponse |
|
80
|
|
|
*/ |
|
81
|
|
|
public function deleteCollection(string $itemId, string $collectionId, Request $rawRequest): Response |
|
|
|
|
|
|
82
|
|
|
{ |
|
83
|
|
|
try { |
|
84
|
|
|
$itemId = Uuid::fromString($itemId); |
|
85
|
|
|
$collectionId = Uuid::fromString($collectionId); |
|
86
|
|
|
$command = new RemoveItemFromCollectionCommand($itemId, $collectionId); |
|
87
|
|
|
$this->commandBus->dispatch($command); |
|
88
|
|
|
$this->addFlash('success','Item removed from collection deleted!'); |
|
89
|
|
|
} catch (\Exception $e) { |
|
90
|
|
|
$this->addFlash('danger','Error while removing item from collection: '.$e->getMessage()); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
return $this->redirectToRoute('admin_collections'); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.