2021-04-25 02:12:14 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
class ExamUser extends NexusModel
|
|
|
|
|
{
|
2021-04-28 19:44:48 +08:00
|
|
|
protected $fillable = ['exam_id', 'uid', 'status', 'progress', 'begin', 'end', 'is_done'];
|
2021-04-25 02:12:14 +08:00
|
|
|
|
|
|
|
|
public $timestamps = true;
|
|
|
|
|
|
|
|
|
|
const STATUS_NORMAL = 0;
|
|
|
|
|
const STATUS_FINISHED = 1;
|
|
|
|
|
|
|
|
|
|
public static $status = [
|
|
|
|
|
self::STATUS_NORMAL => ['text' => 'Normal'],
|
|
|
|
|
self::STATUS_FINISHED => ['text' => 'Finished'],
|
|
|
|
|
];
|
|
|
|
|
|
2021-04-28 19:44:48 +08:00
|
|
|
const IS_DONE_YES = 1;
|
|
|
|
|
const IS_DONE_NO = 0;
|
|
|
|
|
|
|
|
|
|
|
2021-04-25 02:12:14 +08:00
|
|
|
protected $casts = [
|
2021-04-27 02:44:44 +08:00
|
|
|
'progress' => 'json'
|
2021-04-25 02:12:14 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
public function getStatusTextAttribute()
|
|
|
|
|
{
|
|
|
|
|
return self::$status[$this->status]['text'] ?? '';
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-29 19:18:13 +08:00
|
|
|
public function getBeginAttribute()
|
|
|
|
|
{
|
|
|
|
|
return $this->begin ?? $this->exam->begin;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getEndAttribute()
|
|
|
|
|
{
|
|
|
|
|
return $this->end ?? $this->exam->end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-04-25 02:12:14 +08:00
|
|
|
public function exam(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Exam::class, 'exam_id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(User::class, 'uid');
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-25 21:28:58 +08:00
|
|
|
public function progresses()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(ExamProgress::class, 'exam_user_id');
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-25 02:12:14 +08:00
|
|
|
|
|
|
|
|
}
|