Skip to content

Commit 7b3e74b

Browse files
committed
upload/section add tags
1 parent c9b2237 commit 7b3e74b

File tree

4 files changed

+33
-16
lines changed

4 files changed

+33
-16
lines changed

app/Http/Resources/SearchBoxResource.php

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,29 @@ public function toArray(Request $request): array
2121
'id' => $this->id,
2222
'name' => $this->displaySectionName,
2323
'categories' => CategoryResource::collection($this->whenLoaded('categories')),
24+
'tags' => TagResource::collection($this->whenLoaded('tags')),
2425
];
25-
$subCategories = [];
26-
$lang = get_langfolder_cookie();
27-
$fields = array_keys(SearchBox::$taxonomies);
28-
if (!empty($searchBox->extra['taxonomy_labels'])) {
29-
$fields = array_column($searchBox->extra['taxonomy_labels'], 'torrent_field');
30-
}
31-
foreach ($fields as $field) {
32-
$relationName = "taxonomy_$field";
33-
if ($searchBox->relationLoaded($relationName)) {
34-
$subCategories[] = [
35-
'field' => $field,
36-
'label' => $item['display_text'][$lang] ?? (nexus_trans("searchbox.sub_category_{$field}_label") ?: ucfirst($field)),
37-
'data' => MediaResource::collection($searchBox->{$relationName}),
38-
];
26+
if ($searchBox->showsubcat) {
27+
$subCategories = [];
28+
$lang = get_langfolder_cookie();
29+
$fields = array_keys(SearchBox::$taxonomies);
30+
if (!empty($searchBox->extra['taxonomy_labels'])) {
31+
$fields = array_column($searchBox->extra['taxonomy_labels'], 'torrent_field');
32+
}
33+
foreach ($fields as $field) {
34+
$relationName = "taxonomy_$field";
35+
if ($searchBox->relationLoaded($relationName)) {
36+
$subCategories[] = [
37+
'field' => $field,
38+
'label' => $item['display_text'][$lang] ?? (nexus_trans("searchbox.sub_category_{$field}_label") ?: ucfirst($field)),
39+
'data' => MediaResource::collection($searchBox->{$relationName}),
40+
];
41+
}
42+
}
43+
if (!empty($subCategories)) {
44+
$out['sub_categories'] = $subCategories;
3945
}
4046
}
41-
$out['sub_categories'] = $this->when($this->showsubcat, $subCategories);
4247
return $out;
4348
}
4449
}

app/Models/SearchBox.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Models;
44

55
use App\Http\Middleware\Locale;
6+
use App\Repositories\TagRepository;
67
use Illuminate\Database\Eloquent\Casts\Attribute;
78
use Illuminate\Database\Query\Builder;
89
use Illuminate\Support\Str;
@@ -288,6 +289,16 @@ public function loadSubCategories(): void
288289
}
289290
}
290291

292+
public function tags(): \Illuminate\Database\Eloquent\Relations\HasMany
293+
{
294+
return $this->hasMany(Tag::class, 'mode');
295+
}
296+
297+
public function loadTags(): void
298+
{
299+
$this->setRelation("tags", TagRepository::listAll($this->id));
300+
}
301+
291302
public static function getDefaultSearchMode()
292303
{
293304
$meiliConf = get_setting("meilisearch");

app/Repositories/SearchBoxRepository.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ public function listSections()
254254
if ($searchBox->showsubcat) {
255255
$searchBox->loadSubCategories();
256256
}
257+
$searchBox->loadTags();
257258
}
258259
return $searchBoxList;
259260
}

app/Repositories/TagRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public static function getOrderByFieldIdString(): string
149149
return self::$orderByFieldIdString;
150150
}
151151

152-
public function listAll(int $searchBoxId = 0): \Illuminate\Database\Eloquent\Collection|array
152+
public static function listAll(int $searchBoxId = 0): \Illuminate\Database\Eloquent\Collection|array
153153
{
154154
if (empty(self::$allTags)) {
155155
self::$allTags = self::createBasicQuery()->get();

0 commit comments

Comments
 (0)