User::showEmail()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Entities;
4
5
use Carbon\Carbon;
6
use Illuminate\Auth\MustVerifyEmail;
7
use Illuminate\Contracts\Auth\MustVerifyEmail as MustVerifyEmailContract;
8
use Illuminate\Foundation\Auth\User as Authenticatable;
9
use Illuminate\Notifications\Notifiable;
10
use Laratrust\Traits\LaratrustUserTrait;
11
12
/**
13
 * Class User.
14
 *
15
 * @property int $id
16
 * @property string $username
17
 * @property string $email
18
 * @property string $nick
19
 * @property string $school
20
 * @property string $locale
21
 * @property int $language
22
 * @property string $password
23
 * @property string $remember_token
24
 * @property int $submit
25
 * @property int $email_level
26
 * @property int $solved
27
 * @property int $status
28
 * @property Carbon $email_verified_at
29
 * @property Carbon $access_at
30
 * @property Carbon $created_at
31
 * @property Carbon $updated_at
32
 */
33
class User extends Authenticatable implements MustVerifyEmailContract
34
{
35
    use Notifiable, LaratrustUserTrait, MustVerifyEmail;
0 ignored issues
show
introduced by
The trait Laratrust\Traits\LaratrustUserTrait requires some properties which are not provided by App\Entities\User: $forceDeleting, $permissions
Loading history...
36
37
    const ST_ACTIVE = 0;
38
    const ST_INACTIVE = 1;
39
40
    /**
41
     * The attributes that are mass assignable.
42
     *
43
     * @var array
44
     */
45
    protected $fillable = [
46
        'username',
47
        'email',
48
        'school',
49
        'nick',
50
        'email_level',
51
        'confirmed',
52
        'language',
53
        'submit',
54
        'solved',
55
        'locale',
56
        'language',
57
        'status',
58
        'access_at',
59
    ];
60
61
    public $dates = [
62
        'email_verified_at',
63
        'access_at',
64
    ];
65
66
    /**
67
     * The attributes that should be hidden for arrays.
68
     *
69
     * @var array
70
     */
71
    protected $hidden = [
72
        'password',
73
        'remember_token',
74
    ];
75
76
    public function showEmail()
77
    {
78
        return $this->email_level != 0;
79
    }
80
81
    public function getEmail()
82
    {
83
        if ($this->email_level == 2) {
84
            return base64_encode($this->email);
85
        }
86
87
        return $this->email;
88
    }
89
90
    public function logs()
91
    {
92
        return $this->hasMany(LoginLog::class, 'user_id')->orderBy('created_at', 'desc');
93
    }
94
95
    public function contests()
96
    {
97
        return $this->belongsToMany(Contest::class, 'contest_user', 'user_id');
98
    }
99
100
    public function isActive()
101
    {
102
        return $this->status === self::ST_ACTIVE;
103
    }
104
}
105