예제 #1
0
 /**
  * create pagination with only previous and next buttons
  *
  * @return array
  */
 public function simpleRendeArray()
 {
     $array = [];
     $count = $this->paginator->getCount();
     $url = $this->path;
     $current = $this->paginator->getCurrentPage();
     // create appends string
     $appends = $this->createAppendString($this->paginator->getAppends());
     // create fragments string
     $fragments = $this->createFragmentsString($this->paginator->getFragments());
     if ($count < $this->paginator->getPerPage()) {
         $limit = 1;
     } else {
         $limit = ceil($count / $this->paginator->getPerPage());
     }
     if ($this->isAvaibleCurrentPage($current) && $current > 1) {
         $previous = $current - 1;
         $array[] = $this->buildChieldString('Previous', $this->buildFullChieldStrind($url, $appends), $this->pageName, $fragments, $previous);
     }
     if ($this->isAvaibleCurrentPage($current) && $current < $limit) {
         $next = $current + 1;
         $array[] = $this->buildChieldString('Next', $this->buildFullChieldStrind($url, $appends), $this->pageName, $fragments, $next);
     }
     return $array;
 }
예제 #2
0
 public function getResultPaginate()
 {
     if (count($this->results) <= 0) {
         $this->getResult();
     }
     $currentPage = \Paginator::getCurrentPage();
     return array_slice($this->results, ($currentPage - 1) * static::$app['config']->get('statistics::paginate_num'), static::$app['config']->get('statistics::paginate_num'));
 }
 /**
  * Retorna articulos segun tag
  * @return object
  */
 public function generar_paginacion_articulos_segun_tag()
 {
     $sEntrada = Input::get('sEntrada');
     $oArticuloCaracteristicaValorCategoria = new ArticuloCaracteristicaValorCategoria();
     $oElementosPaginacion = $oArticuloCaracteristicaValorCategoria->Obtener_todos_segun_tag($sEntrada);
     //dd($oElementosPaginacion);die;
     // Get pagination information and slice the results.
     $iElementpsPorPagina = 8;
     $iTotalElementosPaginacion = count($oElementosPaginacion);
     $start = (Paginator::getCurrentPage() - 1) * $iElementpsPorPagina;
     $sliced = array_slice($oElementosPaginacion, $start, $iElementpsPorPagina);
     // Eager load the relation.
     $oColeccion = Articulo::hydrate($sliced);
     // Create a paginator instance.
     return Paginator::make($oColeccion->all(), $iTotalElementosPaginacion, $iElementpsPorPagina);
 }
예제 #4
0
 public function testGetData()
 {
     var_dump(Paginator::getCurrentPage());
 }
예제 #5
0
 /**
  * @param Paginator $items
  * @param $data
  * @return \Illuminate\Http\JsonResponse
  */
 protected function respondWithPagination($items, $data)
 {
     $data = array_merge($data, ['paginator' => ['total_count' => $items->getTotal(), 'total_pages' => ceil($items->getTotal() / $items->getPerPage()), 'current_page' => $items->getCurrentPage(), 'limit' => $items->getPerPage()]]);
     return $this->respond($data);
 }
예제 #6
0
        }
        if (!empty($limit)) {
            $this->setItemsPerPage($limit);
        }
        // quickly calculate the offset based on the page
        if ($page > 0) {
            $page -= 1;
        }
        $offset = $page * $this->_itemsPerPage;
        // return the limit iterator
        return new LimitIterator($this->_it, $offset, $this->_itemsPerPage);
    }
}
// generate an example of page items to iterate over
$items = array(array('id' => 1, 'name' => 'Item 1', 'desc' => 'Description', 'price' => 4.99), array('id' => 2, 'name' => 'Item 2', 'desc' => 'Description', 'price' => 4.99), array('id' => 3, 'name' => 'Item 3', 'desc' => 'Description', 'price' => 4.99), array('id' => 4, 'name' => 'Item 4', 'desc' => 'Description', 'price' => 4.99), array('id' => 5, 'name' => 'Item 5', 'desc' => 'Description', 'price' => 4.99), array('id' => 6, 'name' => 'Item 6', 'desc' => 'Description', 'price' => 4.99), array('id' => 7, 'name' => 'Item 7', 'desc' => 'Description', 'price' => 4.99), array('id' => 8, 'name' => 'Item 8', 'desc' => 'Description', 'price' => 4.99), array('id' => 9, 'name' => 'Item 9', 'desc' => 'Description', 'price' => 4.99), array('id' => 10, 'name' => 'Item 10', 'desc' => 'Description', 'price' => 4.99), array('id' => 11, 'name' => 'Item 11', 'desc' => 'Description', 'price' => 4.99), array('id' => 12, 'name' => 'Item 12', 'desc' => 'Description', 'price' => 4.99), array('id' => 13, 'name' => 'Item 13', 'desc' => 'Description', 'price' => 4.99), array('id' => 14, 'name' => 'Item 14', 'desc' => 'Description', 'price' => 4.99), array('id' => 15, 'name' => 'Item 15', 'desc' => 'Description', 'price' => 4.99), array('id' => 16, 'name' => 'Item 16', 'desc' => 'Description', 'price' => 4.99), array('id' => 17, 'name' => 'Item 17', 'desc' => 'Description', 'price' => 4.99), array('id' => 18, 'name' => 'Item 18', 'desc' => 'Description', 'price' => 4.99), array('id' => 19, 'name' => 'Item 19', 'desc' => 'Description', 'price' => 4.99), array('id' => 20, 'name' => 'Item 20', 'desc' => 'Description', 'price' => 4.99), array('id' => 21, 'name' => 'Item 21', 'desc' => 'Description', 'price' => 4.99));
// load the paginator
$Paginator = new Paginator(new ArrayIterator($items));
// displays the initial set (page 1, limit 10)
$results = $Paginator->render();
foreach ($results as $r) {
    var_dump($r);
}
// check for another page
if ($Paginator->hasNextPage()) {
    echo 'DISPLAYING THE NEXT SET OF RESULTS AS AN EXAMPLE' . PHP_EOL;
    // displays the next page results as an example
    $results = $Paginator->render($Paginator->getCurrentPage() + 1);
    foreach ($results as $r) {
        var_dump($r);
    }
}
 /**
  * @param Paginator $elements
  * @param $data
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function respondWithPagination(Paginator $elements, $data)
 {
     $data = array_merge($data, ['paginator' => ['totalCount' => $elements->getTotal(), 'totalPages' => ceil($elements->getTotal() / $elements->getPerPage()), 'currentPage' => $elements->getCurrentPage(), 'limit' => $elements->getPerPage()]]);
     return $this->respond($data);
 }