mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 20:40:49 +08:00
API: upload sections list
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Http\Middleware\Locale;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Illuminate\Support\Str;
|
||||
@@ -182,6 +183,25 @@ class SearchBox extends NexusModel
|
||||
}
|
||||
}
|
||||
|
||||
public function getDisplaySectionNameAttribute()
|
||||
{
|
||||
$locale = Locale::getDefault();
|
||||
if (!empty($this->section_name[$locale])) {
|
||||
return $this->section_name[$locale];
|
||||
}
|
||||
$defaultLang = get_setting("main.defaultlang");
|
||||
if (!empty($this->section_name[$defaultLang])) {
|
||||
return $this->section_name[$defaultLang];
|
||||
}
|
||||
if ($this->isSectionBrowse()) {
|
||||
return nexus_trans("searchbox.sections.browse");
|
||||
}
|
||||
if ($this->isSectionSpecial()) {
|
||||
return nexus_trans("searchbox.sections.special");
|
||||
}
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public static function listSearchModes(): array
|
||||
{
|
||||
$result = [];
|
||||
@@ -206,6 +226,16 @@ class SearchBox extends NexusModel
|
||||
return Setting::get('main.specialcat');
|
||||
}
|
||||
|
||||
public function isSectionBrowse(): bool
|
||||
{
|
||||
return $this->id == self::getBrowseMode();
|
||||
}
|
||||
|
||||
public function isSectionSpecial(): bool
|
||||
{
|
||||
return $this->id == self::getSpecialMode();
|
||||
}
|
||||
|
||||
|
||||
public function categories(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
@@ -247,6 +277,17 @@ class SearchBox extends NexusModel
|
||||
return $this->hasMany(Processing::class, 'mode');
|
||||
}
|
||||
|
||||
public function loadSubCategories(): void
|
||||
{
|
||||
foreach (self::$taxonomies as $name => $info) {
|
||||
$relationName = "taxonomy_" . $name;
|
||||
$show = "show" . $name;
|
||||
if ($this->{$show}) {
|
||||
$this->setRelation($relationName, $this->{$relationName}()->orWhere('mode', 0)->get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function getDefaultSearchMode()
|
||||
{
|
||||
$meiliConf = get_setting("meilisearch");
|
||||
|
||||
@@ -100,4 +100,9 @@ class Setting extends NexusModel
|
||||
return $value;
|
||||
}
|
||||
|
||||
public static function getDefaultLang()
|
||||
{
|
||||
return self::get("main.defaultlang");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user