sls/app/Models/Interview.php

105 lines
2.5 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Interview extends Model
{
use HasFactory;
protected $fillable = [
'candidate_name',
'candidate_email',
'candidate_phone',
'temp_password',
'scheduled_at',
'expires_at',
'language',
'status',
'assigned_interviewers',
'proctor_logs',
'submitted_code',
'submitted_language',
'code_output',
'recording_path',
'recordings',
'submission_unique_id',
'candidate_notes',
'candidate_drawing',
'blocked_ip',
'created_by',
'call_status',
'call_started_by',
'call_started_at',
'enable_tab_switch_screenshot',
'tab_switch_screenshots',
'active_peers',
];
protected $casts = [
'scheduled_at' => 'datetime',
'expires_at' => 'datetime',
'call_started_at' => 'datetime',
'enable_tab_switch_screenshot' => 'boolean',
'assigned_interviewers' => 'array',
'proctor_logs' => 'array',
'recordings' => 'array',
'tab_switch_screenshots' => 'array',
'active_peers' => 'array',
];
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
public function callStarter()
{
return $this->belongsTo(User::class, 'call_started_by');
}
public function warnings()
{
return $this->hasMany(InterviewWarning::class, 'interview_id');
}
public function isExpired(): bool
{
return now()->greaterThan($this->expires_at);
}
/**
* Check if the current time is within the interview timeline.
*/
public function isActiveTimeline(): bool
{
$now = now();
$start = $this->scheduled_at ?? $this->created_at;
if ($now->lessThan($start)) {
return false;
}
if ($now->greaterThan($this->expires_at)) {
return false;
}
return !in_array($this->status, ['completed', 'expired']);
}
/**
* Check if a specific user is assigned as an interviewer.
*/
public function isAssignedInterviewer($userId): bool
{
if (empty($this->assigned_interviewers)) {
return false;
}
$interviewers = array_map('strval', (array) $this->assigned_interviewers);
return in_array((string) $userId, $interviewers, true);
}
}