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 = ChannelWatch::setFlagsOnChannels($channels, $this->member); } $channels = $channels->toNested(); return $this->channels = $channels; }
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(); }