|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* AbstractController controller des méthodes communes. |
|
4
|
|
|
* |
|
5
|
|
|
* PHP Version 5 |
|
6
|
|
|
* |
|
7
|
|
|
* @author Quétier Laurent <[email protected]> |
|
8
|
|
|
* @copyright 2014 Dev-Int GLSR |
|
9
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|
10
|
|
|
* |
|
11
|
|
|
* @version since 1.0.0 |
|
12
|
|
|
* |
|
13
|
|
|
* @link https://github.com/Dev-Int/glsr |
|
14
|
|
|
*/ |
|
15
|
|
|
namespace AppBundle\Controller; |
|
16
|
|
|
|
|
17
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
18
|
|
|
use Doctrine\ORM\QueryBuilder; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Abstract controller |
|
22
|
|
|
* |
|
23
|
|
|
* @category Controller |
|
24
|
|
|
*/ |
|
25
|
|
|
abstract class AbstractController extends Controller |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* SetOrder for the SortAction in views. |
|
29
|
|
|
* |
|
30
|
|
|
* @param string $name session name |
|
31
|
|
|
* @param string $field field name |
|
32
|
|
|
* @param string $type sort type ("ASC"/"DESC") |
|
33
|
|
|
*/ |
|
34
|
|
|
protected function setOrder($name, $field, $type = 'ASC') |
|
35
|
|
|
{ |
|
36
|
|
|
$this->getRequest()->getSession()->set('sort.' . $name, array('field' => $field, 'type' => $type)); |
|
|
|
|
|
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* GetOrder for the SortAction in views. |
|
41
|
|
|
* |
|
42
|
|
|
* @param string $name |
|
43
|
|
|
* @return array |
|
44
|
|
|
*/ |
|
45
|
|
|
protected function getOrder($name) |
|
46
|
|
|
{ |
|
47
|
|
|
$session = $this->getRequest()->getSession(); |
|
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
return $session->has('sort.' . $name) ? $session->get('sort.' . $name) : null; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* AddQueryBuilderSort for the SortAction in views. |
|
54
|
|
|
* |
|
55
|
|
|
* @param QueryBuilder $qb |
|
56
|
|
|
* @param string $name |
|
57
|
|
|
*/ |
|
58
|
|
|
protected function addQueryBuilderSort(QueryBuilder $qb, $name) |
|
59
|
|
|
{ |
|
60
|
|
|
$alias = current($qb->getDQLPart('from'))->getAlias(); |
|
61
|
|
|
if (is_array($order = $this->getOrder($name))) { |
|
62
|
|
|
$qb->orderBy($alias . '.' . $order['field'], $order['type']); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Create Delete form |
|
68
|
|
|
* |
|
69
|
|
|
* @param integer $id |
|
70
|
|
|
* @param string $route |
|
71
|
|
|
* @return \Symfony\Component\Form\Form |
|
72
|
|
|
*/ |
|
73
|
|
|
protected function createDeleteForm($id, $route) |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->createFormBuilder(null, array('attr' => array('id' => 'delete'))) |
|
76
|
|
|
->setAction($this->generateUrl($route, array('id' => $id))) |
|
77
|
|
|
->setMethod('DELETE') |
|
78
|
|
|
->getForm() |
|
79
|
|
|
; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* |
|
84
|
|
|
* @return string |
|
85
|
|
|
*/ |
|
86
|
|
|
protected function testInventory() { |
|
87
|
|
|
$url = null; |
|
88
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
89
|
|
|
$inventories = $em->getRepository('AppBundle:Inventory')->getInventory(); |
|
90
|
|
|
|
|
91
|
|
|
if (empty($inventories)) { |
|
92
|
|
|
$url = null; |
|
93
|
|
|
// Go to installActions |
|
94
|
|
|
} else { |
|
95
|
|
|
foreach ($inventories as $inventory){ |
|
96
|
|
|
if ($inventory->getstatus() === 1 || $inventory->getStatus() === 2) { |
|
97
|
|
|
$message = $this->get('translator')->trans('yet',array(),'gs_inventories'); |
|
98
|
|
|
$this->addFlash('danger', $message); |
|
99
|
|
|
$url = 'inventory'; |
|
100
|
|
|
break; |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
return $url; |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|
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.