protected function prepareResults() { $currentPage = input('page'); $search = trim(input('search')); /** @var Collection $topics */ $topics = TopicModel::filterAreas(AreaModel::getAccessibleIds())->with('area')->recentPosts()->search($search, false)->paginate(20, $currentPage); // Add url $postSearchTokens = SearchHelper::parseQuery($search, ['post'], ['post' => 'post', 'author' => 'author', 'by' => 'author']); $postSearch = SearchHelper::buildQuery($postSearchTokens, ['post']); $topics->each(function (TopicModel $topic) use($postSearch) { $topic->setUrl($this->topicPage, $this->controller, $postSearch ? ['search' => $postSearch] : null); $topic->area->setUrl($this->areaPage, $this->controller); }); $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; } }
public function getArea() { if (!is_null($this->area)) { return $this->area; } $this->area = AreaModel::findOrFail((int) $this->property('id')); if ($this->area->is_private && !Auth::check()) { throw new ApplicationException('Authenticated users only'); } return $this->area; }
public function listAreas() { if (!is_null($this->areas)) { return $this->areas; } $areas = AreaModel::isVisible()->get(); // Add URLs $areas->each(function (AreaModel $area) { $area->setUrl($this->areaPage, $this->controller); }); $areas = $areas->toNested(); return $this->areas = $areas; }
public function index_onDelete() { $areaIds = post('checked'); if ($areaIds && is_array($areaIds) && count($areaIds)) { foreach ($areaIds as $areaId) { if (!($area = AreaModel::find($areaId))) { continue; } //$area->delete(); } Flash::success('Areas deleted.'); } return $this->listRefresh(); }
public function getArea() { if (!is_null($this->area)) { return $this->area; } if ($topic = $this->getTopic()) { $area = $topic->area; } else { if ($areaId = input('area')) { $area = AreaModel::findOrFail($areaId); } else { $area = null; } } if ($area) { if ($area->is_private && !Auth::check()) { throw new ApplicationException('Authenticated users only'); } $area->setUrl($this->areaPage, $this->controller); } return $this->area = $area; }