2021-05-20 17:14:38 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
2022-09-06 20:45:29 +08:00
|
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
|
|
|
|
2021-05-20 23:30:34 +08:00
|
|
|
class SearchBox extends NexusModel
|
2021-05-20 17:14:38 +08:00
|
|
|
{
|
|
|
|
|
protected $table = 'searchbox';
|
|
|
|
|
|
|
|
|
|
protected $fillable = [
|
2022-09-06 20:45:29 +08:00
|
|
|
'name', 'catsperrow', 'catpadding', 'showsubcat', 'section_name', 'is_default',
|
2021-05-20 17:14:38 +08:00
|
|
|
'showsource', 'showmedium', 'showcodec', 'showstandard', 'showprocessing', 'showteam', 'showaudiocodec',
|
2022-09-06 20:45:29 +08:00
|
|
|
'custom_fields', 'custom_fields_display_name', 'custom_fields_display',
|
|
|
|
|
'extra->' . self::EXTRA_TAXONOMY_LABELS,
|
|
|
|
|
'extra->' . self::EXTRA_DISPLAY_COVER_ON_TORRENT_LIST
|
2021-05-20 17:14:38 +08:00
|
|
|
];
|
|
|
|
|
|
2022-09-02 19:49:41 +08:00
|
|
|
protected $casts = [
|
2022-09-06 20:45:29 +08:00
|
|
|
'extra' => 'array',
|
|
|
|
|
'is_default' => 'boolean',
|
|
|
|
|
'showsubcat' => 'boolean',
|
2022-09-02 19:49:41 +08:00
|
|
|
];
|
|
|
|
|
|
2022-09-06 20:45:29 +08:00
|
|
|
const EXTRA_TAXONOMY_LABELS = 'taxonomy_labels';
|
|
|
|
|
|
2022-09-02 19:49:41 +08:00
|
|
|
const EXTRA_DISPLAY_COVER_ON_TORRENT_LIST = 'display_cover_on_torrent_list';
|
2022-09-06 21:54:13 +08:00
|
|
|
const EXTRA_DISPLAY_SEED_BOX_ICON_ON_TORRENT_LIST = 'display_seed_box_icon_on_torrent_list';
|
2022-09-02 19:49:41 +08:00
|
|
|
|
2022-09-06 20:45:29 +08:00
|
|
|
public static array $subCatFields = [
|
|
|
|
|
'source', 'medium', 'codec', 'audiocodec', 'team', 'standard', 'processing'
|
|
|
|
|
];
|
|
|
|
|
|
2022-09-02 19:49:41 +08:00
|
|
|
public static array $extras = [
|
|
|
|
|
self::EXTRA_DISPLAY_COVER_ON_TORRENT_LIST => ['text' => 'Display cover on torrent list'],
|
2022-09-06 21:54:13 +08:00
|
|
|
self::EXTRA_DISPLAY_SEED_BOX_ICON_ON_TORRENT_LIST => ['text' => 'Display seed box icon on torrent list'],
|
2022-09-02 19:49:41 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
public static function listExtraText(): array
|
|
|
|
|
{
|
|
|
|
|
$result = [];
|
|
|
|
|
foreach (self::$extras as $extra => $info) {
|
|
|
|
|
$result[$extra] = nexus_trans("searchbox.extras.$extra");
|
|
|
|
|
}
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-07 17:10:52 +08:00
|
|
|
public static function getTaxonomyDisplayText($field)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-06 20:45:29 +08:00
|
|
|
protected function customFields(): Attribute
|
|
|
|
|
{
|
|
|
|
|
return new Attribute(
|
|
|
|
|
get: fn ($value) => is_string($value) ? explode(',', $value) : $value,
|
|
|
|
|
set: fn ($value) => is_array($value) ? implode(',', $value) : $value,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function getSubCatOptions(): array
|
|
|
|
|
{
|
|
|
|
|
return array_combine(self::$subCatFields, self::$subCatFields);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-20 23:30:34 +08:00
|
|
|
public function categories(): \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Category::class, 'mode');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function normal_fields(): \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(SearchBoxField::class, 'searchbox_id');
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-06 20:45:29 +08:00
|
|
|
public function taxonomy_sources(): \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Source::class, 'mode');
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-07 17:10:52 +08:00
|
|
|
public function taxonomy_medium(): \Illuminate\Database\Eloquent\Relations\HasMany
|
2022-09-06 20:45:29 +08:00
|
|
|
{
|
|
|
|
|
return $this->hasMany(Media::class, 'mode');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function taxonomy_standards(): \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Standard::class, 'mode');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function taxonomy_codecs(): \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Codec::class, 'mode');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function taxonomy_audio_codecs(): \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(AudioCodec::class, 'mode');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function taxonomy_teams(): \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Team::class, 'mode');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function taxonomy_processing(): \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Processing::class, 'mode');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function taxonomies(): \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Taxonomy::class, 'mode');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-05-20 17:14:38 +08:00
|
|
|
}
|