Exemplo n.º 1
0
 /**
  * @param $queryString
  */
 public function prepareFulltext($queryString)
 {
     if (!$this->queryPrepared) {
         if (Strings::length($queryString) > 2) {
             $this->template->searchResults = $this->articleManager->findFulltext($queryString);
         } elseif (Strings::length($queryString) > 0) {
             $this->template->searchStatus = 'too-short';
         }
         $this->queryPrepared = TRUE;
     }
 }
 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');
     }
 }