2021-04-19 20:13:21 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
2021-05-08 16:25:55 +08:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
2021-04-19 20:13:21 +08:00
|
|
|
class Exam extends NexusModel
|
|
|
|
|
{
|
2021-05-06 01:49:05 +08:00
|
|
|
protected $fillable = ['name', 'description', 'begin', 'end', 'duration', 'status', 'is_discovered', 'filters', 'indexes'];
|
2021-04-23 20:05:39 +08:00
|
|
|
|
2021-04-25 02:12:14 +08:00
|
|
|
public $timestamps = true;
|
|
|
|
|
|
2021-04-23 20:05:39 +08:00
|
|
|
protected $casts = [
|
|
|
|
|
'filters' => 'object',
|
|
|
|
|
'indexes' => 'array',
|
|
|
|
|
];
|
2021-04-20 20:18:02 +08:00
|
|
|
|
|
|
|
|
const STATUS_ENABLED = 0;
|
|
|
|
|
const STATUS_DISABLED = 1;
|
|
|
|
|
|
|
|
|
|
public static $status = [
|
2021-04-23 20:05:39 +08:00
|
|
|
self::STATUS_ENABLED => ['text' => 'Enabled'],
|
|
|
|
|
self::STATUS_DISABLED => ['text' => 'Disabled'],
|
2021-04-20 20:18:02 +08:00
|
|
|
];
|
|
|
|
|
|
2021-05-02 17:24:05 +08:00
|
|
|
const DISCOVERED_YES = 1;
|
|
|
|
|
const DISCOVERED_NO = 0;
|
|
|
|
|
|
|
|
|
|
public static $discovers = [
|
|
|
|
|
self::DISCOVERED_NO => ['text' => 'No'],
|
|
|
|
|
self::DISCOVERED_YES => ['text' => 'Yes'],
|
|
|
|
|
];
|
|
|
|
|
|
2021-04-20 20:18:02 +08:00
|
|
|
const INDEX_UPLOADED = 1;
|
2021-04-27 02:44:44 +08:00
|
|
|
const INDEX_SEED_TIME_AVERAGE = 2;
|
2021-04-20 20:18:02 +08:00
|
|
|
const INDEX_DOWNLOADED = 3;
|
2021-05-05 22:28:19 +08:00
|
|
|
const INDEX_SEED_BONUS = 4;
|
2021-04-20 20:18:02 +08:00
|
|
|
|
|
|
|
|
public static $indexes = [
|
2021-04-23 20:05:39 +08:00
|
|
|
self::INDEX_UPLOADED => ['name' => 'Uploaded', 'unit' => 'GB'],
|
2021-05-02 17:24:05 +08:00
|
|
|
self::INDEX_SEED_TIME_AVERAGE => ['name' => 'Seed time average', 'unit' => 'Hour'],
|
2021-04-23 20:05:39 +08:00
|
|
|
self::INDEX_DOWNLOADED => ['name' => 'Downloaded', 'unit' => 'GB'],
|
2021-05-05 22:28:19 +08:00
|
|
|
self::INDEX_SEED_BONUS => ['name' => 'Seed bonus', 'unit' => ''],
|
2021-04-23 20:05:39 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const FILTER_USER_CLASS = 'classes';
|
|
|
|
|
const FILTER_USER_REGISTER_TIME_RANGE = 'register_time_range';
|
|
|
|
|
|
|
|
|
|
public static $filters = [
|
2021-05-02 17:24:05 +08:00
|
|
|
self::FILTER_USER_CLASS => ['name' => 'User class'],
|
|
|
|
|
self::FILTER_USER_REGISTER_TIME_RANGE => ['name' => 'User register time range'],
|
2021-04-20 20:18:02 +08:00
|
|
|
];
|
|
|
|
|
|
2021-05-08 16:25:55 +08:00
|
|
|
protected static function booted()
|
|
|
|
|
{
|
|
|
|
|
static::saving(function (Model $model) {
|
|
|
|
|
$model->duration = (int)$model->duration;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-27 02:44:44 +08:00
|
|
|
public function getStatusTextAttribute(): string
|
2021-04-20 20:18:02 +08:00
|
|
|
{
|
|
|
|
|
return self::$status[$this->status]['text'] ?? '';
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-02 17:24:05 +08:00
|
|
|
public function getIsDiscoveredTextAttribute(): string
|
|
|
|
|
{
|
|
|
|
|
return self::$discovers[$this->is_discovered]['text'] ?? '';
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-08 16:25:55 +08:00
|
|
|
public function getDurationTextAttribute($value): string
|
2021-05-06 01:49:05 +08:00
|
|
|
{
|
2021-05-08 16:25:55 +08:00
|
|
|
if ($value > 0) {
|
|
|
|
|
return $value . ' Days';
|
|
|
|
|
}
|
|
|
|
|
return '';
|
2021-05-06 01:49:05 +08:00
|
|
|
}
|
|
|
|
|
|
2021-04-19 20:13:21 +08:00
|
|
|
}
|