exam add backgrond color

This commit is contained in:
xiaomlove
2024-08-23 04:52:53 +08:00
parent 9b83793c93
commit b8c044d546
8 changed files with 47 additions and 7 deletions
@@ -104,6 +104,10 @@ class ExamResource extends Resource
->inline() ->inline()
->required() ->required()
->columnSpan(['sm' => 2]), ->columnSpan(['sm' => 2]),
Forms\Components\TextInput::make('background_color')
->required()
->label(__('exam.background_color'))
->columnSpan(['sm' => 2]),
Forms\Components\TextInput::make('priority') Forms\Components\TextInput::make('priority')
->columnSpan(['sm' => 2]) ->columnSpan(['sm' => 2])
->integer() ->integer()
+1 -1
View File
@@ -11,7 +11,7 @@ class Exam extends NexusModel
{ {
protected $fillable = [ protected $fillable = [
'name', 'description', 'begin', 'end', 'duration', 'status', 'is_discovered', 'filters', 'indexes', 'priority', '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; public $timestamps = true;
@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('exams', function (Blueprint $table) {
$table->string("background_color")->default("blue");
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('exams', function (Blueprint $table) {
$table->dropColumn("background_color");
});
}
};
+3 -3
View File
@@ -2899,9 +2899,9 @@ if ($msgalert)
//show the exam info //show the exam info
$exam = new \Nexus\Exam\Exam(); $exam = new \Nexus\Exam\Exam();
$examHtml = $exam->render($CURUSER['id']); $currentExam = $exam->getCurrent($CURUSER['id']);
if (!empty($examHtml)) { if (!empty($currentExam['html'])) {
msgalert("messages.php", $examHtml, "blue"); msgalert("messages.php", $currentExam['html'], $currentExam['exam']->background_color ?? 'blue');
} }
} }
if ($offlinemsg) if ($offlinemsg)
+4 -3
View File
@@ -7,12 +7,12 @@ use App\Repositories\ExamRepository;
class Exam class Exam
{ {
public function render($uid) public function getCurrent($uid): array
{ {
$examRep = new ExamRepository(); $examRep = new ExamRepository();
$userExam = $examRep->getUserExamProgress($uid, ExamUser::STATUS_NORMAL); $userExam = $examRep->getUserExamProgress($uid, ExamUser::STATUS_NORMAL);
if (empty($userExam)) { if (empty($userExam)) {
return ''; return ['exam' => null, 'html' => ''];
} }
/** @var \App\Models\Exam $exam */ /** @var \App\Models\Exam $exam */
$exam = $userExam->exam; $exam = $userExam->exam;
@@ -34,6 +34,7 @@ class Exam
if ($exam->description) { if ($exam->description) {
$row[] = "\n" . $exam->description; $row[] = "\n" . $exam->description;
} }
return nl2br(implode("\n", $row)); $html = nl2br(implode("\n", $row));
return compact('exam', 'html');
} }
} }
+1
View File
@@ -68,4 +68,5 @@ return [
'reach_max_user_count' => 'The number of claimed users has reached its maximum', 'reach_max_user_count' => 'The number of claimed users has reached its maximum',
'claimed_user_count' => 'Claimed', 'claimed_user_count' => 'Claimed',
'max_user_count' => 'Max claim user count(0 means unlimited)', 'max_user_count' => 'Max claim user count(0 means unlimited)',
'background_color' => 'Info box background color',
]; ];
+1
View File
@@ -70,4 +70,5 @@ return [
'reach_max_user_count' => '认领人数已达上限', 'reach_max_user_count' => '认领人数已达上限',
'claimed_user_count' => '认领人数', 'claimed_user_count' => '认领人数',
'max_user_count' => '最多认领人数(0表示无限制)', 'max_user_count' => '最多认领人数(0表示无限制)',
'background_color' => '信息框背景色',
]; ];
+1
View File
@@ -68,4 +68,5 @@ return [
'reach_max_user_count' => '認領人數已達上限', 'reach_max_user_count' => '認領人數已達上限',
'claimed_user_count' => '認領人數', 'claimed_user_count' => '認領人數',
'max_user_count' => '最多認領人數(0表示無限製)', 'max_user_count' => '最多認領人數(0表示無限製)',
'background_color' => '信息框背景色',
]; ];