mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-23 19:37:23 +08:00
show-exam
This commit is contained in:
@@ -4,7 +4,7 @@ namespace App\Models;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -35,5 +35,10 @@ class ExamUser extends NexusModel
|
||||
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_PENDING = 'pending';
|
||||
|
||||
const ENABLED_YES = 'yes';
|
||||
const ENABLED_NO = 'no';
|
||||
|
||||
const CLASS_PEASANT = "0";
|
||||
const CLASS_USER = "1";
|
||||
const CLASS_POWER_USER = "2";
|
||||
@@ -96,12 +99,20 @@ class User extends Authenticatable
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
|
||||
'added' => 'datetime',
|
||||
];
|
||||
|
||||
protected $dates = [
|
||||
'added'
|
||||
];
|
||||
public function checkIsNormal(array $fields = ['status', 'enabled'])
|
||||
{
|
||||
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
|
||||
@@ -111,7 +122,7 @@ class User extends Authenticatable
|
||||
|
||||
public function examDetails(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(ExamUser::class. 'uid');
|
||||
return $this->hasMany(ExamUser::class, 'uid');
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user