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