diff --git a/app/Filament/Resources/System/ExamResource.php b/app/Filament/Resources/System/ExamResource.php index 05b29f86..f0f542db 100644 --- a/app/Filament/Resources/System/ExamResource.php +++ b/app/Filament/Resources/System/ExamResource.php @@ -104,6 +104,10 @@ public static function form(Form $form): Form ->inline() ->required() ->columnSpan(['sm' => 2]), + Forms\Components\TextInput::make('background_color') + ->required() + ->label(__('exam.background_color')) + ->columnSpan(['sm' => 2]), Forms\Components\TextInput::make('priority') ->columnSpan(['sm' => 2]) ->integer() diff --git a/app/Models/Exam.php b/app/Models/Exam.php index 04e04898..f00dcd71 100644 --- a/app/Models/Exam.php +++ b/app/Models/Exam.php @@ -11,7 +11,7 @@ class Exam extends NexusModel { protected $fillable = [ 'name', 'description', 'begin', 'end', 'duration', 'status', 'is_discovered', 'filters', 'indexes', 'priority', - 'recurring', 'type', 'success_reward_bonus', 'fail_deduct_bonus', 'max_user_count' + 'recurring', 'type', 'success_reward_bonus', 'fail_deduct_bonus', 'max_user_count', 'background_color', ]; public $timestamps = true; diff --git a/database/migrations/2024_08_23_040843_add_background_color_to_exams_table.php b/database/migrations/2024_08_23_040843_add_background_color_to_exams_table.php new file mode 100644 index 00000000..7198cbef --- /dev/null +++ b/database/migrations/2024_08_23_040843_add_background_color_to_exams_table.php @@ -0,0 +1,32 @@ +string("background_color")->default("blue"); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('exams', function (Blueprint $table) { + $table->dropColumn("background_color"); + }); + } +}; diff --git a/include/functions.php b/include/functions.php index 54241436..0a635a13 100644 --- a/include/functions.php +++ b/include/functions.php @@ -2899,9 +2899,9 @@ function stdhead($title = "", $msgalert = true, $script = "", $place = "") //show the exam info $exam = new \Nexus\Exam\Exam(); - $examHtml = $exam->render($CURUSER['id']); - if (!empty($examHtml)) { - msgalert("messages.php", $examHtml, "blue"); + $currentExam = $exam->getCurrent($CURUSER['id']); + if (!empty($currentExam['html'])) { + msgalert("messages.php", $currentExam['html'], $currentExam['exam']->background_color ?? 'blue'); } } if ($offlinemsg) diff --git a/nexus/Exam/Exam.php b/nexus/Exam/Exam.php index d617c224..356df92b 100644 --- a/nexus/Exam/Exam.php +++ b/nexus/Exam/Exam.php @@ -7,12 +7,12 @@ class Exam { - public function render($uid) + public function getCurrent($uid): array { $examRep = new ExamRepository(); $userExam = $examRep->getUserExamProgress($uid, ExamUser::STATUS_NORMAL); if (empty($userExam)) { - return ''; + return ['exam' => null, 'html' => '']; } /** @var \App\Models\Exam $exam */ $exam = $userExam->exam; @@ -34,6 +34,7 @@ public function render($uid) if ($exam->description) { $row[] = "\n" . $exam->description; } - return nl2br(implode("\n", $row)); + $html = nl2br(implode("\n", $row)); + return compact('exam', 'html'); } } diff --git a/resources/lang/en/exam.php b/resources/lang/en/exam.php index e4d1895a..2349503f 100644 --- a/resources/lang/en/exam.php +++ b/resources/lang/en/exam.php @@ -68,4 +68,5 @@ 'reach_max_user_count' => 'The number of claimed users has reached its maximum', 'claimed_user_count' => 'Claimed', 'max_user_count' => 'Max claim user count(0 means unlimited)', + 'background_color' => 'Info box background color', ]; diff --git a/resources/lang/zh_CN/exam.php b/resources/lang/zh_CN/exam.php index f79b3f68..f4a3b185 100644 --- a/resources/lang/zh_CN/exam.php +++ b/resources/lang/zh_CN/exam.php @@ -70,4 +70,5 @@ 'reach_max_user_count' => '认领人数已达上限', 'claimed_user_count' => '认领人数', 'max_user_count' => '最多认领人数(0表示无限制)', + 'background_color' => '信息框背景色', ]; diff --git a/resources/lang/zh_TW/exam.php b/resources/lang/zh_TW/exam.php index 5f439d05..9dc12076 100644 --- a/resources/lang/zh_TW/exam.php +++ b/resources/lang/zh_TW/exam.php @@ -68,4 +68,5 @@ 'reach_max_user_count' => '認領人數已達上限', 'claimed_user_count' => '認領人數', 'max_user_count' => '最多認領人數(0表示無限製)', + 'background_color' => '信息框背景色', ];