From 97fae9bf9d6d096857f649cfd627ce06a61512cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kv=C3=A1=C4=8Dek?= Date: Sun, 2 Oct 2016 21:58:56 +0200 Subject: [PATCH] FIX: fix selecting pages - exclude pages from disabled modules --- app/Helpers/PageRenderer.php | 4 +++- app/Models/Content.php | 37 ++++++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/app/Helpers/PageRenderer.php b/app/Helpers/PageRenderer.php index e108ddb6..f0acb176 100644 --- a/app/Helpers/PageRenderer.php +++ b/app/Helpers/PageRenderer.php @@ -35,7 +35,9 @@ class PageRenderer // get handler $handler = new $page->module_handler; + $page->content = Shortcode::compile($page->content); + // render page - return Shortcode::compile($handler->render($page, $parameters)); + return $handler->render($page, $parameters); } } diff --git a/app/Models/Content.php b/app/Models/Content.php index 3c85be0e..6dee27a4 100644 --- a/app/Models/Content.php +++ b/app/Models/Content.php @@ -38,7 +38,7 @@ class Content extends Model 'status' ]; protected $guarded = []; - protected $subpages = []; + protected $foundSubpages = []; protected $subpagesInit = false; const STATUS_DRAFT = 'draft'; const STATUS_PROTECTED = 'protected'; @@ -60,7 +60,11 @@ class Content extends Model */ public function getPageQuery() { - return Content::where('status', '!=', Content::STATUS_DRAFT); + return Content::where('status', '!=', Content::STATUS_DRAFT) + ->select('contents.*') + ->join('modules', 'modules.handler', '=', 'contents.module_handler') + ->where('language', LaravelLocalization::getCurrentLocale()) + ->where('modules.enabled', true); } /** @@ -70,7 +74,6 @@ class Content extends Model public function getHomepage() { return $this->getPageQuery() - ->where('language', LaravelLocalization::getCurrentLocale()) ->where('is_homepage', 1) ->first(); } @@ -86,32 +89,39 @@ class Content extends Model { return $this->getPageQuery() ->where('url', $url) - ->where('language', LaravelLocalization::getCurrentLocale()) ->first(); } /** * Get list of all subpages * - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @param bool $orderBy + * @param bool $orderDirection + * + * @return array */ - public function subpages() + public function subpages($orderBy = false, $orderDirection = false) { if (!$this->subpagesInit) { - $this->subpages = $this->getPageQuery() - ->where('parent_id', $this->id) - ->where('language', LaravelLocalization::getCurrentLocale()) - ->get(); + $subpages = $this->getPageQuery() + ->where('contents.parent_id', $this->id); + + if ($orderBy) { + $subpages->orderBy($orderBy, $orderDirection ? $orderDirection : 'ASC'); + } + + $subpages = $subpages->get(); // convert JSON settings into stdClass - foreach ($this->subpages as $subpage) { - $subpage->module_settings = json_decode($subpage->module_settings); + foreach ($subpages as $i => $subpage) { + $subpages[$i]->module_settings = json_decode($subpage->module_settings); } $this->subpagesInit = true; + $this->foundSubpages = $subpages; } - return $this->subpages; + return $this->foundSubpages; } /** @@ -162,7 +172,6 @@ class Content extends Model public function rootPages() { $rootPages = $this->getPageQuery() - ->where('language', LaravelLocalization::getCurrentLocale()) ->where('parent_id', null); if ($this->id) {