|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Del\Repository; |
|
4
|
|
|
|
|
5
|
|
|
use Del\Criteria\UserCriteria; |
|
6
|
|
|
use Del\Entity\User as UserEntity; |
|
7
|
|
|
use Doctrine\ORM\EntityRepository; |
|
8
|
|
|
|
|
9
|
|
|
class User extends EntityRepository |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @param UserEntity $user |
|
13
|
|
|
* @return UserEntity |
|
14
|
|
|
*/ |
|
15
|
2 |
|
public function save(UserEntity $user) |
|
16
|
|
|
{ |
|
17
|
2 |
|
$this->_em->persist($user); |
|
18
|
2 |
|
$this->_em->flush(); |
|
19
|
2 |
|
return $user; |
|
20
|
|
|
} |
|
21
|
|
|
/** |
|
22
|
|
|
* @param UserEntity $user |
|
23
|
|
|
*/ |
|
24
|
1 |
|
public function delete(UserEntity $user) |
|
25
|
|
|
{ |
|
26
|
1 |
|
$this->_em->remove($user); |
|
27
|
1 |
|
$this->_em->flush(); |
|
28
|
1 |
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param UserCriteria $criteria |
|
32
|
|
|
* @return array |
|
33
|
|
|
*/ |
|
34
|
|
|
public function findByCriteria(UserCriteria $criteria) |
|
35
|
|
|
{ |
|
36
|
|
|
$qb = $this->createQueryBuilder('u'); |
|
37
|
|
|
|
|
38
|
|
|
if($criteria->hasId()) { |
|
39
|
|
|
$qb->where('u.id = :id'); |
|
40
|
|
|
$qb->setParameter('id', $criteria->getId()); |
|
41
|
|
|
$criteria->setLimit(1); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
if($criteria->hasEmail()) { |
|
45
|
|
|
$qb->where('u.email = :email'); |
|
46
|
|
|
$qb->setParameter('email', $criteria->getEmail()); |
|
47
|
|
|
$criteria->setLimit(1); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
if($criteria->hasState()) { |
|
51
|
|
|
$qb->andWhere('u.state = :state'); |
|
52
|
|
|
$qb->setParameter('state', $criteria->getState()); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
if($criteria->hasRegistrationDate()) { |
|
56
|
|
|
$qb->andWhere('u.registrationDate = :regdate'); |
|
57
|
|
|
$qb->setParameter('registrationDate', $criteria->getRegistrationDate()); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
if($criteria->hasLastLoginDate()) { |
|
61
|
|
|
$qb->andWhere('u.lastLoginDate = :lastlogin'); |
|
62
|
|
|
$qb->setParameter('lastlogin', $criteria->getLastLoginDate()); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
$criteria->hasOrder() ? $qb->addOrderBy('u.'.$criteria->getOrder(),$criteria->getOrderDirection()) : null; |
|
|
|
|
|
|
66
|
|
|
$criteria->hasLimit() ? $qb->setMaxResults($criteria->getLimit()) : null; |
|
67
|
|
|
$criteria->hasOffset() ? $qb->setFirstResult($criteria->getOffset()) : null; |
|
68
|
|
|
|
|
69
|
|
|
$query = $qb->getQuery(); |
|
70
|
|
|
|
|
71
|
|
|
return $query->getResult(); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.