Files
nexusphp/nexus/Exam/Exam.php

41 lines
1.6 KiB
PHP
Raw Normal View History

2021-04-25 21:28:58 +08:00
<?php
namespace Nexus\Exam;
use App\Models\ExamUser;
2021-04-25 21:28:58 +08:00
use App\Repositories\ExamRepository;
class Exam
{
2024-08-23 04:52:53 +08:00
public function getCurrent($uid): array
2021-04-25 21:28:58 +08:00
{
$examRep = new ExamRepository();
2021-06-14 01:54:19 +08:00
$userExam = $examRep->getUserExamProgress($uid, ExamUser::STATUS_NORMAL);
2021-04-26 20:37:17 +08:00
if (empty($userExam)) {
2024-08-23 04:52:53 +08:00
return ['exam' => null, 'html' => ''];
2021-04-25 21:28:58 +08:00
}
2024-06-27 03:29:03 +08:00
/** @var \App\Models\Exam $exam */
2021-04-26 20:37:17 +08:00
$exam = $userExam->exam;
$row = [];
$row[] = sprintf('%s%s', nexus_trans('exam.name'), $exam->name);
$row[] = sprintf('%s%s ~ %s', nexus_trans('exam.time_range'), $userExam->begin, $userExam->end);
foreach ($userExam->progress_formatted as $key => $index) {
2021-04-26 20:37:17 +08:00
if (isset($index['checked']) && $index['checked']) {
$row[] = sprintf(
'%s%s, %s%s, %s%s, %s%s',
nexus_trans('exam.index') . ($key + 1), nexus_trans('exam.index_text_' . $index['index']),
nexus_trans('exam.require_value'), $index['require_value_formatted'],
nexus_trans('exam.current_value'), $index['current_value_formatted'],
nexus_trans('exam.result'),
2024-06-27 03:29:03 +08:00
$index['passed'] ? nexus_trans($exam->getPassResultTransKey("pass")) : nexus_trans($exam->getPassResultTransKey("not_pass"))
2021-04-26 20:37:17 +08:00
);
2021-04-25 21:28:58 +08:00
}
}
2022-03-21 19:09:32 +08:00
if ($exam->description) {
$row[] = "\n" . $exam->description;
}
2024-08-23 04:52:53 +08:00
$html = nl2br(implode("\n", $row));
return compact('exam', 'html');
2021-04-25 21:28:58 +08:00
}
}