|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Entité Article. |
|
5
|
|
|
* |
|
6
|
|
|
* PHP Version 5 |
|
7
|
|
|
* |
|
8
|
|
|
* @author Quétier Laurent <[email protected]> |
|
9
|
|
|
* @copyright 2014 Dev-Int GLSR |
|
10
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|
11
|
|
|
* |
|
12
|
|
|
* @version since 1.0.0 |
|
13
|
|
|
* |
|
14
|
|
|
* @link https://github.com/Dev-Int/glsr |
|
15
|
|
|
*/ |
|
16
|
|
|
namespace AppBundle\Entity; |
|
17
|
|
|
|
|
18
|
|
|
use Doctrine\ORM\EntityRepository; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* ArticleRepository. |
|
22
|
|
|
* |
|
23
|
|
|
* @category Entity |
|
24
|
|
|
*/ |
|
25
|
|
|
class ArticleRepository extends EntityRepository |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* Affiche les articles actifs. |
|
29
|
|
|
* |
|
30
|
|
|
* @return QueryBuilder Requête DQL |
|
31
|
|
|
*/ |
|
32
|
|
View Code Duplication |
public function getAllArticles() |
|
|
|
|
|
|
33
|
|
|
{ |
|
34
|
|
|
$query = $this->createQueryBuilder('a') |
|
35
|
|
|
->join('a.supplier', 's') |
|
36
|
|
|
->addSelect('s') |
|
37
|
|
|
->where('s.active = 1') |
|
38
|
|
|
->join('a.familyLog', 'fl') |
|
39
|
|
|
->addSelect('fl') |
|
40
|
|
|
->join('a.zoneStorages', 'z') |
|
41
|
|
|
->addSelect('z') |
|
42
|
|
|
; |
|
43
|
|
|
|
|
44
|
|
|
return $query; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Affiche les articles actifs. |
|
49
|
|
|
* |
|
50
|
|
|
* @return QueryBuilder Requête DQL |
|
51
|
|
|
*/ |
|
52
|
|
View Code Duplication |
public function getArticles() |
|
|
|
|
|
|
53
|
|
|
{ |
|
54
|
|
|
$query = $this->createQueryBuilder('a') |
|
55
|
|
|
->join('a.supplier', 's') |
|
56
|
|
|
->addSelect('s') |
|
57
|
|
|
->where('s.active = 1') |
|
58
|
|
|
->join('a.familyLog', 'fl') |
|
59
|
|
|
->addSelect('fl') |
|
60
|
|
|
->join('a.zoneStorages', 'z') |
|
61
|
|
|
->addSelect('z') |
|
62
|
|
|
->where('a.active = 1') |
|
63
|
|
|
; |
|
64
|
|
|
|
|
65
|
|
|
return $query; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Affiche les articles actifs. |
|
70
|
|
|
* |
|
71
|
|
|
* @return array Query result |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getResultArticles() |
|
74
|
|
|
{ |
|
75
|
|
|
$query = $this->getArticles()->getQuery(); |
|
76
|
|
|
|
|
77
|
|
|
return $query->getResult(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Renvoi les article du fournisseur en paramètre. |
|
82
|
|
|
* |
|
83
|
|
|
* @param int $supplier Supplier_id |
|
84
|
|
|
* |
|
85
|
|
|
* @return array Query result |
|
86
|
|
|
*/ |
|
87
|
|
|
public function getArticleFromSupplier($supplier) |
|
|
|
|
|
|
88
|
|
|
{ |
|
89
|
|
|
$query = $this->createQueryBuilder('a') |
|
90
|
|
|
->where('a.active = true') |
|
91
|
|
|
->andWhere('a.supplier = :id') |
|
92
|
|
|
->setParameter('id', $supplier) |
|
93
|
|
|
->orderBy('a.name', 'ASC') |
|
94
|
|
|
->getQuery(); |
|
95
|
|
|
|
|
96
|
|
|
return $query->getResult(); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Renvoi les articles en stock d'alerte. |
|
101
|
|
|
* |
|
102
|
|
|
* @param integer $count Nombre d'élément à afficher |
|
103
|
|
|
* @return array Query result |
|
104
|
|
|
*/ |
|
105
|
|
|
public function getStockAlert($count) |
|
|
|
|
|
|
106
|
|
|
{ |
|
107
|
|
|
$query = $this->createQueryBuilder('a') |
|
108
|
|
|
->where('a.active = true') |
|
109
|
|
|
->andWhere('a.quantity < a.minstock') |
|
110
|
|
|
->orderBy('a.name', 'ASC') |
|
111
|
|
|
->setMaxResults($count) |
|
112
|
|
|
->getQuery(); |
|
113
|
|
|
|
|
114
|
|
|
return $query->getResult(); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.