Captures the current working tree after theme slots, ArticleAccess, and the payment / paid-content plugins so subsequent work has a reviewable git history.
70 lines
1.5 KiB
PHP
70 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Domain\Plugin\Hook;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class Comment extends Model
|
|
{
|
|
public const STATUS_PENDING = 'pending';
|
|
|
|
public const STATUS_PENDING_AI = 'pending_ai';
|
|
|
|
public const STATUS_APPROVED = 'approved';
|
|
|
|
public const STATUS_REJECTED = 'rejected';
|
|
|
|
public const STATUS_NEEDS_HUMAN = 'needs_human';
|
|
|
|
protected $fillable = [
|
|
'article_id',
|
|
'author',
|
|
'url',
|
|
'content',
|
|
'ip',
|
|
'moderation_status',
|
|
'published_at',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'published_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::created(function (Comment $comment): void {
|
|
Hook::dispatch('comment.created', $comment);
|
|
});
|
|
}
|
|
|
|
public function article(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Article::class);
|
|
}
|
|
|
|
public function scopeApproved(Builder $query): Builder
|
|
{
|
|
return $query->where('moderation_status', self::STATUS_APPROVED);
|
|
}
|
|
|
|
public function scopeVisible(Builder $query): Builder
|
|
{
|
|
return $query->approved()
|
|
->whereNotNull('published_at')
|
|
->where('published_at', '<=', now());
|
|
}
|
|
|
|
public function isApproved(): bool
|
|
{
|
|
return $this->moderation_status === self::STATUS_APPROVED;
|
|
}
|
|
}
|