public function testQuerySetOffsetToZero()
 {
     $q = new Doctrine_Query();
     $q->from('User u');
     $q->offset(20);
     $q->offset(0);
     $this->assertEqual($q->getSqlQuery(), 'SELECT e.id AS e__id, e.name AS e__name, e.loginname AS e__loginname, e.password AS e__password, e.type AS e__type, e.created AS e__created, e.updated AS e__updated, e.email_id AS e__email_id FROM entity e WHERE (e.type = 0)');
 }
Example #2
0
 /**
  * Get items
  *
  * @param int $offset
  * @param int $itemsPerPage
  * @return Doctrine_Collection
  */
 public function getItems($offset, $itemsPerPage)
 {
     if ($itemsPerPage !== null) {
         $this->_query->limit($itemsPerPage);
     }
     if ($offset !== null) {
         $this->_query->offset($offset);
     }
     return $this->_query->execute();
 }
Example #3
0
 /**
  * Implementation of method from Zend_Paginator_Adapter_Interface.
  *
  * @param integer $offset
  * @param integer $itemsPerPage
  * @return array[numeric|whatever]=>array|Doctrine_Record
  */
 public function getItems($offset, $itemsPerPage)
 {
     $this->_query->limit($itemsPerPage);
     $this->_query->offset($offset);
     $result = $this->_query->execute(array(), $this->_hydrationMode);
     return $result;
 }
 /**
  * set the hook offset
  *
  * @param integer $offset
  */
 public function hookOffset($offset)
 {
     $this->query->offset((int) $offset);
 }
 /**
  * Typesafe call to modify
  * @access private
  **/
 protected function modifyImpl(Doctrine_Query &$o)
 {
     $o->offset($this->offset);
     if ($this->limit > 0) {
         $o->limit($this->limit);
     }
 }
 public function testLimitWithOneToManyInnerJoin()
 {
     $q = new Doctrine_Query();
     $q->select('u.id, p.*')->from('User u INNER JOIN u.Phonenumber p');
     $q->limit(5);
     $sql = $q->getQuery();
     $users = $q->execute();
     $count = $this->conn->count();
     $this->assertEqual($users->count(), 5);
     $users[0]->Phonenumber[0];
     $this->assertEqual($count, $this->conn->count());
     $q->offset(2);
     $users = $q->execute();
     $count = $this->conn->count();
     $this->assertEqual($users->count(), 5);
     $users[3]->Phonenumber[0];
     $this->assertEqual($count, $this->conn->count());
     $this->assertEqual($q->getQuery(), 'SELECT e.id AS e__id, p.id AS p__id, p.phonenumber AS p__phonenumber, p.entity_id AS p__entity_id FROM entity e INNER JOIN phonenumber p ON e.id = p.entity_id WHERE e.id IN (SELECT DISTINCT e2.id FROM entity e2 INNER JOIN phonenumber p2 ON e2.id = p2.entity_id WHERE (e2.type = 0) LIMIT 5 OFFSET 2) AND (e.type = 0)');
 }
 /**
  * Add a limit/offset to a Doctrine_Query.
  *
  * @param Doctrine_Query $q
  * @param int   $limit
  * @param int   $offset
  */
 protected function rec_query_page(Doctrine_Query $q, $limit, $offset)
 {
     if ($limit > 0) {
         $q->limit($limit);
     }
     if ($offset > 0) {
         $q->offset($offset);
     }
 }
Example #8
0
 static function setPagingFromOptions(Doctrine_Query $q, array $options, $defaultNum = null, $maxNum = null)
 {
     $num = @$options['num'] ? $options['num'] : $defaultNum;
     if ($num && $maxNum) {
         $num = $num > $maxNum ? $maxNum : $num;
     }
     if ($num) {
         $q->limit($num);
         if ($page = @$options['page']) {
             $q->offset($num * ($page - 1));
         }
     }
     return $q;
 }