Exemplo n.º 1
0
 public function testGetSetHasOffset()
 {
     $this->assertFalse($this->criteria->hasOffset());
     $this->criteria->setOffset(38);
     $this->assertTrue($this->criteria->hasOffset());
     $this->assertEquals(38, $this->criteria->getOffset());
 }
Exemplo n.º 2
0
 /**
  * @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();
 }