Completed
Push — master ( a3a68a...0a1479 )
by Joachim
02:49
created

LabelController::resetStatusAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
namespace Loevgaard\PakkelabelsBundle\Controller;
4
5
use Loevgaard\PakkelabelsBundle\Entity\Label;
6
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
7
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
8
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
9
use Symfony\Component\HttpFoundation\BinaryFileResponse;
10
use Symfony\Component\HttpFoundation\RedirectResponse;
11
use Symfony\Component\HttpFoundation\Request;
12
use Symfony\Component\HttpFoundation\Response;
13
14
/**
15
 * @Route("/label")
16
 */
17
class LabelController extends Controller
18
{
19
    /**
20
     * @Method("GET")
21
     * @Route("", name="loevgaard_pakkelabels_label_index")
22
     *
23
     * @param Request $request
24
     *
25
     * @return Response
26
     */
27 View Code Duplication
    public function indexAction(Request $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
28
    {
29
        $repos = $this->get('loevgaard_pakkelabels.label_repository');
30
31
        /** @var Label[] $labels */
32
        $labels = $repos->findAllWithPaging($request->query->getInt('page', 1));
33
34
        return $this->render('@LoevgaardPakkelabels/label/index.html.twig', [
35
            'labels' => $labels,
36
        ]);
37
    }
38
39
    /**
40
     * @Method("GET")
41
     * @Route("/{id}/show", name="loevgaard_pakkelabels_label_show")
42
     *
43
     * @param Label $label
44
     *
45
     * @return Response
46
     */
47
    public function showAction(Label $label): Response
48
    {
49
        return $this->render('@LoevgaardPakkelabels/label/show.html.twig', [
50
            'label' => $label,
51
        ]);
52
    }
53
54
    /**
55
     * @Method("GET")
56
     * @Route("/{id}/image", name="loevgaard_pakkelabels_label_image")
57
     *
58
     * @param Label $label
59
     *
60
     * @return BinaryFileResponse
61
     */
62
    public function imageAction(Label $label): BinaryFileResponse
63
    {
64
        $labelFactory = $this->get('loevgaard_pakkelabels.label_file_factory');
65
66
        // @todo remember to catch exception, maybe create a new exception class
67
        $labelFile = $labelFactory->read($label, true);
68
69
        return new BinaryFileResponse($labelFile);
70
    }
71
72
    /**
73
     * @Method("GET")
74
     * @Route("/{id}/reset-status", name="loevgaard_pakkelabels_label_reset_status")
75
     *
76
     * @param Label $label
77
     *
78
     * @return RedirectResponse
79
     */
80
    public function resetStatusAction(Label $label): RedirectResponse
81
    {
82
        $labelRepository = $this->get('loevgaard_pakkelabels.label_repository');
83
        $label->resetStatus();
84
        $labelRepository->save($label);
85
86
        return $this->redirectToRoute('loevgaard_pakkelabels_label_index');
87
    }
88
}
89