-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserRepository.php
77 lines (68 loc) · 2.02 KB
/
UserRepository.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
namespace App\Repository;
use App\Entity\User;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\QueryBuilder;
use Symfony\Bridge\Doctrine\RegistryInterface;
/**
* @method User|null find($id, $lockMode = null, $lockVersion = null)
* @method User|null findOneBy(array $criteria, array $orderBy = null)
* @method User[] findAll()
* @method User[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class UserRepository extends ServiceEntityRepository
{
public function __construct(RegistryInterface $registry)
{
parent::__construct($registry, User::class);
}
// /**
// * @return User[] Returns an array of User objects
// */
/*
public function findByExampleField($value)
{
return $this->createQueryBuilder('u')
->andWhere('u.exampleField = :val')
->setParameter('val', $value)
->orderBy('u.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
}
*/
/*
public function findOneBySomeField($value): ?User
{
return $this->createQueryBuilder('u')
->andWhere('u.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
*/
public function findAllWithMoreThan5Posts()
{
$this->findAllWithMoreThan5PostsQuery()
->getQuery()
->getResult();
}
public function findAllWithMoreThan5PostsExceptUser(User $user)
{
return $this->findAllWithMoreThan5PostsQuery()
->andHaving('u != :user')
->setParameter('user', $user)
->getQuery()
->getResult();
}
private function findAllWithMoreThan5PostsQuery(): QueryBuilder
{
$qb = $this->createQueryBuilder('u');
return $qb->select('u')
->innerJoin('u.posts', 'mp')
->groupBy('u')
->having('count(mp) > 5');
}
}