Skip to content

Commit

Permalink
exam add backgrond color
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaomlove committed Aug 22, 2024
1 parent 9b83793 commit b8c044d
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 7 deletions.
4 changes: 4 additions & 0 deletions app/Filament/Resources/System/ExamResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Exam.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
});
}
};
6 changes: 3 additions & 3 deletions include/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions nexus/Exam/Exam.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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');
}
}
1 change: 1 addition & 0 deletions resources/lang/en/exam.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];
1 change: 1 addition & 0 deletions resources/lang/zh_CN/exam.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,5 @@
'reach_max_user_count' => '认领人数已达上限',
'claimed_user_count' => '认领人数',
'max_user_count' => '最多认领人数(0表示无限制)',
'background_color' => '信息框背景色',
];
1 change: 1 addition & 0 deletions resources/lang/zh_TW/exam.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,5 @@
'reach_max_user_count' => '認領人數已達上限',
'claimed_user_count' => '認領人數',
'max_user_count' => '最多認領人數(0表示無限製)',
'background_color' => '信息框背景色',
];

0 comments on commit b8c044d

Please sign in to comment.