mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-23 11:27:24 +08:00
upload/section add tags
This commit is contained in:
@@ -21,24 +21,29 @@ class SearchBoxResource extends JsonResource
|
||||
'id' => $this->id,
|
||||
'name' => $this->displaySectionName,
|
||||
'categories' => CategoryResource::collection($this->whenLoaded('categories')),
|
||||
'tags' => TagResource::collection($this->whenLoaded('tags')),
|
||||
];
|
||||
$subCategories = [];
|
||||
$lang = get_langfolder_cookie();
|
||||
$fields = array_keys(SearchBox::$taxonomies);
|
||||
if (!empty($searchBox->extra['taxonomy_labels'])) {
|
||||
$fields = array_column($searchBox->extra['taxonomy_labels'], 'torrent_field');
|
||||
}
|
||||
foreach ($fields as $field) {
|
||||
$relationName = "taxonomy_$field";
|
||||
if ($searchBox->relationLoaded($relationName)) {
|
||||
$subCategories[] = [
|
||||
'field' => $field,
|
||||
'label' => $item['display_text'][$lang] ?? (nexus_trans("searchbox.sub_category_{$field}_label") ?: ucfirst($field)),
|
||||
'data' => MediaResource::collection($searchBox->{$relationName}),
|
||||
];
|
||||
if ($searchBox->showsubcat) {
|
||||
$subCategories = [];
|
||||
$lang = get_langfolder_cookie();
|
||||
$fields = array_keys(SearchBox::$taxonomies);
|
||||
if (!empty($searchBox->extra['taxonomy_labels'])) {
|
||||
$fields = array_column($searchBox->extra['taxonomy_labels'], 'torrent_field');
|
||||
}
|
||||
foreach ($fields as $field) {
|
||||
$relationName = "taxonomy_$field";
|
||||
if ($searchBox->relationLoaded($relationName)) {
|
||||
$subCategories[] = [
|
||||
'field' => $field,
|
||||
'label' => $item['display_text'][$lang] ?? (nexus_trans("searchbox.sub_category_{$field}_label") ?: ucfirst($field)),
|
||||
'data' => MediaResource::collection($searchBox->{$relationName}),
|
||||
];
|
||||
}
|
||||
}
|
||||
if (!empty($subCategories)) {
|
||||
$out['sub_categories'] = $subCategories;
|
||||
}
|
||||
}
|
||||
$out['sub_categories'] = $this->when($this->showsubcat, $subCategories);
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\Http\Middleware\Locale;
|
||||
use App\Repositories\TagRepository;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Illuminate\Support\Str;
|
||||
@@ -288,6 +289,16 @@ class SearchBox extends NexusModel
|
||||
}
|
||||
}
|
||||
|
||||
public function tags(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Tag::class, 'mode');
|
||||
}
|
||||
|
||||
public function loadTags(): void
|
||||
{
|
||||
$this->setRelation("tags", TagRepository::listAll($this->id));
|
||||
}
|
||||
|
||||
public static function getDefaultSearchMode()
|
||||
{
|
||||
$meiliConf = get_setting("meilisearch");
|
||||
|
||||
@@ -254,6 +254,7 @@ class SearchBoxRepository extends BaseRepository
|
||||
if ($searchBox->showsubcat) {
|
||||
$searchBox->loadSubCategories();
|
||||
}
|
||||
$searchBox->loadTags();
|
||||
}
|
||||
return $searchBoxList;
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ class TagRepository extends BaseRepository
|
||||
return self::$orderByFieldIdString;
|
||||
}
|
||||
|
||||
public function listAll(int $searchBoxId = 0): \Illuminate\Database\Eloquent\Collection|array
|
||||
public static function listAll(int $searchBoxId = 0): \Illuminate\Database\Eloquent\Collection|array
|
||||
{
|
||||
if (empty(self::$allTags)) {
|
||||
self::$allTags = self::createBasicQuery()->get();
|
||||
|
||||
Reference in New Issue
Block a user