コード例 #1
0
 public function testGetSetHasLastLimit()
 {
     $this->assertFalse($this->criteria->hasLimit());
     $this->criteria->setLimit(100);
     $this->assertTrue($this->criteria->hasLimit());
     $this->assertEquals(100, $this->criteria->getLimit());
 }
コード例 #2
0
ファイル: UserRepository.php プロジェクト: delboy1978uk/user
 /**
  * @param UserCriteria $criteria
  * @return array
  */
 public function findByCriteria(UserCriteria $criteria)
 {
     $qb = $this->createQueryBuilder('u');
     if ($criteria->hasId()) {
         $qb->where('u.id = :id');
         $qb->setParameter('id', $criteria->getId());
         $criteria->setLimit(1);
     }
     if ($criteria->hasEmail()) {
         $qb->where('u.email = :email');
         $qb->setParameter('email', $criteria->getEmail());
         $criteria->setLimit(1);
     }
     if ($criteria->hasState()) {
         $qb->andWhere('u.state = :state');
         $qb->setParameter('state', $criteria->getState());
     }
     if ($criteria->hasRegistrationDate()) {
         $qb->andWhere('u.registrationDate = :regdate');
         $qb->setParameter('regdate', $criteria->getRegistrationDate());
     }
     if ($criteria->hasLastLoginDate()) {
         $qb->andWhere('u.lastLoginDate = :lastlogin');
         $qb->setParameter('lastlogin', $criteria->getLastLoginDate());
     }
     $criteria->hasOrder() ? $qb->addOrderBy('u.' . $criteria->getOrder(), $criteria->getOrderDirection()) : null;
     $criteria->hasLimit() ? $qb->setMaxResults($criteria->getLimit()) : null;
     $criteria->hasOffset() ? $qb->setFirstResult($criteria->getOffset()) : null;
     $query = $qb->getQuery();
     return $query->getResult();
 }