|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* To change this license header, choose License Headers in Project Properties. |
|
5
|
|
|
* To change this template file, choose Tools | Templates |
|
6
|
|
|
* and open the template in the editor. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace AppBundle\Controller; |
|
10
|
|
|
|
|
11
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
12
|
|
|
use Doctrine\ORM\QueryBuilder; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Description of AbstractController |
|
16
|
|
|
* |
|
17
|
|
|
* @author Laurent |
|
18
|
|
|
*/ |
|
19
|
|
|
abstract class AbstractController extends Controller |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @param string $name session name |
|
23
|
|
|
* @param string $field field name |
|
24
|
|
|
* @param string $type sort type ("ASC"/"DESC") |
|
25
|
|
|
*/ |
|
26
|
|
|
protected function setOrder($name, $field, $type = 'ASC') |
|
27
|
|
|
{ |
|
28
|
|
|
$this->getRequest()->getSession()->set('sort.' . $name, array('field' => $field, 'type' => $type)); |
|
|
|
|
|
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param string $name |
|
33
|
|
|
* @return array |
|
34
|
|
|
*/ |
|
35
|
|
|
protected function getOrder($name) |
|
36
|
|
|
{ |
|
37
|
|
|
$session = $this->getRequest()->getSession(); |
|
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
return $session->has('sort.' . $name) ? $session->get('sort.' . $name) : null; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param QueryBuilder $qb |
|
44
|
|
|
* @param string $name |
|
45
|
|
|
*/ |
|
46
|
|
|
protected function addQueryBuilderSort(QueryBuilder $qb, $name) |
|
47
|
|
|
{ |
|
48
|
|
|
$alias = current($qb->getDQLPart('from'))->getAlias(); |
|
49
|
|
|
if (is_array($order = $this->getOrder($name))) { |
|
50
|
|
|
$qb->orderBy($alias . '.' . $order['field'], $order['type']); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Create Delete form |
|
56
|
|
|
* |
|
57
|
|
|
* @param integer $id |
|
58
|
|
|
* @param string $route |
|
59
|
|
|
* @return \Symfony\Component\Form\Form |
|
60
|
|
|
*/ |
|
61
|
|
|
protected function createDeleteForm($id, $route) |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->createFormBuilder(null, array('attr' => array('id' => 'delete'))) |
|
64
|
|
|
->setAction($this->generateUrl($route, array('id' => $id))) |
|
65
|
|
|
->setMethod('DELETE') |
|
66
|
|
|
->getForm() |
|
67
|
|
|
; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.