1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App; |
4
|
|
|
|
5
|
|
|
use Illuminate\Auth\Authenticatable; |
6
|
|
|
use Illuminate\Auth\Passwords\CanResetPassword; |
7
|
|
|
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; |
8
|
|
|
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract; |
9
|
|
|
use Illuminate\Database\Eloquent\Model; |
10
|
|
|
|
11
|
|
|
class User extends Model implements AuthenticatableContract, CanResetPasswordContract |
12
|
|
|
{ |
13
|
|
|
use Authenticatable, |
14
|
|
|
CanResetPassword; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* The database table used by the model. |
18
|
|
|
* |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $table = 'users'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* The attributes that are mass assignable. |
25
|
|
|
* |
26
|
|
|
* @var array |
27
|
|
|
*/ |
28
|
|
|
protected $fillable = ['user_name', 'email', 'password', 'active', 'first_name', 'last_name', 'ban', 'ext', 'mobile', 'profile_pic', |
29
|
|
|
'phone_number', 'company', 'agent_sign', 'account_type', 'account_status', |
30
|
|
|
'assign_group', 'primary_dpt', 'agent_tzone', 'daylight_save', 'limit_access', |
31
|
|
|
'directory_listing', 'vacation_mode', 'role', 'internal_note', 'country_code', 'not_accept_ticket', 'is_delete', ]; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* The attributes excluded from the model's JSON form. |
35
|
|
|
* |
36
|
|
|
* @var array |
37
|
|
|
*/ |
38
|
|
|
protected $hidden = ['password', 'remember_token']; |
39
|
|
|
|
40
|
|
|
public function getProfilePicAttribute($value) |
41
|
|
|
{ |
42
|
|
|
$info = $this->avatar(); |
43
|
|
|
$pic = null; |
44
|
|
|
if ($info) { |
45
|
|
|
$pic = $this->checkArray('avatar', $info); |
46
|
|
|
} |
47
|
|
|
if (!$pic) { |
48
|
|
|
$pic = asset('uploads/profilepic/'.$value); |
49
|
|
|
} |
50
|
|
|
if (!$value) { |
51
|
|
|
$pic = \Gravatar::src($this->attributes['email']); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return $pic; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function avatar() |
58
|
|
|
{ |
59
|
|
|
$related = 'App\UserAdditionalInfo'; |
60
|
|
|
$foreignKey = 'owner'; |
61
|
|
|
|
62
|
|
|
return $this->hasMany($related, $foreignKey)->select('value')->where('key', 'avatar')->first(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getOrganizationRelation() |
66
|
|
|
{ |
67
|
|
|
$related = "App\Model\helpdesk\Agent_panel\User_org"; |
68
|
|
|
$user_relation = $this->hasMany($related, 'user_id'); |
69
|
|
|
$relation = $user_relation->first(); |
70
|
|
|
if ($relation) { |
71
|
|
|
$org_id = $relation->org_id; |
72
|
|
|
$orgs = new \App\Model\helpdesk\Agent_panel\Organization(); |
73
|
|
|
$org = $orgs->where('id', $org_id); |
|
|
|
|
74
|
|
|
|
75
|
|
|
return $org; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
View Code Duplication |
public function getOrganization() |
|
|
|
|
80
|
|
|
{ |
81
|
|
|
$name = ''; |
82
|
|
|
if ($this->getOrganizationRelation()) { |
83
|
|
|
$org = $this->getOrganizationRelation()->first(); |
84
|
|
|
if ($org) { |
85
|
|
|
$name = $org->name; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
return $name; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
View Code Duplication |
public function getOrgWithLink() |
|
|
|
|
93
|
|
|
{ |
94
|
|
|
$name = ''; |
95
|
|
|
$org = $this->getOrganization(); |
96
|
|
|
if ($org !== '') { |
97
|
|
|
$orgs = $this->getOrganizationRelation()->first(); |
98
|
|
|
if ($orgs) { |
99
|
|
|
$id = $orgs->id; |
100
|
|
|
$name = '<a href='.url('organizations/'.$id).'>'.ucfirst($org).'</a>'; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
return $name; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function getEmailAttribute($value) |
108
|
|
|
{ |
109
|
|
|
if (!$value) { |
110
|
|
|
$value = \Lang::get('lang.not-available'); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
return $value; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function getExtraInfo($id = '') |
117
|
|
|
{ |
118
|
|
|
if ($id === '') { |
119
|
|
|
$id = $this->attributes['id']; |
120
|
|
|
} |
121
|
|
|
$info = new UserAdditionalInfo(); |
122
|
|
|
$infos = $info->where('owner', $id)->lists('value', 'key')->toArray(); |
|
|
|
|
123
|
|
|
|
124
|
|
|
return $infos; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
View Code Duplication |
public function checkArray($key, $array) |
|
|
|
|
128
|
|
|
{ |
129
|
|
|
$value = ''; |
130
|
|
|
if (is_array($array)) { |
131
|
|
|
if (array_key_exists($key, $array)) { |
132
|
|
|
$value = $array[$key]; |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
return $value; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function twitterLink() |
140
|
|
|
{ |
141
|
|
|
$html = ''; |
142
|
|
|
$info = $this->getExtraInfo(); |
143
|
|
|
$username = $this->checkArray('username', $info); |
144
|
|
|
if ($username !== '') { |
145
|
|
|
$html = "<a href='https://twitter.com/".$username."' target='_blank'><i class='fa fa-twitter'> </i> Twitter</a>"; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
return $html; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
public function name() |
152
|
|
|
{ |
153
|
|
|
$first_name = $this->first_name; |
|
|
|
|
154
|
|
|
$last_name = $this->last_name; |
|
|
|
|
155
|
|
|
$name = $this->user_name; |
|
|
|
|
156
|
|
|
if ($first_name !== '' && $first_name !== null) { |
157
|
|
|
if ($last_name !== '' && $last_name !== null) { |
158
|
|
|
$name = $first_name.' '.$last_name; |
159
|
|
|
} else { |
160
|
|
|
$name = $first_name; |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
return $name; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
public function getFullNameAttribute() |
168
|
|
|
{ |
169
|
|
|
return $this->name(); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
// public function save() { |
|
|
|
|
173
|
|
|
// dd($this->id); |
174
|
|
|
// parent::save(); |
175
|
|
|
// } |
176
|
|
|
|
177
|
|
|
// public function save(array $options = array()) { |
|
|
|
|
178
|
|
|
// parent::save($options); |
179
|
|
|
// dd($this->where('id',$this->id)->select('first_name','last_name','user_name','email')->get()->toJson()); |
180
|
|
|
// } |
181
|
|
|
} |
182
|
|
|
|
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: