Passed
Push — develop ( 1d51ce...e805ec )
by BENARD
06:13
created

GameAdminController::setProofVideoOnly()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VideoGamesRecords\CoreBundle\Controller\Admin;
6
7
use Sonata\AdminBundle\Controller\CRUDController;
8
use Symfony\Component\HttpFoundation\RedirectResponse;
9
use Symfony\Component\HttpFoundation\Request;
10
use Symfony\Component\HttpFoundation\Response;
11
use VideoGamesRecords\CoreBundle\Entity\Game;
12
use VideoGamesRecords\CoreBundle\Form\DefaultForm;
13
use VideoGamesRecords\CoreBundle\Form\VideoProofOnly;
14
use VideoGamesRecords\CoreBundle\Manager\GameManager;
15
use Yokai\SonataWorkflow\Controller\WorkflowControllerTrait;
16
17
class GameAdminController extends CRUDController
18
{
19
    use WorkflowControllerTrait;
20
21
    private GameManager $gameManager;
22
23
    public function __construct(GameManager $gameManager)
24
    {
25
        $this->gameManager = $gameManager;
26
    }
27
28
    /**
29
     * @param $id
30
     * @param Request $request
31
     * @return Response
32
     */
33
    public function copyAction($id, Request $request): Response
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

33
    public function copyAction(/** @scrutinizer ignore-unused */ $id, Request $request): Response

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
34
    {
35
        /** @var Game $game */
36
        $game = $this->admin->getSubject();
37
38
        $form = $this->createForm(DefaultForm::class);
39
        $form->handleRequest($request);
40
        if ($form->isSubmitted() && $form->isValid()) {
41
            $this->gameManager->copy($game);
42
            $this->addFlash('sonata_flash_success', 'The game was successfully copied.');
43
            return new RedirectResponse($this->admin->generateUrl('show', ['id' => $game->getId()]));
44
        }
45
46
        return $this->render(
47
            '@VideoGamesRecordsCore/Admin/Form/form.default.html.twig',
48
            [
49
                'base_template' => '@SonataAdmin/standard_layout.html.twig',
50
                'admin' => $this->admin,
51
                'object' => $game,
52
                'form' => $form,
53
                'title' => 'Copy => ' . $game->getName(),
54
                'action' => 'edit'
55
            ]
56
        );
57
    }
58
59
    /**
60
     * @param $id
61
     * @return RedirectResponse
62
     */
63
    public function majAction($id): RedirectResponse
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

63
    public function majAction(/** @scrutinizer ignore-unused */ $id): RedirectResponse

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
64
    {
65
        $this->gameManager->maj($this->admin->getSubject());
66
        $this->addFlash('sonata_flash_success', 'Game maj successfully');
67
        return new RedirectResponse($this->admin->generateUrl('list'));
68
    }
69
70
    /**
71
     * @param         $id
72
     * @param Request $request
73
     * @return RedirectResponse|Response
74
     */
75
    public function setVideoProofOnlyAction($id, Request $request): RedirectResponse|Response
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

75
    public function setVideoProofOnlyAction(/** @scrutinizer ignore-unused */ $id, Request $request): RedirectResponse|Response

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
76
    {
77
        /** @var Game $game */
78
        $game = $this->admin->getSubject();
79
80
        $em = $this->admin->getModelManager()->getEntityManager($this->admin->getClass());
0 ignored issues
show
Bug introduced by
The method getEntityManager() does not exist on Sonata\AdminBundle\Model\ModelManagerInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Sonata\AdminBundle\Model\LockInterface. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

80
        $em = $this->admin->getModelManager()->/** @scrutinizer ignore-call */ getEntityManager($this->admin->getClass());
Loading history...
81
        $form = $this->createForm(VideoProofOnly::class);
82
        $form->handleRequest($request);
83
        if ($form->isSubmitted() && $form->isValid()) {
84
            $data = $form->getData();
85
            $isVideoProofOnly = $data['isVideoProofOnly'];
86
            foreach ($game->getGroups() as $group) {
87
                foreach ($group->getCharts() as $chart) {
88
                    $chart->setIsProofVideoOnly($isVideoProofOnly);
89
                }
90
            }
91
            $em->flush();
92
93
            $this->addFlash('sonata_flash_success', 'All charts are updated successfully');
94
            return new RedirectResponse($this->admin->generateUrl('show', ['id' => $game->getId()]));
95
        }
96
97
        return $this->render(
98
            '@VideoGamesRecordsCore/Admin/Form/form.set_video_proof_only.html.twig',
99
            [
100
                'base_template' => '@SonataAdmin/standard_layout.html.twig',
101
                'admin' => $this->admin,
102
                'object' => $game,
103
                'form' => $form,
104
                'title' => $game->getName(),
105
                'action' => 'edit'
106
            ]
107
        );
108
    }
109
}
110