protected function initPagenation() { $count = $this->listCount; $pagenation = array(); $skip = 0; $page = 1; if ($this->request->query->get('page')) { $skip = ($this->request->query->get('page') - 1) * $this->limit; $page = $this->request->query->get('page'); } $this->queryBuilder->limit($this->limit); $this->queryBuilder->skip($skip); if ($count > 0) { for ($i = 1; $i < $count / $this->limit + 1; $i++) { $isActive = true; if ($page == $i) { $isActive = false; } $pagenation[] = array('href' => $this->baseUrl . '?page=' . $i, 'label' => $i, 'isActive' => $isActive); } } $max = 20; $first = 0; $last = 0; if (count($pagenation) > $max) { $middle = $page; if ($middle < 3) { $from = 1; $till = $max; $last = count($pagenation); } else { if ($middle > count($pagenation) - 2) { $from = $middle - 4 + count($pagenation) - $middle; $till = count($pagenation); $first = 1; } else { $from = $middle - 2; $till = $middle + 2; if ($from > 1) { $first = 1; } if ($till < count($pagenation)) { $last = count($pagenation); } } } if ($first) { $this->pagenation[] = array('href' => $this->baseUrl . '?page=1', 'label' => 'first', 'isActive' => true); } for ($i = $from; $i < $till + 1; $i++) { $this->pagenation[] = $pagenation[$i - 1]; } if ($last) { $this->pagenation[] = array('href' => $this->baseUrl . '?page=' . $last, 'label' => 'last (' . $last . ')', 'isActive' => true); } } else { $this->pagenation = $pagenation; } $till = $skip + $this->limit; if ($till > $count) { $till = $count; } $this->listInformation = array('from' => $skip + 1, 'till' => $till, 'count' => $count, 'page' => $page, 'filters' => $this->filters); }
/** * Get the number of products according to the query * * @param Builder $queryBuilder the query builder * @param array $associatedIds the ids of the products that are associated * @param array $rawQuery the query parameters * * @return int */ protected function countProducts(Builder $queryBuilder, array $associatedIds, array $rawQuery) { $queryBuilder->count(); $queryBuilder->setQueryArray($rawQuery); $queryBuilder->limit(0); $queryBuilder->skip(0); $count = $queryBuilder->getQuery()->execute() - count($associatedIds); return max($count, 0); }
/** * Set the number of Documents to skip for the Cursor * * @param string $skip * @return QueryProxy this instance */ public function skip($skip) { $this->queryChanged = true; return parent::skip($skip); }