Completed
Push — master ( c49bae...43ad9f )
by
unknown
09:25
created

CRUDController::imageAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 4
crap 1
1
<?php
2
3
namespace MediaMonks\SonataMediaBundle\Controller;
4
5
use Sonata\AdminBundle\Controller\CRUDController as BaseCRUDController;
6
use Symfony\Component\HttpFoundation\RedirectResponse;
7
use Symfony\Component\HttpFoundation\Request;
8
use Symfony\Component\HttpFoundation\StreamedResponse;
9
10
class CRUDController extends BaseCRUDController
11
{
12
    /**
13
     * @return \Symfony\Component\HttpFoundation\Response
14
     */
15 5
    public function createAction()
16
    {
17 5
        if (!$this->getRequest()->get('provider') && $this->getRequest()->isMethod('get')) {
18
            return $this->render(
19
                '@MediaMonksSonataMedia/CRUD/select_provider.html.twig',
20
                [
21
                    'providers' => $this->get('mediamonks.sonata_media.provider.pool')->getProviders(),
22
                    'base_template' => $this->getBaseTemplate(),
23
                    'admin' => $this->admin,
24
                    'action' => 'create',
25
                ]
26
            );
27
        }
28
29 5
        return parent::createAction();
30
    }
31
32
    /**
33
     * @param Request $request
34
     * @param $id
35
     * @return StreamedResponse
36
     */
37
    public function downloadAction(Request $request, $id)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

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

Loading history...
38
    {
39
        $object = $this->admin->getObject($id);
40
41
        $this->admin->checkAccess('show', $object);
42
43
        return $this->get('mediamonks.sonata_media.utility.download')->getStreamedResponse($object);
44
    }
45
46
    /**
47
     * @param Request $request
48
     * @param int $id
49
     * @return RedirectResponse
50
     */
51 3
    public function imageAction(Request $request, $id, $width, $height)
52
    {
53 3
        $object = $this->admin->getObject($id);
54
55 3
        $this->admin->checkAccess('show', $object);
56
57 3
        return $this->get('mediamonks.sonata_media.utility.image')->getRedirectResponse(
58 3
            $object,
59 3
            $width,
60 3
            $height,
61 3
            $request->query->all()
62 3
        );
63
    }
64
}
65