72 lines
1.6 KiB
PHP
72 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
class ChatFeedback extends Model
|
|
{
|
|
protected $fillable = [
|
|
'chat_log_id',
|
|
'user_id',
|
|
'rating',
|
|
'comment',
|
|
'correct_answer',
|
|
'converted_to_faq',
|
|
'converted_faq_id',
|
|
'reviewed_by',
|
|
'reviewed_at',
|
|
];
|
|
|
|
protected $casts = [
|
|
'converted_to_faq' => 'boolean',
|
|
'reviewed_at' => 'datetime',
|
|
];
|
|
|
|
const RATING_HELPFUL = 'helpful';
|
|
const RATING_NOT_HELPFUL = 'not_helpful';
|
|
const RATING_PARTIALLY_HELPFUL = 'partially_helpful';
|
|
|
|
// === Relationships ===
|
|
|
|
public function chatLog(): BelongsTo
|
|
{
|
|
return $this->belongsTo(ChatLog::class);
|
|
}
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function reviewer(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'reviewed_by');
|
|
}
|
|
|
|
public function convertedFaq(): BelongsTo
|
|
{
|
|
return $this->belongsTo(KnowledgeItem::class, 'converted_faq_id');
|
|
}
|
|
|
|
// === Scopes ===
|
|
|
|
public function scopeNegative(Builder $query): Builder
|
|
{
|
|
return $query->where('rating', self::RATING_NOT_HELPFUL);
|
|
}
|
|
|
|
public function scopeNotConverted(Builder $query): Builder
|
|
{
|
|
return $query->where('converted_to_faq', false)
|
|
->where('rating', '!=', self::RATING_HELPFUL);
|
|
}
|
|
|
|
public function scopeUnreviewed(Builder $query): Builder
|
|
{
|
|
return $query->whereNull('reviewed_by');
|
|
}
|
|
}
|