Issues (44)

app/Entities/Problem.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace App\Entities;
4
5
use Carbon\Carbon;
6
use Illuminate\Database\Eloquent\Collection;
7
use Illuminate\Database\Eloquent\Model;
8
use Illuminate\Database\Eloquent\SoftDeletes;
9
10
/**
11
 * Class Problem.
12
 *
13
 * @property int $id
14
 * @property string $title
15
 * @property string $description
16
 * @property string $input
17
 * @property string $output
18
 * @property string $sample_input
19
 * @property string $sample_output
20
 * @property string $hint
21
 * @property string $source
22
 * @property int $status
23
 * @property int $time_limit
24
 * @property int $memory_limit
25
 * @property int $submit
26
 * @property int $accepted
27
 * @property int $spj
28
 * @property string $memo
29
 * @property int $user_id
30
 * @property User $author
31
 * @property Solution[]|Collection $solutions
32
 * @property Carbon $created_at
33
 * @property Carbon $updated_at
34
 * @property Carbon $deleted_at
35
 */
36
class Problem extends Model
37
{
38
    use SoftDeletes;
39
40
    const ST_NORMAL = 0;
41
    const ST_HIDE = 1;
42
43
    protected $fillable = [
44
        'title',
45
        'description',
46
        'input',
47
        'output',
48
        'sample_input',
49
        'sample_output',
50
        'spj',
51
        'hint',
52
        'source',
53
        'time_limit',
54
        'memory_limit',
55
        'accepted',
56
        'submit',
57
        'status',
58
        'memo',
59
    ];
60
61
    /**
62
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
63
     */
64
    public function author()
65
    {
66
        return $this->belongsTo(User::class, 'user_id');
67
    }
68
69
    /**
70
     * is problem special judge.
71
     *
72
     * @return bool
73
     */
74
    public function isSpecialJudge()
75
    {
76
        return (int) $this->spj === 1;
77
    }
78
79
    /**
80
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
81
     */
82
    public function solutions()
83
    {
84
        return $this->hasMany(Solution::class);
85
    }
86
87
    /**
88
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany|Contest[]
89
     */
90
    public function contests()
91
    {
92
        return $this->belongsToMany(Contest::class);
93
    }
94
95
    public function order()
96
    {
97
        if (isset($this->pivot)) {
98
            return show_order($this->pivot->order);
0 ignored issues
show
The property pivot does not seem to exist on App\Entities\Problem. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
99
        }
100
101
        return $this->id;
102
    }
103
104
    public function isAvailable()
105
    {
106
        return $this->status === self::ST_NORMAL;
107
    }
108
}
109