mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 12:30:49 +08:00
fix exam get begin and end
This commit is contained in:
@@ -164,14 +164,14 @@ class Exam extends NexusModel
|
|||||||
return implode("<br/>", $arr);
|
return implode("<br/>", $arr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function begin(): Attribute
|
protected function beginForUser(): Attribute
|
||||||
{
|
{
|
||||||
return new Attribute(
|
return new Attribute(
|
||||||
get: fn ($value) => $value ? Carbon::parse($value) : Carbon::now()
|
get: fn ($value) => $value ? Carbon::parse($value) : Carbon::now()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function end(): Attribute
|
protected function endForUser(): Attribute
|
||||||
{
|
{
|
||||||
return new Attribute(
|
return new Attribute(
|
||||||
get: function ($value, $attributes) {
|
get: function ($value, $attributes) {
|
||||||
@@ -180,8 +180,8 @@ class Exam extends NexusModel
|
|||||||
}
|
}
|
||||||
if (!empty($attributes['duration'])) {
|
if (!empty($attributes['duration'])) {
|
||||||
/** @var Carbon $begin */
|
/** @var Carbon $begin */
|
||||||
$begin = $this->begin;
|
$begin = $this->begin_for_user;
|
||||||
return $begin->addDays($attributes['duration']);
|
return $begin->clone()->addDays($attributes['duration']);
|
||||||
}
|
}
|
||||||
throw new \RuntimeException("No specific end or duration");
|
throw new \RuntimeException("No specific end or duration");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -349,27 +349,12 @@ class ExamRepository extends BaseRepository
|
|||||||
'exam_id' => $exam->id,
|
'exam_id' => $exam->id,
|
||||||
];
|
];
|
||||||
if (empty($begin)) {
|
if (empty($begin)) {
|
||||||
if (!empty($exam->begin)) {
|
$begin = $exam->begin_for_user;
|
||||||
$begin = $exam->begin;
|
|
||||||
$logPrefix .= ", begin from exam->begin: $begin";
|
|
||||||
} else {
|
|
||||||
$begin = now();
|
|
||||||
$logPrefix .= ", begin from now: $begin";
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$begin = Carbon::parse($begin);
|
$begin = Carbon::parse($begin);
|
||||||
}
|
}
|
||||||
if (empty($end)) {
|
if (empty($end)) {
|
||||||
if (!empty($exam->end)) {
|
$end = $exam->end_for_user;
|
||||||
$end = $exam->end;
|
|
||||||
$logPrefix .= ", end from exam->end: $end";
|
|
||||||
} elseif ($exam->duration > 0) {
|
|
||||||
$duration = $exam->duration;
|
|
||||||
$end = $begin->clone()->addDays($duration)->toDateTimeString();
|
|
||||||
$logPrefix .= ", end from begin + duration($duration): $end";
|
|
||||||
} else {
|
|
||||||
throw new \RuntimeException("No specific end or duration");
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$end = Carbon::parse($end);
|
$end = Carbon::parse($end);
|
||||||
}
|
}
|
||||||
@@ -1018,8 +1003,8 @@ class ExamRepository extends BaseRepository
|
|||||||
$size = 1000;
|
$size = 1000;
|
||||||
$minId = 0;
|
$minId = 0;
|
||||||
$result = 0;
|
$result = 0;
|
||||||
$begin = $exam->begin;
|
$begin = $exam->begin_for_user;
|
||||||
$end = $exam->end;
|
$end = $exam->end_for_user;
|
||||||
while (true) {
|
while (true) {
|
||||||
$logPrefix = sprintf('[%s], exam: %s, size: %s', __FUNCTION__, $exam->id , $size);
|
$logPrefix = sprintf('[%s], exam: %s, size: %s', __FUNCTION__, $exam->id , $size);
|
||||||
$users = (clone $baseQuery)->where("$userTable.id", ">", $minId)->limit($size)->get();
|
$users = (clone $baseQuery)->where("$userTable.id", ">", $minId)->limit($size)->get();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.12');
|
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.12');
|
||||||
defined('RELEASE_DATE') || define('RELEASE_DATE', '2024-04-10');
|
defined('RELEASE_DATE') || define('RELEASE_DATE', '2024-04-13');
|
||||||
defined('IN_TRACKER') || define('IN_TRACKER', false);
|
defined('IN_TRACKER') || define('IN_TRACKER', false);
|
||||||
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
|
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
|
||||||
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
|
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
|
||||||
|
|||||||
Reference in New Issue
Block a user