exam-user

This commit is contained in:
xiaomlove
2021-04-25 02:12:14 +08:00
parent a0c7a7e5dc
commit 0c5f3d935d
28 changed files with 869 additions and 92 deletions

View File

@@ -6,6 +6,8 @@ class AgentAllow extends NexusModel
{
protected $table = 'agent_allowed_family';
public $timestamps = true;
protected $fillable = [
'family', 'start_name', 'exception', 'allowhttps', 'comment',
'peer_id_pattern', 'peer_id_match_num', 'peer_id_matchtype', 'peer_id_start',

View File

@@ -6,6 +6,8 @@ class Exam extends NexusModel
{
protected $fillable = ['name', 'description', 'begin', 'end', 'status', 'filters', 'indexes'];
public $timestamps = true;
protected $casts = [
'filters' => 'object',
'indexes' => 'array',

View File

@@ -5,4 +5,6 @@ namespace App\Models;
class ExamProgress extends NexusModel
{
protected $fillable = ['exam_id', 'uid', 'type_id', 'value'];
public $timestamps = true;
}

39
app/Models/ExamUser.php Normal file
View File

@@ -0,0 +1,39 @@
<?php
namespace App\Models;
class ExamUser extends NexusModel
{
protected $fillable = ['exam_id', 'uid', 'status', 'result'];
public $timestamps = true;
const STATUS_NORMAL = 0;
const STATUS_FINISHED = 1;
public static $status = [
self::STATUS_NORMAL => ['text' => 'Normal'],
self::STATUS_FINISHED => ['text' => 'Finished'],
];
protected $casts = [
'result' => 'json'
];
public function getStatusTextAttribute()
{
return self::$status[$this->status]['text'] ?? '';
}
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');
}
}

View File

@@ -11,6 +11,8 @@ class NexusModel extends Model
public $timestamps = false;
protected $perPage = 2;
/**
* 为数组 / JSON 序列化准备日期。
*

View File

@@ -54,6 +54,8 @@ class User extends Authenticatable
self::CLASS_STAFF_LEADER => ['text' => 'Staff Leader'],
];
protected $perPage = 2;
public function getClassTextAttribute(): string
{
return self::$classes[$this->class]['text'] ?? '';
@@ -96,4 +98,21 @@ class User extends Authenticatable
protected $casts = [
];
protected $dates = [
'added'
];
public function exams(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(Exam::class, 'exam_users', 'uid', 'exam_id')->withTimestamps();
}
public function examDetails(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(ExamUser::class. 'uid');
}
}