| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- class PreQuestionCandidate extends Model
- {
- use HasFactory;
- protected $fillable = [
- 'import_id',
- 'sequence',
- 'index',
- 'raw_markdown',
- 'stem',
- 'options',
- 'images',
- 'tables',
- 'is_question_candidate',
- 'ai_confidence',
- 'status',
- ];
- protected $casts = [
- 'is_question_candidate' => 'boolean',
- 'ai_confidence' => 'float',
- 'sequence' => 'integer',
- 'options' => 'array',
- 'images' => 'array',
- 'tables' => 'array',
- 'created_at' => 'datetime',
- 'updated_at' => 'datetime',
- ];
- public const STATUS_PENDING = 'pending';
- public const STATUS_REVIEWED = 'reviewed';
- public const STATUS_ACCEPTED = 'accepted';
- public const STATUS_REJECTED = 'rejected';
- public const STATUS_SUPERSEDED = 'superseded';
- public function import(): BelongsTo
- {
- return $this->belongsTo(MarkdownImport::class, 'import_id');
- }
- public function getConfidenceBadgeAttribute(): string
- {
- if ($this->ai_confidence === null) {
- return 'gray';
- }
- if ($this->ai_confidence >= 0.8) {
- return 'success';
- } elseif ($this->ai_confidence >= 0.5) {
- return 'warning';
- }
- return 'danger';
- }
- public function getStatusBadgeAttribute(): string
- {
- $badges = [
- self::STATUS_PENDING => 'gray',
- self::STATUS_REVIEWED => 'info',
- self::STATUS_ACCEPTED => 'success',
- self::STATUS_REJECTED => 'danger',
- self::STATUS_SUPERSEDED => 'gray',
- ];
- return $badges[$this->status] ?? 'gray';
- }
- public function getFirstImageAttribute(): ?string
- {
- if (empty($this->images)) {
- return null;
- }
- $images = is_string($this->images) ? json_decode($this->images, true) : $this->images;
- return $images[0] ?? null;
- }
- public function getStemPreviewAttribute(): string
- {
- if (!$this->stem) {
- return 'No stem extracted';
- }
- return \Str::limit($this->stem, 100);
- }
- }
|