Contest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 29
c 1
b 0
f 0
dl 0
loc 76
rs 10
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A isPublic() 0 3 1
A isAvailable() 0 3 1
A problems() 0 5 1
A solutions() 0 3 1
A isOpen() 0 5 1
A isEnd() 0 3 1
A questions() 0 3 1
A users() 0 3 1
1
<?php
2
3
namespace App\Entities;
4
5
use Illuminate\Database\Eloquent\Collection;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Database\Eloquent\SoftDeletes;
8
use Illuminate\Support\Carbon;
9
10
/**
11
 * Class Contest.
12
 *
13
 * @property int $id
14
 * @property string $title
15
 * @property string $description
16
 * @property Carbon $start_time
17
 * @property Carbon $end_time
18
 * @property int $user_id
19
 * @property int $status
20
 * @property bool $private
21
 * @property-read Collection|Problem[] $problems
22
 * @property-read Collection|User[] $users
23
 */
24
class Contest extends Model
25
{
26
    use SoftDeletes;
27
    const PRIVATE = 1;
28
    const PUBLIC = 0;
29
30
    const ST_NORMAL = 0;
31
    const ST_HIDE = 1;
32
33
    protected $dates = [
34
        'start_time',
35
        'end_time',
36
    ];
37
38
    protected $fillable = [
39
        'id',
40
        'title',
41
        'description',
42
        'start_time',
43
        'end_time',
44
        'user_id',
45
        'status',
46
        'private',
47
    ];
48
49
    public function isOpen()
50
    {
51
        $now = new Carbon();
52
53
        return $now->between($this->start_time, $this->end_time);
54
    }
55
56
    public function isEnd()
57
    {
58
        return Carbon::now()->gt($this->end_time);
59
    }
60
61
    /**
62
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
63
     */
64
    public function problems()
65
    {
66
        return $this->belongsToMany(Problem::class)
67
                    ->withPivot(['order', 'title'])
68
                    ->orderBy('order', 'asc');
69
    }
70
71
    /**
72
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
73
     */
74
    public function questions()
75
    {
76
        return $this->hasMany(Topic::class);
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
    public function users()
88
    {
89
        return $this->belongsToMany(User::class, 'contest_user', 'contest_id');
90
    }
91
92
    public function isPublic()
93
    {
94
        return $this->private == self::PUBLIC;
95
    }
96
97
    public function isAvailable()
98
    {
99
        return $this->status === 0;
100
    }
101
}
102