1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Models\Eloquent; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
6
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
7
|
|
|
|
8
|
|
|
class UserExtra extends Model |
9
|
|
|
{ |
10
|
|
|
protected $table='users_extra'; |
11
|
|
|
|
12
|
|
|
protected $fillable=['uid', 'key', 'value', 'secret_level']; |
13
|
|
|
|
14
|
|
|
public static $extraMapping=[ |
15
|
|
|
0 => 'gender', |
16
|
|
|
1 => 'contact', |
17
|
|
|
2 => 'school', |
18
|
|
|
3 => 'country', |
19
|
|
|
4 => 'location', |
20
|
|
|
5 => 'editor_left_width', |
21
|
|
|
6 => 'editor_theme', |
22
|
|
|
|
23
|
|
|
1000 => 'github_id', |
24
|
|
|
1001 => 'github_email', |
25
|
|
|
1002 => 'github_nickname', |
26
|
|
|
1003 => 'github_homepage', |
27
|
|
|
1004 => 'github_token', |
28
|
|
|
1010 => 'aauth_id', |
29
|
|
|
1011 => 'aauth_nickname', |
30
|
|
|
]; |
31
|
|
|
|
32
|
|
|
public static $extraDict=[ |
33
|
|
|
'gender' => [ |
34
|
|
|
'icon' => 'MDI gender-transgender', |
35
|
|
|
'locale' => 'dashboard.setting.gender', |
36
|
|
|
], |
37
|
|
|
'contact' => [ |
38
|
|
|
'icon' => 'MDI contacts', |
39
|
|
|
'locale' => 'dashboard.setting.contact', |
40
|
|
|
], |
41
|
|
|
'school' => [ |
42
|
|
|
'icon' => 'MDI school', |
43
|
|
|
'locale' => 'dashboard.setting.school', |
44
|
|
|
], |
45
|
|
|
'country' => [ |
46
|
|
|
'icon' => 'MDI earth', |
47
|
|
|
'locale' => 'dashboard.setting.countryAndRegion', |
48
|
|
|
], |
49
|
|
|
'location' => [ |
50
|
|
|
'icon' => 'MDI map-marker', |
51
|
|
|
'locale' => 'dashboard.setting.detailedLocation', |
52
|
|
|
], |
53
|
|
|
]; |
54
|
|
|
|
55
|
|
|
public static $socialite_support=[ |
56
|
|
|
//use the form "platform_id" for unique authentication |
57
|
|
|
//such as github_id |
58
|
|
|
'github' => [ |
59
|
|
|
'email', 'nickname', 'homepage', 'token' |
60
|
|
|
], |
61
|
|
|
'aauth' => [ |
62
|
|
|
'nickname' |
63
|
|
|
], |
64
|
|
|
]; |
65
|
|
|
|
66
|
|
|
public function user() { |
67
|
|
|
return $this->belongsTo('App\Models\Eloquent\User', 'id', 'uid'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* find a extra info key-value pair |
72
|
|
|
* @param string $key_name the key |
73
|
|
|
* @param string $value the value |
74
|
|
|
* @return string $result |
75
|
|
|
*/ |
76
|
|
|
public static function search($key, $value) |
77
|
|
|
{ |
78
|
|
|
$key=array_search($key, UserExtra::$extraMapping); |
79
|
|
|
if ($key) { |
80
|
|
|
return self::where([ |
|
|
|
|
81
|
|
|
'key' => $key, |
82
|
|
|
'value' => $value |
83
|
|
|
])->limit(1)->get()->toArray(); |
84
|
|
|
} else { |
85
|
|
|
return null; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
} |
90
|
|
|
|