1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DefaultValue\Bundle\AkeneoInlineEditBundle\Product; |
4
|
|
|
|
5
|
|
|
use Pim\Bundle\CatalogBundle\Doctrine\ORM\Repository\AttributeRepository; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Query from database product attributes |
9
|
|
|
*/ |
10
|
|
|
class ProductAttributesRepository extends AttributeRepository |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Find attributes by `scopable` attribute. By default fetches scopable attributes |
14
|
|
|
* |
15
|
|
|
* @param int $scopable |
16
|
|
|
* @return \Doctrine\ORM\QueryBuilder |
17
|
|
|
*/ |
18
|
|
View Code Duplication |
public function findByScopable($scopable = 1) |
|
|
|
|
19
|
|
|
{ |
20
|
|
|
$result = $this->getEntityManager() |
21
|
|
|
->createQueryBuilder() |
22
|
|
|
->select('attr') |
23
|
|
|
->from('PimCatalogBundle:Attribute', 'attr') |
24
|
|
|
->where('attr.scopable = :scopable') |
25
|
|
|
->setParameter(':scopable', $scopable) |
26
|
|
|
->orderBy('attr.id', 'desc'); |
27
|
|
|
|
28
|
|
|
return $result; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Find attributes by `localizable` attribute. By default fetches localizable attributes |
33
|
|
|
* |
34
|
|
|
* @param int $localizable |
35
|
|
|
* @return \Doctrine\ORM\QueryBuilder |
36
|
|
|
*/ |
37
|
|
View Code Duplication |
public function findByLocalizable($localizable = 1) |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
$result = $this->getEntityManager() |
40
|
|
|
->createQueryBuilder() |
41
|
|
|
->select('attr') |
42
|
|
|
->from('PimCatalogBundle:Attribute', 'attr') |
43
|
|
|
->where('attr.localizable = :localizable') |
44
|
|
|
->setParameter(':localizable', $localizable) |
45
|
|
|
->orderBy('attr.id', 'desc'); |
46
|
|
|
|
47
|
|
|
return $result; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Find attributes by attributeType. |
52
|
|
|
* |
53
|
|
|
* @param string $attributeType |
54
|
|
|
* @return \Doctrine\ORM\QueryBuilder |
55
|
|
|
*/ |
56
|
|
|
public function findByAttributeType($attributeType) |
57
|
|
|
{ |
58
|
|
|
$result = $this->getEntityManager() |
59
|
|
|
->createQueryBuilder() |
60
|
|
|
->select() |
61
|
|
|
->from('PimCatalogBundle:Attribute', 'attr') |
62
|
|
|
->where('attr.attributeType = :attributeType') |
63
|
|
|
->setParameter(':attributeType', $attributeType); |
64
|
|
|
|
65
|
|
|
return $result; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
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.