Commit 8195fc24005c73b97f21ea1eaa89d50a6ab865d8
1 parent
61f6789b
Models
Showing
7 changed files
with
597 additions
and
186 deletions
Show diff stats
common/models/User.php
1 | 1 | <?php |
2 | -namespace common\models; | |
3 | - | |
4 | -use Yii; | |
5 | -use yii\base\NotSupportedException; | |
6 | -use yii\behaviors\TimestampBehavior; | |
7 | -use yii\db\ActiveRecord; | |
8 | -use yii\web\IdentityInterface; | |
9 | - | |
10 | -/** | |
11 | - * User model | |
12 | - * | |
13 | - * @property integer $id | |
14 | - * @property string $username | |
15 | - * @property string $password_hash | |
16 | - * @property string $password_reset_token | |
17 | - * @property string $email | |
18 | - * @property string $auth_key | |
19 | - * @property integer $status | |
20 | - * @property integer $created_at | |
21 | - * @property integer $updated_at | |
22 | - * @property string $password write-only password | |
23 | - */ | |
24 | -class User extends ActiveRecord implements IdentityInterface | |
25 | -{ | |
26 | - const STATUS_DELETED = 0; | |
27 | - const STATUS_ACTIVE = 10; | |
28 | - | |
29 | - | |
30 | - /** | |
31 | - * @inheritdoc | |
32 | - */ | |
33 | - public static function tableName() | |
34 | - { | |
35 | - return '{{%user}}'; | |
36 | - } | |
37 | - | |
38 | - /** | |
39 | - * @inheritdoc | |
40 | - */ | |
41 | - public function behaviors() | |
42 | - { | |
43 | - return [ | |
44 | - TimestampBehavior::className(), | |
45 | - ]; | |
46 | - } | |
47 | - | |
48 | - /** | |
49 | - * @inheritdoc | |
50 | - */ | |
51 | - public function rules() | |
52 | - { | |
53 | - return [ | |
54 | - ['status', 'default', 'value' => self::STATUS_ACTIVE], | |
55 | - ['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED]], | |
56 | - ]; | |
57 | - } | |
58 | - | |
59 | - /** | |
60 | - * @inheritdoc | |
61 | - */ | |
62 | - public static function findIdentity($id) | |
63 | - { | |
64 | - return static::findOne(['id' => $id, 'status' => self::STATUS_ACTIVE]); | |
65 | - } | |
66 | - | |
67 | - /** | |
68 | - * @inheritdoc | |
69 | - */ | |
70 | - public static function findIdentityByAccessToken($token, $type = null) | |
71 | - { | |
72 | - throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.'); | |
73 | - } | |
74 | - | |
75 | - /** | |
76 | - * Finds user by username | |
2 | + namespace common\models; | |
3 | + | |
4 | + use frontend\models\UserData; | |
5 | + use frontend\models\UserPassport; | |
6 | + use Yii; | |
7 | + use yii\base\NotSupportedException; | |
8 | + use yii\behaviors\TimestampBehavior; | |
9 | + use yii\db\ActiveRecord; | |
10 | + use yii\web\IdentityInterface; | |
11 | + | |
12 | + /** | |
13 | + * User model | |
77 | 14 | * |
78 | - * @param string $username | |
79 | - * @return static|null | |
80 | - */ | |
81 | - public static function findByUsername($username) | |
82 | - { | |
83 | - return static::findOne(['username' => $username, 'status' => self::STATUS_ACTIVE]); | |
84 | - } | |
85 | - | |
86 | - /** | |
87 | - * Finds user by password reset token | |
88 | - * | |
89 | - * @param string $token password reset token | |
90 | - * @return static|null | |
91 | - */ | |
92 | - public static function findByPasswordResetToken($token) | |
93 | - { | |
94 | - if (!static::isPasswordResetTokenValid($token)) { | |
95 | - return null; | |
96 | - } | |
97 | - | |
98 | - return static::findOne([ | |
99 | - 'password_reset_token' => $token, | |
100 | - 'status' => self::STATUS_ACTIVE, | |
101 | - ]); | |
102 | - } | |
103 | - | |
104 | - /** | |
105 | - * Finds out if password reset token is valid | |
106 | - * | |
107 | - * @param string $token password reset token | |
108 | - * @return bool | |
109 | - */ | |
110 | - public static function isPasswordResetTokenValid($token) | |
111 | - { | |
112 | - if (empty($token)) { | |
113 | - return false; | |
15 | + * @property integer $id | |
16 | + * @property string $username | |
17 | + * @property string $password_hash | |
18 | + * @property string $password_reset_token | |
19 | + * @property string $email | |
20 | + * @property string $auth_key | |
21 | + * @property integer $status | |
22 | + * @property integer $created_at | |
23 | + * @property integer $updated_at | |
24 | + * @property string $password write-only password | |
25 | + * @property UserData $userData | |
26 | + * @property UserPassport $userPassport | |
27 | + */ | |
28 | + class User extends ActiveRecord implements IdentityInterface | |
29 | + { | |
30 | + const STATUS_DELETED = 0; | |
31 | + const STATUS_ACTIVE = 10; | |
32 | + | |
33 | + /** | |
34 | + * @inheritdoc | |
35 | + */ | |
36 | + public static function tableName() | |
37 | + { | |
38 | + return '{{%user}}'; | |
39 | + } | |
40 | + | |
41 | + /** | |
42 | + * @inheritdoc | |
43 | + */ | |
44 | + public function behaviors() | |
45 | + { | |
46 | + return [ | |
47 | + TimestampBehavior::className(), | |
48 | + ]; | |
49 | + } | |
50 | + | |
51 | + /** | |
52 | + * @inheritdoc | |
53 | + */ | |
54 | + public function rules() | |
55 | + { | |
56 | + return [ | |
57 | + [ | |
58 | + 'status', | |
59 | + 'default', | |
60 | + 'value' => self::STATUS_ACTIVE, | |
61 | + ], | |
62 | + [ | |
63 | + 'status', | |
64 | + 'in', | |
65 | + 'range' => [ | |
66 | + self::STATUS_ACTIVE, | |
67 | + self::STATUS_DELETED, | |
68 | + ], | |
69 | + ], | |
70 | + ]; | |
71 | + } | |
72 | + | |
73 | + /** | |
74 | + * @inheritdoc | |
75 | + */ | |
76 | + public static function findIdentity($id) | |
77 | + { | |
78 | + return static::findOne( | |
79 | + [ | |
80 | + 'id' => $id, | |
81 | + 'status' => self::STATUS_ACTIVE, | |
82 | + ] | |
83 | + ); | |
84 | + } | |
85 | + | |
86 | + /** | |
87 | + * @inheritdoc | |
88 | + */ | |
89 | + public static function findIdentityByAccessToken($token, $type = null) | |
90 | + { | |
91 | + throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.'); | |
92 | + } | |
93 | + | |
94 | + /** | |
95 | + * Finds user by username | |
96 | + * | |
97 | + * @param string $username | |
98 | + * | |
99 | + * @return static|null | |
100 | + */ | |
101 | + public static function findByUsername($username) | |
102 | + { | |
103 | + return static::findOne( | |
104 | + [ | |
105 | + 'username' => $username, | |
106 | + 'status' => self::STATUS_ACTIVE, | |
107 | + ] | |
108 | + ); | |
109 | + } | |
110 | + | |
111 | + /** | |
112 | + * Finds user by password reset token | |
113 | + * | |
114 | + * @param string $token password reset token | |
115 | + * | |
116 | + * @return static|null | |
117 | + */ | |
118 | + public static function findByPasswordResetToken($token) | |
119 | + { | |
120 | + if (!static::isPasswordResetTokenValid($token)) { | |
121 | + return null; | |
122 | + } | |
123 | + | |
124 | + return static::findOne( | |
125 | + [ | |
126 | + 'password_reset_token' => $token, | |
127 | + 'status' => self::STATUS_ACTIVE, | |
128 | + ] | |
129 | + ); | |
130 | + } | |
131 | + | |
132 | + /** | |
133 | + * Finds out if password reset token is valid | |
134 | + * | |
135 | + * @param string $token password reset token | |
136 | + * | |
137 | + * @return bool | |
138 | + */ | |
139 | + public static function isPasswordResetTokenValid($token) | |
140 | + { | |
141 | + if (empty( $token )) { | |
142 | + return false; | |
143 | + } | |
144 | + | |
145 | + $timestamp = (int) substr($token, strrpos($token, '_') + 1); | |
146 | + $expire = Yii::$app->params[ 'user.passwordResetTokenExpire' ]; | |
147 | + return $timestamp + $expire >= time(); | |
148 | + } | |
149 | + | |
150 | + /** | |
151 | + * @inheritdoc | |
152 | + */ | |
153 | + public function getId() | |
154 | + { | |
155 | + return $this->getPrimaryKey(); | |
156 | + } | |
157 | + | |
158 | + /** | |
159 | + * @inheritdoc | |
160 | + */ | |
161 | + public function getAuthKey() | |
162 | + { | |
163 | + return $this->auth_key; | |
164 | + } | |
165 | + | |
166 | + /** | |
167 | + * @inheritdoc | |
168 | + */ | |
169 | + public function validateAuthKey($authKey) | |
170 | + { | |
171 | + return $this->getAuthKey() === $authKey; | |
172 | + } | |
173 | + | |
174 | + /** | |
175 | + * Validates password | |
176 | + * | |
177 | + * @param string $password password to validate | |
178 | + * | |
179 | + * @return bool if password provided is valid for current user | |
180 | + */ | |
181 | + public function validatePassword($password) | |
182 | + { | |
183 | + return Yii::$app->security->validatePassword($password, $this->password_hash); | |
184 | + } | |
185 | + | |
186 | + /** | |
187 | + * Generates password hash from password and sets it to the model | |
188 | + * | |
189 | + * @param string $password | |
190 | + */ | |
191 | + public function setPassword($password) | |
192 | + { | |
193 | + $this->password_hash = Yii::$app->security->generatePasswordHash($password); | |
194 | + } | |
195 | + | |
196 | + /** | |
197 | + * Generates "remember me" authentication key | |
198 | + */ | |
199 | + public function generateAuthKey() | |
200 | + { | |
201 | + $this->auth_key = Yii::$app->security->generateRandomString(); | |
202 | + } | |
203 | + | |
204 | + /** | |
205 | + * Generates new password reset token | |
206 | + */ | |
207 | + public function generatePasswordResetToken() | |
208 | + { | |
209 | + $this->password_reset_token = Yii::$app->security->generateRandomString() . '_' . time(); | |
210 | + } | |
211 | + | |
212 | + /** | |
213 | + * Removes password reset token | |
214 | + */ | |
215 | + public function removePasswordResetToken() | |
216 | + { | |
217 | + $this->password_reset_token = null; | |
218 | + } | |
219 | + | |
220 | + public function getUserData() | |
221 | + { | |
222 | + return $this->hasOne(UserData::className(), [ 'user_id' => 'id' ]); | |
223 | + } | |
224 | + | |
225 | + public function getUserPassport() | |
226 | + { | |
227 | + return $this->hasOne(UserPassport::className(), [ 'user_id' => 'id' ]); | |
114 | 228 | } |
115 | - | |
116 | - $timestamp = (int) substr($token, strrpos($token, '_') + 1); | |
117 | - $expire = Yii::$app->params['user.passwordResetTokenExpire']; | |
118 | - return $timestamp + $expire >= time(); | |
119 | - } | |
120 | - | |
121 | - /** | |
122 | - * @inheritdoc | |
123 | - */ | |
124 | - public function getId() | |
125 | - { | |
126 | - return $this->getPrimaryKey(); | |
127 | - } | |
128 | - | |
129 | - /** | |
130 | - * @inheritdoc | |
131 | - */ | |
132 | - public function getAuthKey() | |
133 | - { | |
134 | - return $this->auth_key; | |
135 | - } | |
136 | - | |
137 | - /** | |
138 | - * @inheritdoc | |
139 | - */ | |
140 | - public function validateAuthKey($authKey) | |
141 | - { | |
142 | - return $this->getAuthKey() === $authKey; | |
143 | - } | |
144 | - | |
145 | - /** | |
146 | - * Validates password | |
147 | - * | |
148 | - * @param string $password password to validate | |
149 | - * @return bool if password provided is valid for current user | |
150 | - */ | |
151 | - public function validatePassword($password) | |
152 | - { | |
153 | - return Yii::$app->security->validatePassword($password, $this->password_hash); | |
154 | - } | |
155 | - | |
156 | - /** | |
157 | - * Generates password hash from password and sets it to the model | |
158 | - * | |
159 | - * @param string $password | |
160 | - */ | |
161 | - public function setPassword($password) | |
162 | - { | |
163 | - $this->password_hash = Yii::$app->security->generatePasswordHash($password); | |
164 | - } | |
165 | - | |
166 | - /** | |
167 | - * Generates "remember me" authentication key | |
168 | - */ | |
169 | - public function generateAuthKey() | |
170 | - { | |
171 | - $this->auth_key = Yii::$app->security->generateRandomString(); | |
172 | - } | |
173 | - | |
174 | - /** | |
175 | - * Generates new password reset token | |
176 | - */ | |
177 | - public function generatePasswordResetToken() | |
178 | - { | |
179 | - $this->password_reset_token = Yii::$app->security->generateRandomString() . '_' . time(); | |
180 | - } | |
181 | - | |
182 | - /** | |
183 | - * Removes password reset token | |
184 | - */ | |
185 | - public function removePasswordResetToken() | |
186 | - { | |
187 | - $this->password_reset_token = null; | |
188 | 229 | } |
189 | -} | ... | ... |
frontend/controllers/CabinetController.php
1 | 1 | <?php |
2 | 2 | namespace frontend\controllers; |
3 | 3 | |
4 | + use common\models\User; | |
5 | + use frontend\models\UserData; | |
6 | + use frontend\models\UserPassport; | |
4 | 7 | use yii\web\Controller; |
5 | 8 | |
6 | 9 | /** |
... | ... | @@ -24,7 +27,21 @@ |
24 | 27 | */ |
25 | 28 | public function actionIndex() |
26 | 29 | { |
27 | - return $this->render('index'); | |
30 | + \Yii::$app->user->login(User::findOne(1)); | |
31 | + /** | |
32 | + * @var User $user | |
33 | + */ | |
34 | + $user = \Yii::$app->user->identity; | |
35 | + if(!$userData = $user->userData) { | |
36 | + $userData = new UserData(); | |
37 | + } | |
38 | + if(!$userPassport = $user->userPassport) { | |
39 | + $userPassport = new UserPassport(); | |
40 | + } | |
41 | + return $this->render('index', [ | |
42 | + 'userData' => $userData, | |
43 | + 'userPassport' => $userPassport, | |
44 | + ]); | |
28 | 45 | } |
29 | 46 | |
30 | 47 | } | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace frontend\models; | |
4 | + | |
5 | +/** | |
6 | + * This is the model class for table "creative_role". | |
7 | + * | |
8 | + * @property integer $id | |
9 | + * @property integer $intellectual_property_id | |
10 | + * @property string $title | |
11 | + * @property string $name | |
12 | + * @property double $part | |
13 | + * @property string $code | |
14 | + * @property string $iri | |
15 | + * @property string $society | |
16 | + * | |
17 | + * @property IntellectualProperty $intellectualProperty | |
18 | + */ | |
19 | +class CreativeRole extends \yii\db\ActiveRecord | |
20 | +{ | |
21 | + /** | |
22 | + * @inheritdoc | |
23 | + */ | |
24 | + public static function tableName() | |
25 | + { | |
26 | + return 'creative_role'; | |
27 | + } | |
28 | + | |
29 | + /** | |
30 | + * @inheritdoc | |
31 | + */ | |
32 | + public function rules() | |
33 | + { | |
34 | + return [ | |
35 | + [['intellectual_property_id'], 'integer'], | |
36 | + [['part'], 'number'], | |
37 | + [['title', 'name', 'code', 'iri', 'society'], 'string', 'max' => 255], | |
38 | + [['intellectual_property_id'], 'exist', 'skipOnError' => true, 'targetClass' => IntellectualProperty::className(), 'targetAttribute' => ['intellectual_property_id' => 'id']], | |
39 | + ]; | |
40 | + } | |
41 | + | |
42 | + /** | |
43 | + * @inheritdoc | |
44 | + */ | |
45 | + public function attributeLabels() | |
46 | + { | |
47 | + return [ | |
48 | + 'id' => 'ID', | |
49 | + 'intellectual_property_id' => 'Intellectual Property ID', | |
50 | + 'title' => 'Title', | |
51 | + 'name' => 'Name', | |
52 | + 'part' => 'Part', | |
53 | + 'code' => 'Code', | |
54 | + 'iri' => 'Iri', | |
55 | + 'society' => 'Society', | |
56 | + ]; | |
57 | + } | |
58 | + | |
59 | + /** | |
60 | + * @return \yii\db\ActiveQuery | |
61 | + */ | |
62 | + public function getIntellectualProperty() | |
63 | + { | |
64 | + return $this->hasOne(IntellectualProperty::className(), ['id' => 'intellectual_property_id']); | |
65 | + } | |
66 | +} | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace frontend\models; | |
4 | + | |
5 | +use common\models\User; | |
6 | + | |
7 | +/** | |
8 | + * This is the model class for table "intellectual_property". | |
9 | + * | |
10 | + * @property integer $id | |
11 | + * @property integer $user_id | |
12 | + * @property string $title | |
13 | + * @property integer $creation_date | |
14 | + * @property string $code | |
15 | + * @property string $genre | |
16 | + * @property integer $registration_date | |
17 | + * @property string $contract | |
18 | + * @property string $type | |
19 | + * | |
20 | + * @property CreativeRole[] $creativeRoles | |
21 | + * @property User $user | |
22 | + * @property Report[] $reports | |
23 | + */ | |
24 | +class IntellectualProperty extends \yii\db\ActiveRecord | |
25 | +{ | |
26 | + /** | |
27 | + * @inheritdoc | |
28 | + */ | |
29 | + public static function tableName() | |
30 | + { | |
31 | + return 'intellectual_property'; | |
32 | + } | |
33 | + | |
34 | + /** | |
35 | + * @inheritdoc | |
36 | + */ | |
37 | + public function rules() | |
38 | + { | |
39 | + return [ | |
40 | + [['user_id', 'creation_date', 'registration_date'], 'integer'], | |
41 | + [['title', 'code', 'genre', 'contract', 'type'], 'string', 'max' => 255], | |
42 | + [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']], | |
43 | + ]; | |
44 | + } | |
45 | + | |
46 | + /** | |
47 | + * @inheritdoc | |
48 | + */ | |
49 | + public function attributeLabels() | |
50 | + { | |
51 | + return [ | |
52 | + 'id' => 'ID', | |
53 | + 'user_id' => 'User ID', | |
54 | + 'title' => 'Title', | |
55 | + 'creation_date' => 'Creation Date', | |
56 | + 'code' => 'Code', | |
57 | + 'genre' => 'Genre', | |
58 | + 'registration_date' => 'Registration Date', | |
59 | + 'contract' => 'Contract', | |
60 | + 'type' => 'Type', | |
61 | + ]; | |
62 | + } | |
63 | + | |
64 | + /** | |
65 | + * @return \yii\db\ActiveQuery | |
66 | + */ | |
67 | + public function getCreativeRoles() | |
68 | + { | |
69 | + return $this->hasMany(CreativeRole::className(), ['intellectual_property_id' => 'id']); | |
70 | + } | |
71 | + | |
72 | + /** | |
73 | + * @return \yii\db\ActiveQuery | |
74 | + */ | |
75 | + public function getUser() | |
76 | + { | |
77 | + return $this->hasOne(User::className(), ['id' => 'user_id']); | |
78 | + } | |
79 | + | |
80 | + /** | |
81 | + * @return \yii\db\ActiveQuery | |
82 | + */ | |
83 | + public function getReports() | |
84 | + { | |
85 | + return $this->hasMany(Report::className(), ['intellectual_property_id' => 'id']); | |
86 | + } | |
87 | +} | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace frontend\models; | |
4 | + | |
5 | +/** | |
6 | + * This is the model class for table "report". | |
7 | + * | |
8 | + * @property integer $id | |
9 | + * @property integer $intellectual_property_id | |
10 | + * @property string $title | |
11 | + * @property string $artist | |
12 | + * @property string $music_author | |
13 | + * @property string $text_author | |
14 | + * @property integer $time | |
15 | + * @property integer $total_time | |
16 | + * @property double $royalty | |
17 | + * @property integer $count | |
18 | + * | |
19 | + * @property IntellectualProperty $intellectualProperty | |
20 | + */ | |
21 | +class Report extends \yii\db\ActiveRecord | |
22 | +{ | |
23 | + /** | |
24 | + * @inheritdoc | |
25 | + */ | |
26 | + public static function tableName() | |
27 | + { | |
28 | + return 'report'; | |
29 | + } | |
30 | + | |
31 | + /** | |
32 | + * @inheritdoc | |
33 | + */ | |
34 | + public function rules() | |
35 | + { | |
36 | + return [ | |
37 | + [['intellectual_property_id', 'time', 'total_time', 'count'], 'integer'], | |
38 | + [['royalty'], 'number'], | |
39 | + [['title', 'artist', 'music_author', 'text_author'], 'string', 'max' => 255], | |
40 | + [['intellectual_property_id'], 'exist', 'skipOnError' => true, 'targetClass' => IntellectualProperty::className(), 'targetAttribute' => ['intellectual_property_id' => 'id']], | |
41 | + ]; | |
42 | + } | |
43 | + | |
44 | + /** | |
45 | + * @inheritdoc | |
46 | + */ | |
47 | + public function attributeLabels() | |
48 | + { | |
49 | + return [ | |
50 | + 'id' => 'ID', | |
51 | + 'intellectual_property_id' => 'Intellectual Property ID', | |
52 | + 'title' => 'Title', | |
53 | + 'artist' => 'Artist', | |
54 | + 'music_author' => 'Music Author', | |
55 | + 'text_author' => 'Text Author', | |
56 | + 'time' => 'Time', | |
57 | + 'total_time' => 'Total Time', | |
58 | + 'royalty' => 'Royalty', | |
59 | + 'count' => 'Count', | |
60 | + ]; | |
61 | + } | |
62 | + | |
63 | + /** | |
64 | + * @return \yii\db\ActiveQuery | |
65 | + */ | |
66 | + public function getIntellectualProperty() | |
67 | + { | |
68 | + return $this->hasOne(IntellectualProperty::className(), ['id' => 'intellectual_property_id']); | |
69 | + } | |
70 | +} | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace frontend\models; | |
4 | + | |
5 | +use common\models\User; | |
6 | + | |
7 | +/** | |
8 | + * This is the model class for table "user_data". | |
9 | + * | |
10 | + * @property integer $id | |
11 | + * @property integer $user_id | |
12 | + * @property string $name | |
13 | + * @property string $surname | |
14 | + * @property string $patronymic | |
15 | + * @property string $phone | |
16 | + * @property string $email | |
17 | + * @property string $inn | |
18 | + * | |
19 | + * @property User $user | |
20 | + */ | |
21 | +class UserData extends \yii\db\ActiveRecord | |
22 | +{ | |
23 | + /** | |
24 | + * @inheritdoc | |
25 | + */ | |
26 | + public static function tableName() | |
27 | + { | |
28 | + return 'user_data'; | |
29 | + } | |
30 | + | |
31 | + /** | |
32 | + * @inheritdoc | |
33 | + */ | |
34 | + public function rules() | |
35 | + { | |
36 | + return [ | |
37 | + [['user_id'], 'integer'], | |
38 | + [['name', 'surname', 'patronymic', 'phone', 'email', 'inn'], 'string', 'max' => 255], | |
39 | + [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']], | |
40 | + ]; | |
41 | + } | |
42 | + | |
43 | + /** | |
44 | + * @inheritdoc | |
45 | + */ | |
46 | + public function attributeLabels() | |
47 | + { | |
48 | + return [ | |
49 | + 'id' => 'ID', | |
50 | + 'user_id' => 'User ID', | |
51 | + 'name' => 'Name', | |
52 | + 'surname' => 'Surname', | |
53 | + 'patronymic' => 'Patronymic', | |
54 | + 'phone' => 'Phone', | |
55 | + 'email' => 'Email', | |
56 | + 'inn' => 'Inn', | |
57 | + ]; | |
58 | + } | |
59 | + | |
60 | + /** | |
61 | + * @return \yii\db\ActiveQuery | |
62 | + */ | |
63 | + public function getUser() | |
64 | + { | |
65 | + return $this->hasOne(User::className(), ['id' => 'user_id']); | |
66 | + } | |
67 | +} | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace frontend\models; | |
4 | + | |
5 | +use common\models\User; | |
6 | + | |
7 | +/** | |
8 | + * This is the model class for table "user_passport". | |
9 | + * | |
10 | + * @property integer $id | |
11 | + * @property integer $user_id | |
12 | + * @property string $series | |
13 | + * @property string $number | |
14 | + * @property string $birthday | |
15 | + * @property string $given_by | |
16 | + * | |
17 | + * @property User $user | |
18 | + */ | |
19 | +class UserPassport extends \yii\db\ActiveRecord | |
20 | +{ | |
21 | + /** | |
22 | + * @inheritdoc | |
23 | + */ | |
24 | + public static function tableName() | |
25 | + { | |
26 | + return 'user_passport'; | |
27 | + } | |
28 | + | |
29 | + /** | |
30 | + * @inheritdoc | |
31 | + */ | |
32 | + public function rules() | |
33 | + { | |
34 | + return [ | |
35 | + [['user_id'], 'integer'], | |
36 | + [['given_by'], 'string'], | |
37 | + [['series', 'number', 'birthday'], 'string', 'max' => 255], | |
38 | + [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']], | |
39 | + ]; | |
40 | + } | |
41 | + | |
42 | + /** | |
43 | + * @inheritdoc | |
44 | + */ | |
45 | + public function attributeLabels() | |
46 | + { | |
47 | + return [ | |
48 | + 'id' => 'ID', | |
49 | + 'user_id' => 'User ID', | |
50 | + 'series' => 'Series', | |
51 | + 'number' => 'Number', | |
52 | + 'birthday' => 'Birthday', | |
53 | + 'given_by' => 'Given By', | |
54 | + ]; | |
55 | + } | |
56 | + | |
57 | + /** | |
58 | + * @return \yii\db\ActiveQuery | |
59 | + */ | |
60 | + public function getUser() | |
61 | + { | |
62 | + return $this->hasOne(User::className(), ['id' => 'user_id']); | |
63 | + } | |
64 | +} | ... | ... |