|
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
|
|
|
public function getArticles() |
|
33
|
|
|
{ |
|
34
|
|
|
$query = $this->createQueryBuilder('a') |
|
35
|
|
|
->leftjoin('a.supplier', 's') |
|
36
|
|
|
->addSelect('s') |
|
37
|
|
|
->where('a.active = 1') |
|
38
|
|
|
->orderBy('a.name', 'ASC'); |
|
39
|
|
|
|
|
40
|
|
|
return $query; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Affiche les articles actifs. |
|
45
|
|
|
* |
|
46
|
|
|
* @return array |
|
47
|
|
|
*/ |
|
48
|
|
|
public function getResultArticles() |
|
49
|
|
|
{ |
|
50
|
|
|
$query = $this->getArticles()->getQuery(); |
|
51
|
|
|
|
|
52
|
|
|
return $query->getResult(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Renvoi les article du fournisseur en paramètre. |
|
57
|
|
|
* |
|
58
|
|
|
* @param int $supplier Supplier_id |
|
59
|
|
|
* |
|
60
|
|
|
* @return array Query result |
|
61
|
|
|
*/ |
|
62
|
|
View Code Duplication |
public function getArticleFromSupplier($supplier) |
|
|
|
|
|
|
63
|
|
|
{ |
|
64
|
|
|
$query = $this->createQueryBuilder('a') |
|
65
|
|
|
->where('a.active = true') |
|
66
|
|
|
->andWhere('a.supplier = :id') |
|
67
|
|
|
->setParameter('id', $supplier) |
|
68
|
|
|
->orderBy('a.name', 'ASC') |
|
69
|
|
|
->getQuery(); |
|
70
|
|
|
|
|
71
|
|
|
return $query->getResult(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
View Code Duplication |
public function getStockAlert($count) { |
|
|
|
|
|
|
75
|
|
|
$query = $this->createQueryBuilder('a') |
|
76
|
|
|
->where('a.active = true') |
|
77
|
|
|
->andWhere('a.quantity < a.minstock') |
|
78
|
|
|
->orderBy('a.name', 'ASC') |
|
79
|
|
|
->setMaxResults($count) |
|
80
|
|
|
->getQuery(); |
|
81
|
|
|
|
|
82
|
|
|
return $query->getResult(); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
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.