MessageAdminController   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 7
dl 0
loc 56
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A batchActionPublish() 0 14 3
A batchActionCancelled() 0 12 3
A getMessageManager() 0 4 1
A getBackend() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\NotificationBundle\Controller;
15
16
use Sonata\AdminBundle\Controller\CRUDController;
17
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
18
use Sonata\NotificationBundle\Backend\BackendInterface;
19
use Sonata\NotificationBundle\Model\MessageManagerInterface;
20
use Symfony\Component\HttpFoundation\RedirectResponse;
21
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
22
23
class MessageAdminController extends CRUDController
24
{
25
    /**
26
     * @throws AccessDeniedException
27
     *
28
     * @return RedirectResponse
29
     */
30
    public function batchActionPublish(ProxyQueryInterface $query)
31
    {
32
        if (false === $this->admin->isGranted('EDIT')) {
33
            throw new AccessDeniedException();
34
        }
35
36
        foreach ($query->execute() as $message) {
37
            $message = $this->getMessageManager()->restart($message);
38
39
            $this->getBackend()->publish($message);
40
        }
41
42
        return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
43
    }
44
45
    /**
46
     * @throws AccessDeniedException
47
     *
48
     * @return RedirectResponse
49
     */
50
    public function batchActionCancelled(ProxyQueryInterface $query)
51
    {
52
        if (false === $this->admin->isGranted('EDIT')) {
53
            throw new AccessDeniedException();
54
        }
55
56
        foreach ($query->execute() as $message) {
57
            $this->getMessageManager()->cancel($message);
58
        }
59
60
        return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
61
    }
62
63
    /**
64
     * @return MessageManagerInterface
65
     */
66
    protected function getMessageManager()
67
    {
68
        return $this->get('sonata.notification.manager.message');
69
    }
70
71
    /**
72
     * @return BackendInterface
73
     */
74
    protected function getBackend()
75
    {
76
        return $this->get('sonata.notification.backend');
77
    }
78
}
79