Files
UNIT3D-Community-Edition/app/Models/Comment.php
HDVinnie 9a893662de Apply fixes from StyleCI
[ci skip] [skip ci]
2020-01-08 16:28:32 +00:00

137 lines
4.0 KiB
PHP
Executable File

<?php
/**
* NOTICE OF LICENSE.
*
* UNIT3D 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
*
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
* @author HDVinnie
*/
namespace App\Models;
use App\Helpers\Bbcode;
use App\Traits\Auditable;
use Illuminate\Database\Eloquent\Model;
/**
* App\Models\Comment.
*
* @property int $id
* @property string $content
* @property int $anon
* @property int|null $torrent_id
* @property int|null $article_id
* @property int|null $requests_id
* @property int|null $user_id
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \App\Models\Article|null $article
* @property-read \App\Models\TorrentRequest|null $request
* @property-read \App\Models\Torrent|null $torrent
* @property-read \App\Models\User|null $user
*
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Comment newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Comment newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Comment query()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Comment whereAnon($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Comment whereArticleId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Comment whereContent($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Comment whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Comment whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Comment whereRequestsId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Comment whereTorrentId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Comment whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Comment whereUserId($value)
* @mixin \Eloquent
*
* @property int|null $playlist_id
* @property-read \App\Models\Playlist|null $playlist
*
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Comment wherePlaylistId($value)
*/
class Comment extends Model
{
use Auditable;
/**
* Belongs To A Torrent.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function torrent()
{
return $this->belongsTo(Torrent::class);
}
/**
* Belongs To A Article.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function article()
{
return $this->belongsTo(Article::class);
}
/**
* Belongs To A Request.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function request()
{
return $this->belongsTo(TorrentRequest::class, 'requests_id', 'id');
}
/**
* Belongs To A Playlist.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function playlist()
{
return $this->belongsTo(Playlist::class);
}
/**
* Belongs To A User.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user()
{
return $this->belongsTo(User::class)->withDefault([
'username' => 'System',
'id' => '1',
]);
}
/**
* Set The Comments Content After Its Been Purified.
*
* @param string $value
*
* @return void
*/
public function setContentAttribute($value)
{
$this->attributes['content'] = htmlspecialchars($value);
}
/**
* Parse Content And Return Valid HTML.
*
* @return string Parsed BBCODE To HTML
*/
public function getContentHtml()
{
$bbcode = new Bbcode();
return $bbcode->parse($this->content, true);
}
}