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
$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);
}
}
+23 -14
View File
@@ -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) {