¨4.0.1¨

This commit is contained in:
¨NW¨
2023-12-03 14:07:47 +00:00
parent c08b36d1b6
commit f35052522d
1112 changed files with 43019 additions and 24987 deletions

View File

@@ -66,6 +66,43 @@ class MenuItem extends Model
*/
protected $translatedAttributes = ['name'];
/**
* Get the root menu item for the given menu id.
*
* @param int $menuId
*
* @return $this
*/
public static function root($menuId)
{
return static::withoutGlobalScope('not_root')
->where('menu_id', $menuId)
->firstOrFail();
}
/**
* Get the parents of the given menuId.
*
* @param int $menuId
* @param int $menuItemId
*
* @return array
*/
public static function parents($menuId, $menuItemId)
{
return static::withoutGlobalScope('active')
->where('id', '!=', $menuItemId)
->where('menu_id', $menuId)
->get()
->noCleaning()
->nest()
->setIndent('¦–– ')
->listsFlattened('name');
}
/**
* Perform any actions required after the model boots.
*
@@ -80,30 +117,36 @@ class MenuItem extends Model
static::addActiveGlobalScope();
}
public function menu()
{
return $this->belongsTo(Menu::class);
}
public function children()
{
return $this->hasMany(MenuItem::class, 'parent_id');
}
public function category()
{
return $this->belongsTo(Category::class);
}
public function page()
{
return $this->belongsTo(Page::class);
}
/**
* Set the menu item's page id.
*
* @param int $pageId
*
* @return void
*/
public function setPageIdAttribute($pageId)
@@ -111,10 +154,12 @@ class MenuItem extends Model
$this->attributes['page_id'] = $pageId;
}
/**
* Set the menu item's parent id.
*
* @param int $parentId
*
* @return void
*/
public function setParentIdAttribute($parentId)
@@ -122,16 +167,18 @@ class MenuItem extends Model
$this->attributes['parent_id'] = $parentId;
}
/**
* Get the menu item's background image.
*
* @return \Modules\Media\Entities\File
* @return File
*/
public function getBackgroundImageAttribute()
{
return $this->files->where('pivot.zone', 'background_image')->first() ?: new File;
}
/**
* Determine if the menu item has any children.
*
@@ -142,25 +189,6 @@ class MenuItem extends Model
return $this->items->isNotEmpty();
}
/**
* Determine if the menu item type is category.
*
* @return bool
*/
public function isCategoryType()
{
return $this->type === 'category';
}
/**
* Determine if the menu item type is page.
*
* @return bool
*/
public function isPageType()
{
return $this->type === 'page';
}
/**
* Determine if the menu item type is url.
@@ -172,6 +200,7 @@ class MenuItem extends Model
return $this->type === 'url';
}
/**
* Returns the public url for the menu item.
*
@@ -198,35 +227,25 @@ class MenuItem extends Model
return localized_url(locale(), $this->getAttributeFromArray('url'));
}
/**
* Get the root menu item for the given menu id.
*
* @param int $menuId
* @return $this
*/
public static function root($menuId)
{
return static::withoutGlobalScope('not_root')
->where('menu_id', $menuId)
->firstOrFail();
}
/**
* Get the parents of the given menuId.
* Determine if the menu item type is category.
*
* @param int $menuId
* @param int $menuItemId
* @return array
* @return bool
*/
public static function parents($menuId, $menuItemId)
public function isCategoryType()
{
return static::withoutGlobalScope('active')
->where('id', '!=', $menuItemId)
->where('menu_id', $menuId)
->get()
->noCleaning()
->nest()
->setIndent('¦–– ')
->listsFlattened('name');
return $this->type === 'category';
}
/**
* Determine if the menu item type is page.
*
* @return bool
*/
public function isPageType()
{
return $this->type === 'page';
}
}