|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace app\models; |
|
4
|
|
|
|
|
5
|
|
|
use app\models\User; |
|
6
|
|
|
use app\models\query\UserProviderQuery; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* This is the model class for table "user_provider" |
|
10
|
|
|
* |
|
11
|
|
|
* @property integer $id |
|
12
|
|
|
* @property integer $user_id |
|
13
|
|
|
* @property integer $type |
|
14
|
|
|
* @property string $profile_id |
|
15
|
|
|
* @property string $profile_url |
|
16
|
|
|
* @property string $access_token |
|
17
|
|
|
* @property string $access_token_secret |
|
18
|
|
|
*/ |
|
19
|
|
|
class UserProvider extends \yii\db\ActiveRecord |
|
20
|
|
|
{ |
|
21
|
|
|
const TYPE_TWITTER = 1; |
|
22
|
|
|
const TYPE_FACEBOOK = 2; |
|
23
|
|
|
const TYPE_VKONTAKTE = 3; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @inheritdoc |
|
27
|
|
|
*/ |
|
28
|
|
|
public static function tableName() |
|
29
|
|
|
{ |
|
30
|
|
|
return 'user_provider'; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @inheritdoc |
|
35
|
|
|
*/ |
|
36
|
|
|
public function rules() |
|
37
|
|
|
{ |
|
38
|
|
|
return [ |
|
39
|
|
|
[ |
|
40
|
|
|
['type', 'profile_id', 'profile_url', 'access_token', 'access_token_secret'], 'safe' |
|
41
|
|
|
], |
|
42
|
|
|
]; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @inheritdoc |
|
47
|
|
|
* @return UserProviderQuery |
|
48
|
|
|
*/ |
|
49
|
|
|
public static function find() |
|
50
|
|
|
{ |
|
51
|
|
|
return new UserProviderQuery(get_called_class()); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @return \yii\db\ActiveQuery |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getUser() |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->hasOne(User::class, ['id' => 'user_id']); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Get types |
|
64
|
|
|
* |
|
65
|
|
|
* @return array |
|
66
|
|
|
*/ |
|
67
|
|
|
public static function getTypes(): array |
|
68
|
|
|
{ |
|
69
|
|
|
return [ |
|
70
|
|
|
self::TYPE_TWITTER => 'twitter', |
|
71
|
|
|
self::TYPE_FACEBOOK => 'facebook', |
|
72
|
|
|
self::TYPE_VKONTAKTE => 'vkontakte', |
|
73
|
|
|
]; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Get type by id |
|
78
|
|
|
* |
|
79
|
|
|
* @return string $name |
|
80
|
|
|
* @return int |
|
81
|
|
|
*/ |
|
82
|
|
|
public static function getTypeByName(string $name): int |
|
83
|
|
|
{ |
|
84
|
|
|
$types = array_flip(self::getTypes()); |
|
85
|
|
|
return isset($types[$name]) ? $types[$name] : false; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Get type name |
|
90
|
|
|
* |
|
91
|
|
|
* @return string |
|
92
|
|
|
*/ |
|
93
|
|
|
public function getTypeName(): string |
|
94
|
|
|
{ |
|
95
|
|
|
$types = self::getTypes(); |
|
96
|
|
|
return isset($types[$this->type]) ? $types[$this->type] : false; |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|