Files
UNIT3D-Community-Edition/app/Models/TorrentRequest.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

208 lines
6.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\Helpers\Bbcode;
use App\Helpers\Linkify;
use App\Traits\Auditable;
use App\Traits\TorrentFilter;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use voku\helper\AntiXSS;
/**
* App\Models\TorrentRequest.
*
* @property int $id
* @property string $name
* @property int $category_id
* @property int|null $imdb
* @property int|null $tvdb
* @property int|null $tmdb
* @property int|null $mal
* @property int $igdb
* @property string $description
* @property int $user_id
* @property float $bounty
* @property int $votes
* @property int|null $claimed
* @property int $anon
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property int|null $filled_by
* @property int|null $torrent_id
* @property \Illuminate\Support\Carbon|null $filled_when
* @property int $filled_anon
* @property int|null $approved_by
* @property \Illuminate\Support\Carbon|null $approved_when
* @property int $type_id
* @property int|null $resolution_id
*/
class TorrentRequest extends Model
{
use Auditable;
use HasFactory;
use TorrentFilter;
/**
* The Attributes That Should Be Mutated To Dates.
*
* @var array<string, string>
*/
protected $casts = [
'filled_when' => 'datetime',
'approved_when' => 'datetime',
'igdb' => 'integer',
];
/**
* The Database Table Used By The Model.
*
* @var string
*/
protected $table = 'requests';
/**
* 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 User.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo<User, self>
*/
public function approver(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(User::class, 'approved_by')->withDefault([
'username' => 'System',
'id' => '1',
]);
}
/**
* Belongs To A User.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo<User, self>
*/
public function filler(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(User::class, 'filled_by')->withDefault([
'username' => 'System',
'id' => '1',
]);
}
/**
* Belongs To A Category.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo<Category, self>
*/
public function category(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Category::class);
}
/**
* Belongs To A Type.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo<Type, self>
*/
public function type(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Type::class);
}
/**
* Belongs To A Resolution.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo<Resolution, self>
*/
public function resolution(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Resolution::class);
}
/**
* Belongs To A Torrent.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo<Torrent, self>
*/
public function torrent(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Torrent::class);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\MorphMany<Comment>
*/
public function comments(): \Illuminate\Database\Eloquent\Relations\MorphMany
{
return $this->morphMany(Comment::class, 'commentable');
}
/**
* Has Many BON Bounties.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany<TorrentRequestBounty>
*/
public function bounties(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(TorrentRequestBounty::class, 'requests_id', 'id');
}
/**
* Has One Torrent Request Claim.
*
* @return \Illuminate\Database\Eloquent\Relations\HasOne<TorrentRequestClaim>
*/
public function claim(): \Illuminate\Database\Eloquent\Relations\HasOne
{
return $this->hasOne(TorrentRequestClaim::class, 'request_id');
}
/**
* Set The Requests Description After Its Been Purified.
*/
public function setDescriptionAttribute(?string $value): void
{
$this->attributes['description'] = htmlspecialchars((new AntiXSS())->xss_clean($value), ENT_NOQUOTES);
}
/**
* Parse Description And Return Valid HTML.
*/
public function getDescriptionHtml(): string
{
$bbcode = new Bbcode();
return (new Linkify())->linky($bbcode->parse($this->description));
}
}