AttachFileAdminController::fileDeleteAction()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 16
rs 9.4285
cc 3
eloc 9
nc 3
nop 1
1
<?php
2
3
namespace ItBlaster\AttachFileBundle\Controller;
4
5
6
use ItBlaster\AttachFileBundle\Model\AttachFileQuery;
7
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
8
use Symfony\Component\HttpFoundation\JsonResponse;
9
use Symfony\Component\HttpFoundation\Request;
10
11
/**
12
 * Class AttachFileAdminController
13
 * @package ItBlaster\AttachFileBundle\Controller
14
 */
15
class AttachFileAdminController extends Controller
16
{
17
    /**
18
     * Удаление файла
19
     *
20
     * @param Request $request
21
     * @return \Symfony\Component\HttpFoundation\Response
22
     */
23
    public function fileDeleteAction(Request $request)
24
    {
25
        if (!$this->get('security.context')->isGranted('ROLE_SUPER_ADMIN')) {
26
            throw new \Exception('Access denied');
27
        }
28
29
        $id = $request->get('attach_file');
30
        $attach_file = AttachFileQuery::create()->findOneById($id);
31
32
        $success = $attach_file ? $attach_file->deleteFile() : false;
33
34
        $response = new JsonResponse(array(
35
            'success'   =>  $success,
36
        ));
37
        return $response;
38
    }
39
}