Пример #1
0
 protected function createPaginator()
 {
     $paginator = new Nette\Utils\Paginator();
     $paginator->setItemsPerPage($this->itemsPerPage);
     $paginator->setPage((int) $this->page);
     return $paginator;
 }
Пример #2
0
 /**
  * @param Paginator
  * @param bool fills paginator "itemCount", if true, solr query will be executed immediately
  * @throws InvalidStateException
  */
 public function applyPaginator(Paginator $paginator, $fillItemCount = TRUE)
 {
     $this->applyPaging($paginator->getOffset(), $paginator->getLength());
     if ($fillItemCount) {
         $this->execute();
         $paginator->setItemCount($this->getTotalCount());
     }
 }
Пример #3
0
 public function setPagination($rowsPerPage = 20, $rowsCount = null)
 {
     $paginator = new Paginator();
     $paginator->setItemsPerPage($rowsPerPage);
     if ($rowsCount) {
         $paginator->setItemCount($rowsCount);
     }
     $this->renderer->setPaginator($paginator);
 }
Пример #4
0
 public function handlePage($stranka = '')
 {
     if (!$stranka || !is_numeric($stranka)) {
         throw new \Nette\Application\BadRequestException();
     }
     $this->paginator->setPage($stranka);
     $this->stranka = $stranka;
     $this->template->articles = $this->articleManager->getNewArticleList($this->paginator);
 }
Пример #5
0
 public function renderDefault($rPage = 1)
 {
     $rPaginator = new Paginator();
     $rPaginator->setItemCount(count($this->reservationManager->getReservations()));
     $rPaginator->setItemsPerPage(15);
     $rPaginator->setPage($rPage);
     $this->template->rPaginator = $rPaginator;
     $this->template->rButtons = $this->reservationManager->getPaginatorsButtons($rPaginator);
     $this->template->reservations = $this->reservationManager->getReservationsForPaginator($rPaginator->getLength(), $rPaginator->getOffset());
 }
Пример #6
0
 private function setPage($page = 1, $new = false)
 {
     if ($new) {
         $this->paginator->itemCount++;
     }
     $this->paginator->setPage($page);
     $this->page = $page;
     $this->template->lastPage = $this->lastPage;
     $this->template->comments = $this->commentsManager->getComments($this->paginator);
 }
Пример #7
0
 /**
  * @param IQueryable $repository
  * @return array
  */
 public function fetch(IQueryable $repository)
 {
     $query = $this->getQuery($repository);
     if ($this->paginator) {
         $query = Paginate::getPaginateQuery($query, $this->paginator->getOffset(), $this->paginator->getLength());
         // Step 2 and 3
     } else {
         $query = $query->setMaxResults(NULL)->setFirstResult(NULL);
     }
     $this->lastQuery = $query;
     return $query->getResult();
 }
Пример #8
0
 public function handlePage($page = '', $for = 'pub')
 {
     if (!$page) {
         throw new \Nette\Application\BadRequestException();
     }
     if ($for == 'pub') {
         $this->paginator->setPage($page);
     } else {
         $this->paginatorDel->setPage($page);
     }
     $this->redrawAjax('pubNews');
     $this->redrawAjax('delNews');
 }
 public function renderDefault($page = 1)
 {
     $empty = FALSE;
     $this->page = $page;
     $paginator = new Paginator();
     $paginator->setItemsPerPage(10);
     $paginator->setPage($this->page);
     if (!$this->user->isAllowed('Article', 'editAll')) {
         $count = $this->articleManager->getCount($this->user->id);
     } else {
         $count = $this->articleManager->getCount();
     }
     $paginator->setItemCount($count);
     if (Strings::length($this->q) >= 3) {
         $this->fulltextQuery = $this->q;
     }
     if ($this->fulltextQuery) {
         if (!$this->user->isAllowed('Article', 'editAll')) {
             $fulltextArticles = $this->articleManager->findFulltext($this->fulltextQuery)->fetchAll();
         } else {
             $fulltextArticles = $this->articleManager->findFulltext($this->fulltextQuery)->where('article.user_id', $this->user->id)->fetchAll();
         }
         if (!empty($fulltextArticles)) {
             $paginator->setItemCount(count($fulltextArticles));
             $fulltextPages = array_chunk($fulltextArticles, $paginator->itemsPerPage, true);
             $this->template->listOfArticles = $fulltextPages[$paginator->page - 1];
         } else {
             $paginator->setItemCount(0);
             $this->template->listOfArticles = array();
         }
     } else {
         if (!$this->user->isAllowed('Article', 'editAll')) {
             $this->template->listOfArticles = $this->articleManager->findAll()->where('article.user_id', $this->user->id)->limit($paginator->getLength(), $paginator->getOffset())->fetchAll();
         } else {
             $this->template->listOfArticles = $this->articleManager->findAll()->limit($paginator->getLength(), $paginator->getOffset())->fetchAll();
         }
         if (empty($this->template->listOfArticles)) {
             $empty = TRUE;
         }
     }
     $this->template->fulltextQuery = $this->q;
     $this->template->page = $this->page;
     $this->template->empty = $empty;
     if ($count > $paginator->itemsPerPage && !$paginator->last) {
         $this->template->showMoreButton = TRUE;
     }
     if ($this->ajax) {
         $this->redrawControl('datalistResult');
     }
 }
Пример #10
0
 public function getData()
 {
     $this->paginator->setItemsPerPage($this->itemsPerPage);
     $this->paginator->setItemCount($this->dataset->getCount());
     $this->paginator->setPage($this->page);
     $this->page = $this->paginator->getPage();
     $this->dataset->setLimit($this->paginator->length, $this->paginator->offset);
     // TODO: IDataSource::setOrderBy() is optional
     if (empty($this->orderColumn) && !empty($this->defaultOrderColumn)) {
         $this->dataset->setOrderBy($this->defaultOrderColumn, $this->defaultOrderDir === self::ASC);
     } elseif (!empty($this->orderColumn)) {
         $this->dataset->setOrderBy($this->orderColumn, $this->orderDir === self::ASC);
     }
     return $this->dataset->getData();
 }
Пример #11
0
 public function renderDefault($page)
 {
     // initial dao object
     $dao = $this->em->getRepository(Search::getClassName());
     $searchQuery = new SearchQuery();
     // initial paginator
     $paginator = new Nette\Utils\Paginator();
     $paginator->setPage($page);
     $searchs = $dao->fetch($searchQuery)->applySorting(array('Search.date' => 'DESC'))->applyPaginator($paginator, self::ROWSONPAGE);
     $numberRows = $searchs->getTotalCount();
     $paginator->setItemCount($numberRows);
     // push data to template
     $this->template->search = $searchs;
     $this->template->paginator = $paginator;
     $this->template->page = $page;
 }
Пример #12
0
 public function handleSetPage($page)
 {
     $this->paginator->setPage($page);
     if ($this->presenter->isAjax()) {
         $this->invalidateControl("datagrid");
     }
 }
Пример #13
0
 /**
  * Returns the total number of pages.
  *
  * @return int|NULL
  */
 public function getPageCount()
 {
     if (!$this->itemsOnFirstPage) {
         return parent::getPageCount();
     }
     return $this->itemCount === NULL ? NULL : (int) ceil(1 + ($this->itemCount - $this->itemsOnFirstPage) / $this->itemsPerPage);
 }
Пример #14
0
 /**
  * @return int
  */
 public function getPage()
 {
     if ($this->page === NULL) {
         $this->page = parent::getPage();
     }
     return $this->page;
 }
Пример #15
0
 private function startPaginator(HttpService $httpService, array $rows)
 {
     $this->paginator->setPage($httpService->getPaginatorPage());
     if (is_null($this->paginator->getItemCount())) {
         $this->paginator->setItemCount(count($rows));
     }
     return array_slice($rows, $this->paginator->offset, $this->paginator->itemsPerPage);
 }
Пример #16
0
 /**
  * @return int
  */
 public function getOffset()
 {
     if ($this->limit === NULL) {
         return NULL;
     }
     $this->getSteps();
     return $this->paginator->getOffset();
 }
Пример #17
0
 /**
  * Výpis uživatelů
  * @param int
  */
 public function renderDefault($page = 1)
 {
     $paginator = new Paginator();
     $pocet = $this->uzivateleModel->pocet();
     $paginator->setPage($page)->setItemsPerPage(self::POLOZEK_NA_STRANKU)->setItemCount($pocet);
     if ($paginator->getPage() != $page) {
         // je li page nastavena na neexistující, je přesměrována
         $this->redirect('this', array('page' => $paginator->getPage()));
     }
     $data = FALSE;
     if ($pocet) {
         $data = $this->uzivateleModel->vypis($paginator);
     }
     $this->template->data = $data;
     $this->template->pocetDat = $pocet;
     $this->template->paginator = $paginator;
     $this->template->opravneni = $this->opravneni;
 }
Пример #18
0
 public function renderArticles()
 {
     /** @var Doctrine\Common\Collections\ArrayCollection */
     $articles = $this->objectWithArticles->getArticles();
     $total = $articles->count();
     $this->template->news = $articles->slice($this->paginator->getOffset(), $this->paginator->getLength());
     $this->paginator->setItemCount($total);
     $this->template->paginator = $this->paginator;
 }
Пример #19
0
 /**
  * Render grid
  */
 public function render()
 {
     $this->paginator->setPage($this->page);
     $this->model->setLimit($this->paginator->getLength());
     $this->model->setOffset($this->paginator->getOffset());
     if ($this->sortColumn && $this["columns"]->getComponent($this->sortColumn)->isSortable()) {
         $this->model->setSorting($this->sortColumn, $this->sortType);
     }
     $this->template->render();
 }
Пример #20
0
 /**
  * Render grid
  */
 public function render()
 {
     $this->model->setLimit($this->paginator->getLength());
     $this->model->setOffset($this->paginator->getOffset());
     if ($this->sortColumn && $this["columns"]->getComponent($this->sortColumn)->isSortable()) {
         $this->model->setSorting($this->sortColumn, $this->sortType);
     }
     $this['visualPaginator']->setClass(array('paginator', $this->ajaxClass));
     $this->template->render();
 }
Пример #21
0
 /**
  * Nastavuje stranku paginatoru pro zobrazeni komentaru
  * @param int $page 
  */
 public function handleSetCommentPage($page = NULL)
 {
     if ($page === NULL) {
         $page = $this->paginator->getPage() + 1;
     }
     if ($this->paginator->getPage() != $page) {
         $this->paginator->setPage($page);
         $this->redrawControl('comments');
         $this->redrawControl('pagin');
     }
 }
 public function renderDefault($page = 1)
 {
     $paginator = new Paginator();
     $paginator->setItemsPerPage(10);
     $paginator->setPage($page);
     $count = $this->shortcutsManager->getCount();
     $paginator->setItemCount($count);
     $empty = FALSE;
     if ($this->fulltextQuery != '') {
         $this->template->listOfShortcuts = $this->shortcutsManager->findFulltext($this->fulltextQuery);
     } else {
         $this->template->listOfShortcuts = $this->shortcutsManager->findAll($paginator->getOffset(), $paginator->getLength());
         if (empty($this->template->listOfShortcuts)) {
             $empty = TRUE;
         }
     }
     $this->template->fulltextQuery = $this->fulltextQuery;
     $this->template->empty = $empty;
     $this->template->page = $page;
     if ($count > 10) {
         $this->template->showMoreButton = TRUE;
     }
     if ($this->ajax) {
         $this->redrawControl('datalistResult');
     }
 }
 /**
  * @return Form
  */
 public function create($kat = null, $page = null, $id_user = null)
 {
     // nastaveni paginatoru
     $paginator = new Nette\Utils\Paginator();
     $paginator->setItemsPerPage(6);
     // def počtu položek na stránce
     $paginator->setPage($page);
     // def stranky
     // selekce upozorneni
     $alerts = $this->database->findAll('alert')->where('id_user', $id_user);
     if ($kat == 'read') {
         // prectene
         $alerts = $alerts->where('visited', 1);
     } else {
         // neprectene
         $alerts = $alerts->where('visited', 0);
     }
     $alerts = $alerts->order('added DESC')->order('id DESC');
     // prideleni produktu na stranku
     $paginator->setItemCount($alerts->count('*'));
     $this->alerts = $alerts->limit($paginator->getLength(), $paginator->getOffset());
     $this->kat = $kat;
     // form
     $form = new Form();
     $form->getElementPrototype()->class('ajax form');
     foreach ($this->alerts as $alert) {
         $form->addCheckbox($alert->id);
     }
     $form->addSubmit('btndel', 'Smazat upozornění')->setAttribute('class', 'btn btn-primary');
     $form->addSubmit('btnvis', 'Označit jako přečtené')->setAttribute('class', 'btn btn-default');
     $form->onSuccess[] = array($this, 'formSucceeded');
     $form->onError[] = array($this, 'formNotSucceeded');
     return $form;
 }
Пример #24
0
 public function renderDefault($page = 1, $filter = '%')
 {
     $paginator = new Nette\Utils\Paginator();
     $paginator->setItemsPerPage(5);
     $paginator->setPage($page);
     $results = count($this->database->table('users')->where('username LIKE ? OR email LIKE ?', $filter, $filter));
     $paginator->setItemCount($results);
     $this->template->totalPages = $paginator->getPageCount();
     $this->template->page = $paginator->page;
     $this->template->filter = $filter;
     $this->template->users = $this->database->table('users')->order('username')->where('username LIKE ? OR email LIKE ?', $filter, $filter)->limit($paginator->getLength(), $paginator->getOffset());
 }
Пример #25
0
 public function renderDefault($page = 1, $filter = '%')
 {
     $paginator = new Nette\Utils\Paginator();
     $paginator->setItemsPerPage(3);
     // the number of records on page
     $paginator->setPage($page);
     //current page, default 1
     $users = $this->database->table('users')->where('login LIKE ? OR email LIKE ?', $filter, $filter)->limit($paginator->getLength(), $paginator->getOffset());
     $this->template->users = $users;
     $this->template->filter = $filter;
     $this->template->totalPosts = $this->database->table('users')->count();
     $paginator->setItemCount($this->template->totalPosts);
     $this->template->totalPages = $paginator->getPageCount();
     $this->template->page = $paginator->page;
     $this->template->pageCount = $paginator->getItemsPerPage();
 }
Пример #26
0
 /**
  * @param \Nette\ComponentModel\IComponent $component
  */
 protected function attached($component)
 {
     parent::attached($component);
     if (!$component instanceof Presenter) {
         return;
     }
     $this->configure($component);
     // sorting validation
     $directions = [self::SORT_ASC, self::SORT_DESC];
     foreach ($this->sortBy as $column => $direction) {
         if (!isset($this->columns[$column]) || !$this->columns[$column]->isSortable() || !in_array($direction, $directions)) {
             unset($this->sortBy[$column]);
             continue;
         }
     }
     $this->paginator->setPage($this->page)->setItemsPerPage($this->perPage);
 }
Пример #27
0
 public function renderDefault()
 {
     $cols = array("pages_types_id" => 6, "pages_id" => $this->getParameter("page_id"));
     $this->template->galleryId = $this->getParameter("id");
     $gallery = $this->database->table("pages")->where($cols);
     $paginator = new \Nette\Utils\Paginator();
     $paginator->setItemCount($gallery->count());
     $paginator->setItemsPerPage(20);
     $paginator->setPage($this->getParameter("page"));
     $this->template->paginator = $paginator;
     $this->template->galleries = $gallery->order("title")->limit($paginator->getLength(), $paginator->getOffset());
     $this->template->args = $this->getParameters(TRUE);
 }
Пример #28
0
 public function renderDefault()
 {
     $this->template->categoryId = $this->template->settings['categories:id:contact'];
     $contactsDb = $this->database->table("contacts")->order("name");
     $paginator = new \Nette\Utils\Paginator();
     $paginator->setItemCount($contactsDb->count("*"));
     $paginator->setItemsPerPage(20);
     $paginator->setPage($this->getParameter("page"));
     $this->template->args = $this->getParameters();
     $this->template->paginator = $paginator;
     $this->template->contacts = $contactsDb->limit($paginator->getLength(), $paginator->getOffset());
     $this->template->menu = $this->database->table("categories")->where('parent_id', $this->template->settings['categories:id:contact']);
 }
Пример #29
0
 /**
  * Render grid
  */
 public function render()
 {
     $this->getModel()->setLimit($this->paginator->getLength());
     $this->getModel()->setOffset($this->paginator->getOffset());
     $sorting = $this->getSorting();
     if ($sorting) {
         $this->getModel()->setSorting($sorting);
     }
     if (!is_null($vp = $this->getComponent('visualPaginator', FALSE))) {
         $vp->setClass(array('paginator', $this->ajaxClass));
         $this->template->paginator = $vp;
     } else {
         $this->template->paginator = $this->getPaginator();
     }
     //for default check
     $this->template->defaultSorting = (array) $this->defaultSorting;
     $this->template->emptyResultText = $this->emptyResultText;
     $this->template->render();
 }
Пример #30
0
 public function renderDetail($id, $page = 1)
 {
     $allProducts = $this->productService->getProductsInCategory(self::BASE_LANG, $id);
     $paginator = new Paginator();
     $paginator->setItemsPerPage(self::ITEMS_PER_PAGE);
     $paginator->setItemCount(count($allProducts));
     $paginator->setPage((int) $page);
     $products = array_slice($allProducts, self::ITEMS_PER_PAGE * $paginator->getPage() - 1, $paginator->getItemsPerPage());
     if (!$products && 0 === count($allProducts)) {
         throw new BadRequestException();
     }
     $this->template->paginator = $paginator;
     $this->template->products = $products;
 }