Пример #1
0
 public function testNumbers()
 {
     $pagination = new Pagination(['context' => $this->context]);
     $set = new Set(null, ['page' => 1, 'total' => 25, 'limit' => 5]);
     $res = $pagination->numbers(['documents' => $set]);
     $this->assertEqual([1, 2, 3, 4, 5], $res);
     $set->meta(['total' => 100]);
     $res = $pagination->numbers(['documents' => $set]);
     $this->assertEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], $res);
     $set->meta(['page' => 20]);
     $res = $pagination->numbers(['documents' => $set]);
     $this->assertEqual([11, 12, 13, 14, 15, 16, 17, 18, 19, 20], $res);
     $set->meta(['total' => 10]);
     $res = $pagination->numbers(['documents' => $set]);
     $this->assertEqual([1, 2], $res);
 }
Пример #2
0
 /**
  * Executes the 2 necessary requests : count and all.
  *
  * @param  Request       $request Lithium http request
  * @param  array         $query   Model query
  * @return PaginableSet           A paginable documents set
  */
 public static function paginate(Request $request, array $query = [])
 {
     $query += ['limit' => 20];
     $page = static::_page($request);
     $total = static::count($query);
     $records = static::all(['page' => $page] + $query);
     $return = new PaginableSet($records);
     $return->meta(['page' => $page, 'total' => $total, 'limit' => $query['limit']]);
     return $return;
 }