section basic

This commit is contained in:
xiaomlove
2022-10-27 20:21:54 +08:00
parent 0053d14183
commit ce5d99c16a
92 changed files with 3188 additions and 1367 deletions
+5
View File
@@ -13,4 +13,9 @@ class AudioCodec extends NexusModel
{
return nexus_trans('searchbox.sub_category_audio_codec_label');
}
public function search_box()
{
return $this->belongsTo(SearchBox::class, 'mode', 'id');
}
}
+5
View File
@@ -18,4 +18,9 @@ class Category extends NexusModel
{
return $this->belongsTo(Icon::class, 'icon_id');
}
public function search_box()
{
return $this->belongsTo(SearchBox::class, 'mode', 'id');
}
}
+5
View File
@@ -13,4 +13,9 @@ class Codec extends NexusModel
{
return nexus_trans('searchbox.sub_category_codec_label');
}
public function search_box()
{
return $this->belongsTo(SearchBox::class, 'mode', 'id');
}
}
+5
View File
@@ -13,4 +13,9 @@ class Media extends NexusModel
{
return nexus_trans('searchbox.sub_category_media_label');
}
public function search_box()
{
return $this->belongsTo(SearchBox::class, 'mode', 'id');
}
}
+5
View File
@@ -13,4 +13,9 @@ class Processing extends NexusModel
{
return nexus_trans('searchbox.sub_category_processing_label');
}
public function search_box()
{
return $this->belongsTo(SearchBox::class, 'mode', 'id');
}
}
+31 -5
View File
@@ -3,10 +3,14 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Str;
use Nexus\Database\NexusDB;
class SearchBox extends NexusModel
{
private static array $instances = [];
protected $table = 'searchbox';
protected $fillable = [
@@ -21,6 +25,7 @@ class SearchBox extends NexusModel
'extra' => 'array',
'is_default' => 'boolean',
'showsubcat' => 'boolean',
'section_name' => 'json',
];
const EXTRA_TAXONOMY_LABELS = 'taxonomy_labels';
@@ -40,9 +45,9 @@ class SearchBox extends NexusModel
'medium' => 'media',
'codec' => 'codecs',
'audiocodec' => 'audiocodecs',
'team' => 'teams',
'standard' => 'standards',
'processing' => 'processings'
'processing' => 'processings',
'team' => 'teams',
];
public static array $extras = [
@@ -66,21 +71,23 @@ class SearchBox extends NexusModel
foreach ($data['extra'][self::EXTRA_TAXONOMY_LABELS] ?? [] as $item) {
if ($field == $item['torrent_field']) {
$data["show{$field}"] = 1;
$data["extra->" . self::EXTRA_TAXONOMY_LABELS][] = $item;
// $data["extra->" . self::EXTRA_TAXONOMY_LABELS][] = $item;
}
}
}
$data["extra->" . self::EXTRA_TAXONOMY_LABELS] = $data['extra'][self::EXTRA_TAXONOMY_LABELS];
return $data;
}
public function getTaxonomyLabel($torrentField)
{
$lang = get_langfolder_cookie();
foreach ($this->extra[self::EXTRA_TAXONOMY_LABELS] ?? [] as $item) {
if ($item['torrent_field'] == $torrentField) {
return $item['display_text'];
return $item['display_text'][$lang] ?? 'Unknown';
}
}
return nexus_trans('label.torrent.' . $torrentField) ?: ucfirst($torrentField);
return nexus_trans("searchbox.sub_category_{$torrentField}_label") ?: ucfirst($torrentField);
}
protected function customFields(): Attribute
@@ -111,6 +118,25 @@ class SearchBox extends NexusModel
return $result;
}
public static function get(int $id)
{
if (!isset(self::$instances[$id])) {
self::$instances[$id] = self::query()->find($id);
}
return self::$instances[$id];
}
public static function listTaxonomyItems($searchBox, $torrentField): \Illuminate\Support\Collection
{
if (!$searchBox instanceof self) {
$searchBox = self::get(intval($searchBox));
}
$table = self::$taxonomies[$torrentField];
return NexusDB::table($table)->where(function (Builder $query) use ($searchBox) {
return $query->where('mode', $searchBox->id)->orWhere('mode', 0);
})->get();
}
public function getCustomFieldsAttribute($value): array
{
if (!is_array($value)) {
+32
View File
@@ -0,0 +1,32 @@
<?php
namespace App\Models;
class SecondIcon extends NexusModel
{
protected $table = 'secondicons';
protected $fillable = [
'name', 'class_name', 'image', 'mode',
'source', 'medium', 'codec', 'audiocodec', 'standard', 'processing', 'team'
];
public static function formatFormData(array $data): array
{
foreach (SearchBox::$taxonomies as $torrentField => $table) {
$mode = $data['mode'];
if (empty($data[$torrentField][$mode])) {
unset($data[$torrentField]);
} else {
$data[$torrentField] = $data[$torrentField][$mode];
}
}
return $data;
}
public function search_box()
{
return $this->belongsTo(SearchBox::class, 'mode', 'id');
}
}
+5
View File
@@ -11,4 +11,9 @@ class Source extends NexusModel
{
return nexus_trans('searchbox.sub_category_source_label');
}
public function search_box()
{
return $this->belongsTo(SearchBox::class, 'mode', 'id');
}
}
+5
View File
@@ -11,4 +11,9 @@ class Standard extends NexusModel
{
return nexus_trans('searchbox.sub_category_standard_label');
}
public function search_box()
{
return $this->belongsTo(SearchBox::class, 'mode', 'id');
}
}
+5
View File
@@ -11,4 +11,9 @@ class Team extends NexusModel
{
return nexus_trans('searchbox.sub_category_team_label');
}
public function search_box()
{
return $this->belongsTo(SearchBox::class, 'mode', 'id');
}
}
+1 -8
View File
@@ -2,23 +2,16 @@
namespace App\Models;
<<<<<<< HEAD
=======
use Nexus\Database\NexusDB;
>>>>>>> php8
class TorrentCustomFieldValue extends NexusModel
{
protected $table = 'torrents_custom_field_values';
<<<<<<< HEAD
protected $fillable = [
'torrent_id', 'custom_field_id', 'custom_field_value',
];
=======
public $timestamps = true;
protected $fillable = ['torrent_id', 'custom_field_id', 'custom_field_value', ];
>>>>>>> php8
}