Ejemplo n.º 1
0
 protected function prepareTopicList()
 {
     $currentPage = input('page');
     $searchString = trim(input('search'));
     $topics = TopicModel::with('last_post_member')->listFrontEnd(['page' => $currentPage, 'perPage' => $this->topicsPerPage, 'sort' => 'updated_at', 'search' => $searchString]);
     /*
      * Add a "url" helper attribute for linking to each topic
      */
     $topics->each(function ($topic) {
         $topic->setUrl($this->topicPage, $this->controller);
         if ($topic->last_post_member) {
             $topic->last_post_member->setUrl($this->memberPage, $this->controller);
         }
         if ($topic->start_member) {
             $topic->start_member->setUrl($this->memberPage, $this->controller);
         }
     });
     /*
      * Signed in member
      */
     $this->page['member'] = $this->member = MemberModel::getFromUser();
     if ($this->member) {
         $this->member->setUrl($this->memberPage, $this->controller);
         $topics = TopicTracker::instance()->setFlagsOnTopics($topics, $this->member);
     }
     $this->page['topics'] = $this->topics = $topics;
     /*
      * Pagination
      */
     if ($topics) {
         $queryArr = [];
         if ($searchString) {
             $queryArr['search'] = $searchString;
         }
         $queryArr['page'] = '';
         $paginationUrl = Request::url() . '?' . http_build_query($queryArr);
         if ($currentPage > ($lastPage = $topics->lastPage()) && $currentPage > 1) {
             return Redirect::to($paginationUrl . $lastPage);
         }
         $this->page['paginationUrl'] = $paginationUrl;
     }
 }
Ejemplo n.º 2
0
 public function listChannels()
 {
     if ($this->channels !== null) {
         return $this->channels;
     }
     $channels = Channel::with('first_topic')->isVisible()->get();
     /*
      * Add a "url" helper attribute for linking to each channel
      */
     $channels->each(function ($channel) {
         $channel->setUrl($this->channelPage, $this->controller);
         if ($channel->first_topic) {
             $channel->first_topic->setUrl($this->topicPage, $this->controller);
         }
     });
     $this->page['member'] = $this->member = MemberModel::getFromUser();
     if ($this->member) {
         $channels = TopicTracker::instance()->setFlagsOnChannels($channels, $this->member);
     }
     $channels = $channels->toNested();
     return $this->channels = $channels;
 }
Ejemplo n.º 3
0
 protected function preparePostList()
 {
     /*
      * If topic exists, loads the posts
      */
     if ($topic = $this->getTopic()) {
         $currentPage = input('page');
         $searchString = trim(input('search'));
         $posts = PostModel::with('member.user.avatar')->listFrontEnd(['page' => $currentPage, 'perPage' => $this->property('postsPerPage'), 'sort' => 'created_at', 'topic' => $topic->id, 'search' => $searchString]);
         /*
          * Add a "url" helper attribute for linking to each member
          */
         $posts->each(function ($post) {
             if ($post->member) {
                 $post->member->setUrl($this->memberPage, $this->controller);
             }
         });
         $this->page['posts'] = $this->posts = $posts;
         /*
          * Pagination
          */
         $queryArr = [];
         if ($searchString) {
             $queryArr['search'] = $searchString;
         }
         $queryArr['page'] = '';
         $paginationUrl = Request::url() . '?' . http_build_query($queryArr);
         $lastPage = $posts->lastPage();
         if ($currentPage == 'last' || $currentPage > $lastPage && $currentPage > 1) {
             return Redirect::to($paginationUrl . $lastPage);
         }
         $this->page['paginationUrl'] = $paginationUrl;
     }
     /*
      * Set topic as watched
      */
     if ($this->topic && $this->member) {
         TopicTracker::instance()->markTopicTracked($this->topic);
     }
     /*
      * Return URL
      */
     if ($this->getChannel()) {
         if ($this->embedMode == 'single') {
             $returnUrl = null;
         } elseif ($this->embedMode) {
             $returnUrl = $this->currentPageUrl([$this->paramName('slug') => null]);
         } else {
             $returnUrl = $this->channel->url;
         }
         $this->returnUrl = $this->page['returnUrl'] = $returnUrl;
     }
 }