FIX: fix selecting pages - exclude pages from disabled modules

This commit is contained in:
Michal Kváček
2016-10-02 21:58:56 +02:00
parent e42d06904e
commit 97fae9bf9d
2 changed files with 26 additions and 15 deletions
+3 -1
View File
@@ -35,7 +35,9 @@ class PageRenderer
// get handler // get handler
$handler = new $page->module_handler; $handler = new $page->module_handler;
$page->content = Shortcode::compile($page->content);
// render page // render page
return Shortcode::compile($handler->render($page, $parameters)); return $handler->render($page, $parameters);
} }
} }
+23 -14
View File
@@ -38,7 +38,7 @@ class Content extends Model
'status' 'status'
]; ];
protected $guarded = []; protected $guarded = [];
protected $subpages = []; protected $foundSubpages = [];
protected $subpagesInit = false; protected $subpagesInit = false;
const STATUS_DRAFT = 'draft'; const STATUS_DRAFT = 'draft';
const STATUS_PROTECTED = 'protected'; const STATUS_PROTECTED = 'protected';
@@ -60,7 +60,11 @@ class Content extends Model
*/ */
public function getPageQuery() 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() public function getHomepage()
{ {
return $this->getPageQuery() return $this->getPageQuery()
->where('language', LaravelLocalization::getCurrentLocale())
->where('is_homepage', 1) ->where('is_homepage', 1)
->first(); ->first();
} }
@@ -86,32 +89,39 @@ class Content extends Model
{ {
return $this->getPageQuery() return $this->getPageQuery()
->where('url', $url) ->where('url', $url)
->where('language', LaravelLocalization::getCurrentLocale())
->first(); ->first();
} }
/** /**
* Get list of all subpages * 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) { if (!$this->subpagesInit) {
$this->subpages = $this->getPageQuery() $subpages = $this->getPageQuery()
->where('parent_id', $this->id) ->where('contents.parent_id', $this->id);
->where('language', LaravelLocalization::getCurrentLocale())
->get(); if ($orderBy) {
$subpages->orderBy($orderBy, $orderDirection ? $orderDirection : 'ASC');
}
$subpages = $subpages->get();
// convert JSON settings into stdClass // convert JSON settings into stdClass
foreach ($this->subpages as $subpage) { foreach ($subpages as $i => $subpage) {
$subpage->module_settings = json_decode($subpage->module_settings); $subpages[$i]->module_settings = json_decode($subpage->module_settings);
} }
$this->subpagesInit = true; $this->subpagesInit = true;
$this->foundSubpages = $subpages;
} }
return $this->subpages; return $this->foundSubpages;
} }
/** /**
@@ -162,7 +172,6 @@ class Content extends Model
public function rootPages() public function rootPages()
{ {
$rootPages = $this->getPageQuery() $rootPages = $this->getPageQuery()
->where('language', LaravelLocalization::getCurrentLocale())
->where('parent_id', null); ->where('parent_id', null);
if ($this->id) { if ($this->id) {