|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Repository; |
|
4
|
|
|
|
|
5
|
|
|
use App\Entity\Main\Product; |
|
6
|
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
|
7
|
|
|
use Doctrine\Persistence\ManagerRegistry; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @extends ServiceEntityRepository<Product> |
|
11
|
|
|
* |
|
12
|
|
|
* @method Product|null find($id, $lockMode = null, $lockVersion = null) |
|
13
|
|
|
* @method Product|null findOneBy(array $criteria, array $orderBy = null) |
|
14
|
|
|
* @method Product[] findAll() |
|
15
|
|
|
* @method Product[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) |
|
16
|
|
|
*/ |
|
17
|
|
|
class ProductRepository extends ServiceEntityRepository |
|
18
|
|
|
{ |
|
19
|
|
|
public function __construct(ManagerRegistry $registry) |
|
20
|
|
|
{ |
|
21
|
|
|
parent::__construct($registry, Product::class); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** @SuppressWarnings(PHPMD.BooleanArgumentFlag) */ |
|
25
|
|
|
public function save(Product $entity, bool $flush = false): void |
|
26
|
|
|
{ |
|
27
|
|
|
$this->getEntityManager()->persist($entity); |
|
28
|
|
|
|
|
29
|
|
|
if ($flush) { |
|
30
|
|
|
$this->getEntityManager()->flush(); |
|
31
|
|
|
} |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** @SuppressWarnings(PHPMD.BooleanArgumentFlag) */ |
|
35
|
|
|
public function remove(Product $entity, bool $flush = false): void |
|
36
|
|
|
{ |
|
37
|
|
|
$this->getEntityManager()->remove($entity); |
|
38
|
|
|
|
|
39
|
|
|
if ($flush) { |
|
40
|
|
|
$this->getEntityManager()->flush(); |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
// /** |
|
45
|
|
|
// * @return Product[] Returns an array of Product objects |
|
46
|
|
|
// */ |
|
47
|
|
|
// public function findByExampleField($value): array |
|
48
|
|
|
// { |
|
49
|
|
|
// return $this->createQueryBuilder('p') |
|
50
|
|
|
// ->andWhere('p.exampleField = :val') |
|
51
|
|
|
// ->setParameter('val', $value) |
|
52
|
|
|
// ->orderBy('p.id', 'ASC') |
|
53
|
|
|
// ->setMaxResults(10) |
|
54
|
|
|
// ->getQuery() |
|
55
|
|
|
// ->getResult() |
|
56
|
|
|
// ; |
|
57
|
|
|
// } |
|
58
|
|
|
|
|
59
|
|
|
// public function findOneBySomeField($value): ?Product |
|
60
|
|
|
// { |
|
61
|
|
|
// return $this->createQueryBuilder('p') |
|
62
|
|
|
// ->andWhere('p.exampleField = :val') |
|
63
|
|
|
// ->setParameter('val', $value) |
|
64
|
|
|
// ->getQuery() |
|
65
|
|
|
// ->getOneOrNullResult() |
|
66
|
|
|
// ; |
|
67
|
|
|
// } |
|
68
|
|
|
} |
|
69
|
|
|
|