Files
UNIT3D-Community-Edition/app/Models/Rss.php
HDVinnie 8a03bec818 add: model docblocks
- this resolves some larastan property issues but in return has revealed quite a few issues with our castings and such. baseline has been regenerated so we can work through them. The properties in docblocks are in order and match everything in DB schema wise.
2024-02-07 16:39:43 -05:00

146 lines
4.1 KiB
PHP

<?php
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
namespace App\Models;
use App\Traits\Auditable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use stdClass;
/**
* App\Models\Rss.
*
* @property int $id
* @property int $position
* @property string $name
* @property int $user_id
* @property int $is_private
* @property int $is_torrent
* @property array $json_torrent
* @property \Illuminate\Support\Carbon|null $deleted_at
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
*/
class Rss extends Model
{
use Auditable;
use HasFactory;
use SoftDeletes;
/**
* The Database Table Used By The Model.
*
* @var string
*/
protected $table = 'rss';
/**
* Indicates If The Model Should Be Timestamped.
*
* @var bool
*/
public $timestamps = true;
/**
* The Attributes That Should Be Cast To Native Types.
*
* @var array<string, string>
*/
protected $casts = [
'name' => 'string',
'json_torrent' => 'array',
'expected_fields' => 'array',
];
/**
* The attributes that aren't mass assignable.
*
* @var string[]
*/
protected $guarded = ['id', 'created_at', 'updated_at'];
/**
* Belongs To A User.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo<User, self>
*/
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(User::class)->withDefault([
'username' => 'System',
'id' => '1',
]);
}
/**
* Belongs To A Staff Member.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo<User, self>
*/
public function staff(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
// Not needed yet. Just added for future extendability.
return $this->belongsTo(User::class, 'staff_id');
}
/**
* Get the RSS feeds JSON Torrent as object.
*/
public function getObjectTorrentAttribute(): stdClass|bool
{
// Went with attribute to avoid () calls in views. Uniform ->object_torrent vs ->json_torrent.
if ($this->json_torrent) {
$expected = $this->expected_fields;
return (object) array_merge($expected, $this->json_torrent);
}
return false;
}
/**
* Get the RSS feeds expected fields for form validation.
*
* @return array<string, null>
*/
public function getExpectedFieldsAttribute(): array
{
// Just Torrents for now... extendable to check on feed type in future.
return [
'search' => null,
'description' => null,
'uploader' => null,
'imdb' => null,
'mal' => null,
'categories' => null,
'types' => null,
'resolutions' => null,
'genres' => null,
'freeleech' => null,
'doubleupload' => null,
'featured' => null,
'stream' => null,
'highspeed' => null,
'sd' => null,
'internal' => null,
'personalrelease' => null,
'bookmark' => null,
'alive' => null,
'dying' => null,
'dead' => null,
];
}
}