mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-26 13:27:22 +08:00
show-exam
This commit is contained in:
@@ -2,9 +2,13 @@
|
|||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Models\Exam;
|
||||||
|
use App\Models\ExamProgress;
|
||||||
|
use App\Models\ExamUser;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Repositories\ExamRepository;
|
use App\Repositories\ExamRepository;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
|
||||||
class Test extends Command
|
class Test extends Command
|
||||||
@@ -40,9 +44,8 @@ class Test extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$examRep = new ExamRepository();
|
$rep = new ExamRepository();
|
||||||
$user = User::query()->find(1);
|
$r = $rep->listUserExamProgress(1);
|
||||||
$r = $examRep->assignToUser($user->id);
|
|
||||||
dd($r);
|
dd($r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ namespace App\Models;
|
|||||||
|
|
||||||
class ExamProgress extends NexusModel
|
class ExamProgress extends NexusModel
|
||||||
{
|
{
|
||||||
protected $fillable = ['exam_id', 'uid', 'type_id', 'value'];
|
protected $fillable = ['exam_user_id', 'exam_id', 'uid', 'index', 'value', 'torrent_id'];
|
||||||
|
|
||||||
public $timestamps = true;
|
public $timestamps = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,5 +35,10 @@ class ExamUser extends NexusModel
|
|||||||
return $this->belongsTo(User::class, 'uid');
|
return $this->belongsTo(User::class, 'uid');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function progresses()
|
||||||
|
{
|
||||||
|
return $this->hasMany(ExamProgress::class, 'exam_user_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
class Torrent extends NexusModel
|
||||||
|
{
|
||||||
|
protected $fillable = [
|
||||||
|
'name', 'filename', 'save_as', 'descr', 'small_descr', 'ori_descr',
|
||||||
|
'category', 'source', 'medium', 'codec', 'standard', 'processing', 'team', 'audiocodec',
|
||||||
|
'size', 'added', 'type', 'numfiles', 'owner', 'nfo', 'sp_state', 'promotion_time_type',
|
||||||
|
'promotion_until', 'anonymous', 'url', 'pos_state', 'cache_stamp', 'picktype', 'picktime',
|
||||||
|
'last_reseed', 'pt_gen', 'tags', 'technical_info'
|
||||||
|
];
|
||||||
|
|
||||||
|
const VISIBLE_YES = 'yes';
|
||||||
|
const VISIBLE_NO = 'no';
|
||||||
|
|
||||||
|
const BANNED_YES = 'yes';
|
||||||
|
const BANNED_NO = 'no';
|
||||||
|
|
||||||
|
public $timestamps = true;
|
||||||
|
|
||||||
|
public function checkIsNormal(array $fields = ['visible', 'banned'])
|
||||||
|
{
|
||||||
|
if (in_array('visible', $fields) && $this->getAttribute('visible') != self::VISIBLE_YES) {
|
||||||
|
throw new \InvalidArgumentException(sprintf('Torrent: %s is not visible.', $this->id));
|
||||||
|
}
|
||||||
|
if (in_array('banned', $fields) && $this->getAttribute('banned') == self::BANNED_YES) {
|
||||||
|
throw new \InvalidArgumentException(sprintf('Torrent: %s is banned.', $this->id));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
+16
-5
@@ -16,6 +16,9 @@ class User extends Authenticatable
|
|||||||
const STATUS_CONFIRMED = 'confirmed';
|
const STATUS_CONFIRMED = 'confirmed';
|
||||||
const STATUS_PENDING = 'pending';
|
const STATUS_PENDING = 'pending';
|
||||||
|
|
||||||
|
const ENABLED_YES = 'yes';
|
||||||
|
const ENABLED_NO = 'no';
|
||||||
|
|
||||||
const CLASS_PEASANT = "0";
|
const CLASS_PEASANT = "0";
|
||||||
const CLASS_USER = "1";
|
const CLASS_USER = "1";
|
||||||
const CLASS_POWER_USER = "2";
|
const CLASS_POWER_USER = "2";
|
||||||
@@ -96,12 +99,20 @@ class User extends Authenticatable
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
|
'added' => 'datetime',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $dates = [
|
public function checkIsNormal(array $fields = ['status', 'enabled'])
|
||||||
'added'
|
{
|
||||||
];
|
if (in_array('visible', $fields) && $this->getAttribute('status') != self::STATUS_CONFIRMED) {
|
||||||
|
throw new \InvalidArgumentException(sprintf('User: %s is not confirmed.', $this->id));
|
||||||
|
}
|
||||||
|
if (in_array('enabled', $fields) && $this->getAttribute('enabled') != self::ENABLED_YES) {
|
||||||
|
throw new \InvalidArgumentException(sprintf('User: %s is not enabled.', $this->id));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function exams(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
public function exams(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||||
@@ -111,7 +122,7 @@ class User extends Authenticatable
|
|||||||
|
|
||||||
public function examDetails(): \Illuminate\Database\Eloquent\Relations\HasMany
|
public function examDetails(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(ExamUser::class. 'uid');
|
return $this->hasMany(ExamUser::class, 'uid');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,10 @@
|
|||||||
namespace App\Repositories;
|
namespace App\Repositories;
|
||||||
|
|
||||||
use App\Models\Exam;
|
use App\Models\Exam;
|
||||||
|
use App\Models\ExamProgress;
|
||||||
use App\Models\ExamUser;
|
use App\Models\ExamUser;
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
|
use App\Models\Torrent;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
@@ -141,6 +143,7 @@ class ExamRepository extends BaseRepository
|
|||||||
return $filtered;
|
return $filtered;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* assign exam to user
|
* assign exam to user
|
||||||
*
|
*
|
||||||
@@ -187,6 +190,70 @@ class ExamRepository extends BaseRepository
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addProgress(int $examUserId, int $indexId, int $value, int $torrentId)
|
||||||
|
{
|
||||||
|
$examUser = ExamUser::query()->with(['exam', 'user'])->findOrFail($examUserId);
|
||||||
|
if ($examUser->status != ExamUser::STATUS_NORMAL) {
|
||||||
|
throw new \InvalidArgumentException("ExamUser: $examUserId is not normal.");
|
||||||
|
}
|
||||||
|
if (!isset(Exam::$indexes[$indexId])) {
|
||||||
|
throw new \InvalidArgumentException("Invalid index id: $indexId.");
|
||||||
|
}
|
||||||
|
$exam = $examUser->exam;
|
||||||
|
$indexes = collect($exam->indexes)->keyBy('index');
|
||||||
|
if (!$indexes->has($indexId)) {
|
||||||
|
throw new \InvalidArgumentException(sprintf('Exam: %s does not has index: %s', $exam->id, $indexId));
|
||||||
|
}
|
||||||
|
$index = $indexes->get($indexId);
|
||||||
|
if (!isset($index['checked']) || !$index['checked']) {
|
||||||
|
throw new \InvalidArgumentException(sprintf('Exam: %s index: %s is not checked', $exam->id, $indexId));
|
||||||
|
}
|
||||||
|
$torrentFields = ['id', 'visible', 'banned'];
|
||||||
|
$torrent = Torrent::query()->findOrFail($torrentId, $torrentFields);
|
||||||
|
$torrent->checkIsNormal(true, $torrentFields);
|
||||||
|
|
||||||
|
$user = $examUser->user;
|
||||||
|
$user->checkIsNormal();
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'uid' => $user->id,
|
||||||
|
'exam_id' => $exam->id,
|
||||||
|
'torrent_id' => $torrentId,
|
||||||
|
'index' => $indexId,
|
||||||
|
'value' => $value,
|
||||||
|
];
|
||||||
|
Log::info('[addProgress]', $data);
|
||||||
|
return $examUser->progresses()->create($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function listUserExamProgress($uid, $status = null)
|
||||||
|
{
|
||||||
|
$logPrefix = "uid: $uid";
|
||||||
|
$query = ExamUser::query()->with(['exam', 'user'])->where('uid', $uid)->orderBy('exam_id', 'desc');
|
||||||
|
if ($status) {
|
||||||
|
$query->where('status', $status);
|
||||||
|
}
|
||||||
|
$result = $query->paginate();
|
||||||
|
$idArr = array_column($result->items(), 'id');
|
||||||
|
$progressSum = ExamProgress::query()
|
||||||
|
->whereIn('exam_user_id', $idArr)
|
||||||
|
->groupBy(['exam_user_id', 'index'])
|
||||||
|
->selectRaw('`exam_user_id`, `index`, sum(`value`) as `index_sum`')
|
||||||
|
->get();
|
||||||
|
|
||||||
|
$map = [];
|
||||||
|
foreach ($progressSum as $value) {
|
||||||
|
$map[$value->exam_user_id][$value->index] = $value->index_sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($result as &$item) {
|
||||||
|
$item->progress_value = $map[$item->id] ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
if (!empty($_SERVER['HTTP_X_REQUEST_ID'])) {
|
||||||
|
define('REQUEST_ID', $_SERVER['HTTP_X_REQUEST_ID']);
|
||||||
|
} else {
|
||||||
|
define('REQUEST_ID', intval(LARAVEL_START * 10000));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Create The Application
|
| Create The Application
|
||||||
|
|||||||
@@ -15,9 +15,11 @@ class CreateExamProgressTable extends Migration
|
|||||||
{
|
{
|
||||||
Schema::create('exam_progress', function (Blueprint $table) {
|
Schema::create('exam_progress', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
|
$table->integer('exam_user_id')->index();
|
||||||
$table->integer('exam_id')->index();
|
$table->integer('exam_id')->index();
|
||||||
$table->integer('uid')->index();
|
$table->integer('uid')->index();
|
||||||
$table->integer('type_id');
|
$table->integer('torrent_id');
|
||||||
|
$table->integer('index');
|
||||||
$table->integer('value');
|
$table->integer('value');
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
$table->index('created_at');
|
$table->index('created_at');
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ if (!file_exists($rootpath . '.env')) {
|
|||||||
require $rootpath . 'vendor/autoload.php';
|
require $rootpath . 'vendor/autoload.php';
|
||||||
require $rootpath . 'nexus/Database/helpers.php';
|
require $rootpath . 'nexus/Database/helpers.php';
|
||||||
require $rootpath . 'classes/class_cache_redis.php';
|
require $rootpath . 'classes/class_cache_redis.php';
|
||||||
|
require $rootpath . 'include/eloquent.php';
|
||||||
require $rootpath . 'include/config.php';
|
require $rootpath . 'include/config.php';
|
||||||
|
|
||||||
ini_set('date.timezone', nexus_config('nexus.timezone'));
|
ini_set('date.timezone', nexus_config('nexus.timezone'));
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use \Illuminate\Database\Capsule\Manager as Capsule;
|
||||||
|
|
||||||
|
$config = require ROOT_PATH . 'config/nexus.php';
|
||||||
|
$connectionMysql = $config['mysql'];
|
||||||
|
$connectionMysql['driver'] = 'mysql';
|
||||||
|
$connectionMysql['charset'] = 'utf8mb4';
|
||||||
|
$connectionMysql['collation'] = 'utf8mb4_unicode_ci';
|
||||||
|
$capsule = new Capsule;
|
||||||
|
$capsule->addConnection($connectionMysql, 'default');
|
||||||
|
$capsule->setAsGlobal();
|
||||||
|
$capsule->bootEloquent();
|
||||||
|
|
||||||
|
|
||||||
@@ -2598,12 +2598,11 @@ if ($msgalert)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//show the exam info
|
//show the exam info
|
||||||
$examRepository = new \App\Repositories\ExamRepository();
|
$exam = new \Nexus\Exam\Exam();
|
||||||
$matchExams = $examRepository->listMatchExam($CURUSER['id']);
|
$examHtml = $exam->render($CURUSER['id']);
|
||||||
// if ($matchExams->isNotEmpty()) {
|
if (!empty($examHtml)) {
|
||||||
// dd($matchExams);
|
msgalert("messages.php", $examHtml, "green");
|
||||||
// }
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if ($offlinemsg)
|
if ($offlinemsg)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -315,7 +315,10 @@ $lang_functions = array
|
|||||||
'text_required' => '不能为空',
|
'text_required' => '不能为空',
|
||||||
'text_invalid' => '非法',
|
'text_invalid' => '非法',
|
||||||
'text_technical_info' => '技术信息',
|
'text_technical_info' => '技术信息',
|
||||||
'text_technical_info_help_text' => '文件技术信息来自软件 <b><a href="https://mediaarea.net/en/MediaInfo" target=\'_blank\'>MediaInfo</a></b>,用该软件打开文件,点击菜单视图(View)->文件(Text),在框中右键->全选,再右键->复制,粘贴到这里来。'
|
'text_technical_info_help_text' => '文件技术信息来自软件 <b><a href="https://mediaarea.net/en/MediaInfo" target=\'_blank\'>MediaInfo</a></b>,用该软件打开文件,点击菜单视图(View)->文件(Text),在框中右键->全选,再右键->复制,粘贴到这里来。',
|
||||||
|
'exam_name' => '考核名称',
|
||||||
|
'exam_time_range' => '考核时间',
|
||||||
|
'exam_index' => '考核指标',
|
||||||
);
|
);
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Nexus\Exam;
|
||||||
|
|
||||||
|
use App\Repositories\ExamRepository;
|
||||||
|
use App\Models\Exam as ExamModel;
|
||||||
|
|
||||||
|
class Exam
|
||||||
|
{
|
||||||
|
public function render($uid)
|
||||||
|
{
|
||||||
|
global $lang_functions;
|
||||||
|
$examRep = new ExamRepository();
|
||||||
|
$userExams = $examRep->listUserExamProgress($uid);
|
||||||
|
if ($userExams->isEmpty()) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
$htmlArr = [];
|
||||||
|
foreach ($userExams as $userExam) {
|
||||||
|
$exam = $userExam->exam;
|
||||||
|
$row = [];
|
||||||
|
$row[] = sprintf('%s:%s', $lang_functions['exam_name'], $exam->name);
|
||||||
|
$row[] = sprintf('%s:%s ~ %s', $lang_functions['exam_time_range'], $exam->begin, $exam->end);
|
||||||
|
foreach ($exam->indexes as $key => $index) {
|
||||||
|
if (isset($index['checked']) && $index['checked']) {
|
||||||
|
$requireValue = $index['require_value'];
|
||||||
|
$currentValue = $userExam->progress_value[$index['index']] ?? 0;
|
||||||
|
$unit = ExamModel::$indexes[$index['index']]['unit'] ?? '';
|
||||||
|
$row[] = sprintf(
|
||||||
|
'%s:%s, Require:%s %s, Current:%s %s, Result:%s',
|
||||||
|
$lang_functions['exam_index'] . ($key + 1),
|
||||||
|
ExamModel::$indexes[$index['index']]['name'] ?? '',
|
||||||
|
$requireValue, $unit,
|
||||||
|
$currentValue, $unit,
|
||||||
|
$currentValue >= $requireValue ? 'Done!' : 'Not done!'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$htmlArr[] = implode("\n", $row);
|
||||||
|
}
|
||||||
|
return nl2br(implode("\n\n", $htmlArr));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user