exam add duration

This commit is contained in:
xiaomlove
2021-05-06 01:49:05 +08:00
parent ca07078415
commit 05fb848fc5
9 changed files with 80 additions and 29 deletions
+6 -1
View File
@@ -4,7 +4,7 @@ namespace App\Models;
class Exam extends NexusModel
{
protected $fillable = ['name', 'description', 'begin', 'end', 'status', 'is_discovered', 'filters', 'indexes'];
protected $fillable = ['name', 'description', 'begin', 'end', 'duration', 'status', 'is_discovered', 'filters', 'indexes'];
public $timestamps = true;
@@ -59,4 +59,9 @@ class Exam extends NexusModel
return self::$discovers[$this->is_discovered]['text'] ?? '';
}
public function getDurationTextAttribute(): string
{
return $this->duration . ' Days';
}
}
+42 -3
View File
@@ -24,19 +24,58 @@ class ExamUser extends NexusModel
'progress' => 'json'
];
public function getStatusTextAttribute()
public function getStatusTextAttribute(): string
{
return self::$status[$this->status]['text'] ?? '';
}
public function getBeginAttribute()
{
return $this->begin ?? $this->exam->begin;
$begin = $this->getRawOriginal('begin');
$end = $this->getRawOriginal('end');
if ($begin && $end) {
do_log(sprintf('examUser: %s, begin from self', $this->id));
return $begin;
}
$exam = $this->exam;
$begin = $exam->getRawOriginal('begin');
$end = $exam->getRawOriginal('end');
if ($begin && $end) {
do_log(sprintf('examUser: %s, begin from exam: %s', $this->id, $exam->id));
return $begin;
}
if ($exam->duration > 0) {
do_log(sprintf('examUser: %s, begin from self created_at', $this->id));
return $this->created_at->toDateTimeString();
}
return null;
}
public function getEndAttribute()
{
return $this->end ?? $this->exam->end;
$begin = $this->getRawOriginal('begin');
$end = $this->getRawOriginal('end');
if ($begin && $end) {
do_log(sprintf('examUser: %s, end from self', $this->id));
return $end;
}
$exam = $this->exam;
$begin = $exam->getRawOriginal('begin');
$end = $exam->getRawOriginal('end');
if ($begin && $end) {
do_log(sprintf('examUser: %s, end from exam: %s', $this->id, $exam->id));
return $end;
}
$duration = $exam->duration;
if ($duration > 0) {
do_log(sprintf('examUser: %s, end from self created_at + exam: %s %s days', $this->id, $exam->id, $duration));
return $this->created_at->addDays($duration)->toDateTimeString();
}
return null;
}