Ejemplo n.º 1
0
 protected function prepareTopics()
 {
     if ($area = $this->getArea()) {
         $currentPage = input('page');
         $search = trim(input('search'));
         /** @var  Collection  $topics */
         $topics = TopicModel::filterAreas($area->id)->recentPosts()->search($search)->paginate(20, $currentPage);
         // Add url
         $postSearchTokens = Search::parseQuery($search, ['post'], ['post' => 'post', 'author' => 'author', 'by' => 'author']);
         $postSearch = Search::buildQuery($postSearchTokens, ['post']);
         $topics->each(function (TopicModel $topic) use($postSearch) {
             $topic->setUrl($this->topicPage, $this->controller, $postSearch ? ['search' => $postSearch] : null);
         });
         $this->page['topics'] = $this->topics = $topics;
         // Paginate
         if ($topics) {
             $query = [];
             $search and $query['search'] = $search;
             $query['page'] = '';
             $paginationUrl = Request::url() . '?' . http_build_query($query);
             if ($currentPage > ($lastPage = $topics->lastPage()) && $currentPage > 1) {
                 return Redirect::to($paginationUrl . $lastPage);
             }
             $this->page['paginationUrl'] = $paginationUrl;
         }
     }
 }
Ejemplo n.º 2
0
 public function getTopic()
 {
     if (!is_null($this->topic)) {
         return $this->topic;
     }
     /** @var  TopicModel  $topic */
     $topic = TopicModel::findOrFail((int) $this->property('id'));
     if ($topic) {
         $topic->increaseReadCount();
     }
     return $this->topic = $topic;
 }
Ejemplo n.º 3
0
 public function listTopics()
 {
     if (!is_null($this->topics)) {
         return $this->topics;
     }
     /** @var  Collection  $topics */
     switch ($this->listType) {
         case self::NEW_POSTS:
             $topics = TopicModel::recentPosts()->limit(10)->get();
             break;
         case self::NEW_TOPICS:
             $topics = TopicModel::recentTopics()->limit(10)->get();
             break;
         case self::HOT_TOPICS:
         default:
             return [];
     }
     $topics->each(function (TopicModel $topic) {
         $topic->setUrl($this->topicPage, $this->controller);
     });
     return $topics;
 }