Skip to content

Commit

Permalink
fix exam get begin and end
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaomlove committed Apr 12, 2024
1 parent 6ea03a2 commit cb4f91b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 24 deletions.
8 changes: 4 additions & 4 deletions app/Models/Exam.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,14 @@ public function getFilterFormattedAttribute(): string
return implode("<br/>", $arr);
}

public function begin(): Attribute
protected function beginForUser(): Attribute
{
return new Attribute(
get: fn ($value) => $value ? Carbon::parse($value) : Carbon::now()
);
}

public function end(): Attribute
protected function endForUser(): Attribute
{
return new Attribute(
get: function ($value, $attributes) {
Expand All @@ -180,8 +180,8 @@ public function end(): Attribute
}
if (!empty($attributes['duration'])) {
/** @var Carbon $begin */
$begin = $this->begin;
return $begin->addDays($attributes['duration']);
$begin = $this->begin_for_user;
return $begin->clone()->addDays($attributes['duration']);
}
throw new \RuntimeException("No specific end or duration");
}
Expand Down
23 changes: 4 additions & 19 deletions app/Repositories/ExamRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,27 +349,12 @@ public function assignToUser(int $uid, int $examId, $begin = null, $end = null)
'exam_id' => $exam->id,
];
if (empty($begin)) {
if (!empty($exam->begin)) {
$begin = $exam->begin;
$logPrefix .= ", begin from exam->begin: $begin";
} else {
$begin = now();
$logPrefix .= ", begin from now: $begin";
}
$begin = $exam->begin_for_user;
} else {
$begin = Carbon::parse($begin);
}
if (empty($end)) {
if (!empty($exam->end)) {
$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");
}
$end = $exam->end_for_user;
} else {
$end = Carbon::parse($end);
}
Expand Down Expand Up @@ -1018,8 +1003,8 @@ public function fetchUserAndDoAssign(Exam $exam): bool|int
$size = 1000;
$minId = 0;
$result = 0;
$begin = $exam->begin;
$end = $exam->end;
$begin = $exam->begin_for_user;
$end = $exam->end_for_user;
while (true) {
$logPrefix = sprintf('[%s], exam: %s, size: %s', __FUNCTION__, $exam->id , $size);
$users = (clone $baseQuery)->where("$userTable.id", ">", $minId)->limit($size)->get();
Expand Down
2 changes: 1 addition & 1 deletion include/constants.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
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('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
Expand Down

0 comments on commit cb4f91b

Please sign in to comment.