-
Notifications
You must be signed in to change notification settings - Fork 0
/
User.php
128 lines (107 loc) · 3.38 KB
/
User.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
namespace Modules\Core;
use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use Vinkla\Hashids\Facades\Hashids;
use Codesleeve\Stapler\ORM\StaplerableInterface;
use Codesleeve\Stapler\ORM\EloquentTrait;
use Illuminate\Database\Eloquent\SoftDeletes;
class User extends Model implements AuthenticatableContract, CanResetPasswordContract, StaplerableInterface
{
use Authenticatable, CanResetPassword, EloquentTrait, SoftDeletes;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'cwa_users';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['name', 'email', 'password', 'avatar', 'features'];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = ['password', 'remember_token'];
public function __construct(array $attributes = array())
{
$this->hasAttachedFile('avatar', [
'styles' => [
'medium' => '300x300',
'thumb' => '100x100'
]
]);
parent::__construct($attributes);
}
public function uniqueid()
{
$uniqueId = Hashids::encode($this->id);
return $uniqueId;
}
public static function originalid($value)
{
$originalId = Hashids::decode($value)[0];
return $originalId;
}
public function userpreference()
{
return $this->hasOne('Modules\Core\UserPreference');
}
public function usersubscription()
{
return $this->hasOne('Modules\Core\UserSubscription');
}
public function userintegration()
{
return $this->hasOne('Modules\Core\UserIntegration');
}
public function emails()
{
return $this->hasMany('Modules\Core\UserEmailTrack');
}
public function dismissednotifications()
{
return $this->hasMany('Modules\Notification\NotificationTrack')
->where('status', '=', 'DISMISSED')
->select(array('notification_id'));
}
/**
* Check is logged user has access to something
* @param string $tag Feature tag name
* @return boolean|null true: has access, false: doesn't has access, null: tag name is invalid
*/
public function hasAccess($tag)
{
$features = [];
$userPreference = $this->userpreference;
$userLevels = json_decode($userPreference->userlevel_id, true);
foreach ($userLevels as $userlevelId) {
$userLevel = UserLevel::find($userlevelId);
$fs = json_decode($userLevel->features, true);
if ($fs != null) {
foreach ($fs as $f => $v) {
$features[$f] = $v;
}
}
}
if (isset($features[$tag])) {
return $features[$tag] === true ? true : $features[$tag];
}
return false;
}
public function userleveltracks()
{
return $this->hasMany('Modules\Core\UserLevelTrack');
}
public function checkUserExpiration()
{
return \Modules\Core\Helpers\AuthHelper::checkUserExpiration('', $this->id);
}
}