Example #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 = TopicWatch::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;
     }
 }
Example #2
0
 protected function prepareTopicList()
 {
     /*
      * If channel exists, load the topics
      */
     if ($channel = $this->getChannel()) {
         $currentPage = input('page');
         $searchString = trim(input('search'));
         $topics = TopicModel::with('last_post_member')->listFrontEnd(['page' => $currentPage, 'sort' => 'updated_at', 'channels' => $channel->id, 'search' => $searchString]);
         /*
          * Add a "url" helper attribute for linking to each topic
          */
         $topics->each(function ($topic) {
             if ($this->embedMode) {
                 $topic->url = $this->pageUrl($this->topicPage, [$this->embedTopicParam => $topic->slug]);
             } else {
                 $topic->setUrl($this->topicPage, $this->controller);
             }
             if ($topic->last_post_member) {
                 $topic->last_post_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 = TopicWatch::setFlagsOnTopics($topics, $this->member);
             ChannelWatch::flagAsWatched($channel, $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;
         }
     }
     $this->page['isGuest'] = !Auth::check();
 }
Example #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) {
         TopicWatch::flagAsWatched($this->topic, $this->member);
     }
     /*
      * 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;
     }
 }
Example #4
0
 public function afterDelete()
 {
     $this->start_member()->decrement('count_topics');
     $this->channel()->decrement('count_topics');
     $this->channel()->decrement('count_posts', $this->posts()->count());
     $this->posts()->delete();
     $this->followers()->detach();
     TopicWatch::where('topic_id', $this->id)->delete();
 }