API: upload sections list

This commit is contained in:
xiaomlove
2025-02-15 03:15:45 +08:00
parent 0d7cbcde9f
commit c9b2237efd
16 changed files with 262 additions and 10 deletions

View File

@@ -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");

View File

@@ -100,4 +100,9 @@ class Setting extends NexusModel
return $value;
}
public static function getDefaultLang()
{
return self::get("main.defaultlang");
}
}