mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 03:57:22 +08:00
exam user set begin and end when cronjobAssign()
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Google\Service\Dataproc\RegexValidation;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Exam extends NexusModel
|
||||
@@ -162,4 +164,28 @@ class Exam extends NexusModel
|
||||
return implode("<br/>", $arr);
|
||||
}
|
||||
|
||||
public function begin(): Attribute
|
||||
{
|
||||
return new Attribute(
|
||||
get: fn ($value) => $value ? Carbon::parse($value) : Carbon::now()
|
||||
);
|
||||
}
|
||||
|
||||
public function end(): Attribute
|
||||
{
|
||||
return new Attribute(
|
||||
get: function ($value, $attributes) {
|
||||
if ($value) {
|
||||
return Carbon::parse($value);
|
||||
}
|
||||
if (!empty($attributes['duration'])) {
|
||||
/** @var Carbon $begin */
|
||||
$begin = $this->begin;
|
||||
return $begin->addDays($attributes['duration']);
|
||||
}
|
||||
throw new \RuntimeException("No specific end or duration");
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -67,16 +67,14 @@ class ExamUser extends NexusModel
|
||||
public function getBeginAttribute()
|
||||
{
|
||||
$begin = $this->getRawOriginal('begin');
|
||||
$end = $this->getRawOriginal('end');
|
||||
if ($begin && $end) {
|
||||
if ($begin) {
|
||||
do_log(sprintf('examUser: %s, begin from self: %s', $this->id, $begin));
|
||||
return $begin;
|
||||
}
|
||||
|
||||
$exam = $this->exam;
|
||||
$begin = $exam->getRawOriginal('begin');
|
||||
$end = $exam->getRawOriginal('end');
|
||||
if ($begin && $end) {
|
||||
if ($begin) {
|
||||
do_log(sprintf('examUser: %s, begin from exam(%s): %s', $this->id, $exam->id, $begin));
|
||||
return $begin;
|
||||
}
|
||||
@@ -90,17 +88,15 @@ class ExamUser extends NexusModel
|
||||
|
||||
public function getEndAttribute()
|
||||
{
|
||||
$begin = $this->getRawOriginal('begin');
|
||||
$end = $this->getRawOriginal('end');
|
||||
if ($begin && $end) {
|
||||
if ($end) {
|
||||
do_log(sprintf('examUser: %s, end from self: %s', $this->id, $end));
|
||||
return $end;
|
||||
}
|
||||
|
||||
$exam = $this->exam;
|
||||
$begin = $exam->getRawOriginal('begin');
|
||||
$end = $exam->getRawOriginal('end');
|
||||
if ($begin && $end) {
|
||||
if ($end) {
|
||||
do_log(sprintf('examUser: %s, end from exam(%s): %s', $this->id, $exam->id, $end));
|
||||
return $end;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user