FIX: fix selecting pages - exclude pages from disabled modules
This commit is contained in:
+23
-14
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user