/
ExceptionController.php
91 lines (76 loc) · 2.62 KB
/
ExceptionController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace Kunstmaan\AdminBundle\Controller;
use Doctrine\ORM\EntityManager;
use Kunstmaan\AdminBundle\AdminList\ExceptionAdminListConfigurator;
use Kunstmaan\AdminBundle\Entity\Exception;
use Kunstmaan\AdminListBundle\Controller\AdminListController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
class ExceptionController extends AdminListController
{
/** @var ExceptionAdminListConfigurator */
private $configurator;
private function getAdminListConfigurator()
{
if (!isset($this->configurator)) {
$this->configurator = new ExceptionAdminListConfigurator($this->getEntityManager());
}
return $this->configurator;
}
/**
* @Route("/", name="kunstmaanadminbundle_admin_exception")
*/
public function indexAction(Request $request)
{
return parent::doIndexAction($this->getAdminListConfigurator(), $request);
}
/**
* @Route("/resolve_all", name="kunstmaanadminbundle_admin_exception_resolve_all")
*
* @return RedirectResponse
*
* @throws \Doctrine\ORM\NonUniqueResultException
* @throws \Doctrine\ORM\NoResultException
* @throws \InvalidArgumentException
*/
public function resolveAllAction()
{
$this->getEntityManager()->getRepository(Exception::class)->markAllAsResolved();
$indexUrl = $this->getAdminListConfigurator()->getIndexUrl();
return new RedirectResponse(
$this->generateUrl(
$indexUrl['path'],
isset($indexUrl['params']) ? $indexUrl['params'] : array()
)
);
}
/**
* @Route("/toggle_resolve/{id}", name="kunstmaanadminbundle_admin_exception_toggle_resolve")
*
* @param Request $request
* @param Exception $model
*
* @return RedirectResponse
*
* @throws \Doctrine\ORM\OptimisticLockException
* @throws \InvalidArgumentException
* @throws \Doctrine\ORM\ORMInvalidArgumentException
*/
public function toggleResolveAction(Request $request, Exception $model)
{
/* @var EntityManager $em */
$em = $this->getEntityManager();
$this->getAdminListConfigurator();
$model->setResolved(!$model->isResolved());
$em->persist($model);
$em->flush();
$indexUrl = $this->configurator->getIndexUrl();
return new RedirectResponse(
$this->generateUrl(
$indexUrl['path'],
isset($indexUrl['params']) ? $indexUrl['params'] : array()
)
);
}
}