Failed Conditions
Push — issue#808 ( 868db7...3c2936 )
by Guilherme
07:23
created

SuggestionController   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 40
dl 0
loc 62
ccs 0
cts 49
cp 0
rs 10
c 0
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A indexAction() 0 5 1
B listQueryAction() 0 44 6
1
<?php
2
3
namespace LoginCidadao\CoreBundle\Controller\Admin;
4
5
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6
use Symfony\Component\Routing\Annotation\Route;
7
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
8
use Symfony\Component\HttpFoundation\Request;
9
use LoginCidadao\CoreBundle\Form\Type\SuggestionFilterFormType;
10
use LoginCidadao\CoreBundle\Helper\GridHelper;
11
12
/**
13
 * @Route("/admin/suggestion")
14
 */
15
class SuggestionController extends Controller
16
{
17
18
    /**
19
     * @Route("/", name="lc_admin_sugg")
20
     * @Template()
21
     */
22
    public function indexAction(Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request 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

22
    public function indexAction(/** @scrutinizer ignore-unused */ Request $request)

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...
23
    {
24
        $form = $this->createForm('LoginCidadao\CoreBundle\Form\Type\SuggestionFilterFormType');
25
        $form = $form->createView();
26
        return compact('form');
27
    }
28
29
    /**
30
     * @Route("/listQuery", name="lc_admin_sugg_list_query")
31
     * @Template()
32
     */
33
    public function listQueryAction(Request $request)
34
    {
35
        $form           = $this->createForm('LoginCidadao\CoreBundle\Form\Type\SuggestionFilterFormType');
36
        $form->handleRequest($request);
37
        $result['grid'] = null;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$result was never initialized. Although not strictly required by PHP, it is generally a good practice to add $result = array(); before regardless.
Loading history...
38
        if ($form->isValid()) {
39
            $em    = $this->getDoctrine()->getManager();
40
            $sql   = $em->createQueryBuilder();
41
            $sql->select('cs.id, cs.createdAt, cs.text shorttext, u.username');
42
            $sql->from('LoginCidadaoCoreBundle:ClientSuggestion', 'cs');
43
            $sql->join('LoginCidadaoCoreBundle:Person', 'u', 'WITH',
44
                'cs.person = u');
45
            $sql->where('1=1');
46
            $parms = $form->getData();
47
            if (isset($parms['username'][0])) {
48
                $sql->andWhere('u.username = ?1');
49
                $sql->setParameter('1', $parms['username']);
50
            }
51
            if (isset($parms['dateini'])) {
52
                $sql->andWhere('cs.createdAt >= ?2');
53
                $sql->setParameter('2', $parms['dateini']);
54
            }
55
            if (isset($parms['dateend'])) {
56
                $sql->andWhere('cs.createdAt <= ?3');
57
                $sql->setParameter('3', $parms['dateend']);
58
            }
59
            if (isset($parms['text'][0])) {
60
                $sql->andWhere("cs.text like ?4");
61
                $sql->setParameter('4',
62
                    '%'.addcslashes($parms['text'], '\\%_').'%');
63
            }
64
            $sql->addOrderBy('cs.createdAt');
65
66
            $grid = new GridHelper();
67
            $grid->setId('suggs-grid');
68
            $grid->setPerPage(5);
69
            $grid->setMaxResult(5);
70
            $grid->setQueryBuilder($sql);
0 ignored issues
show
Deprecated Code introduced by
The function LoginCidadao\CoreBundle\...lper::setQueryBuilder() has been deprecated: since version 1.1.0 ( Ignorable by Annotation )

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

70
            /** @scrutinizer ignore-deprecated */ $grid->setQueryBuilder($sql);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
71
            $grid->setInfiniteGrid(true);
72
            $grid->setRoute('lc_admin_sugg_list_query');
73
            $grid->setRouteParams(array($form->getName()));
74
            return array('grid' => $grid->createView($request));
75
        }
76
        return $result;
77
    }
78
}
79