Commit 3dc20ff72c14cc17bfc757929acd8f854345360d
1 parent
5a6471b3
24.02.16
Showing
8 changed files
with
78 additions
and
29 deletions
Show diff stats
common/models/CompanyInfo.php
common/models/Project.php
| @@ -177,7 +177,7 @@ | @@ -177,7 +177,7 @@ | ||
| 177 | /** | 177 | /** |
| 178 | * @return \yii\db\ActiveQuery | 178 | * @return \yii\db\ActiveQuery |
| 179 | */ | 179 | */ |
| 180 | - public function getOwner() | 180 | + public function getUser() |
| 181 | { | 181 | { |
| 182 | return $this->hasOne(User::className(), [ 'id' => 'user_id' ]); | 182 | return $this->hasOne(User::className(), [ 'id' => 'user_id' ]); |
| 183 | } | 183 | } |
common/models/User.php
| @@ -23,6 +23,7 @@ | @@ -23,6 +23,7 @@ | ||
| 23 | * @property integer $created_at | 23 | * @property integer $created_at |
| 24 | * @property integer $updated_at | 24 | * @property integer $updated_at |
| 25 | * @property string $password write-only password | 25 | * @property string $password write-only password |
| 26 | + * @property string $type | ||
| 26 | */ | 27 | */ |
| 27 | class User extends ActiveRecord implements IdentityInterface, UserRbacInterface | 28 | class User extends ActiveRecord implements IdentityInterface, UserRbacInterface |
| 28 | { | 29 | { |
| @@ -56,6 +57,9 @@ | @@ -56,6 +57,9 @@ | ||
| 56 | ]; | 57 | ]; |
| 57 | } | 58 | } |
| 58 | 59 | ||
| 60 | + | ||
| 61 | + | ||
| 62 | + | ||
| 59 | /** | 63 | /** |
| 60 | * @inheritdoc | 64 | * @inheritdoc |
| 61 | */ | 65 | */ |
| @@ -86,22 +90,10 @@ | @@ -86,22 +90,10 @@ | ||
| 86 | 'max' => 255, | 90 | 'max' => 255, |
| 87 | ], | 91 | ], |
| 88 | [ | 92 | [ |
| 89 | - [ 'type' ], | ||
| 90 | - 'in', | ||
| 91 | - 'range' => [ | ||
| 92 | - 1, | ||
| 93 | - 2, | ||
| 94 | - ], | ||
| 95 | - ], | ||
| 96 | - [ | ||
| 97 | - [ 'type' ], | ||
| 98 | - 'default', | ||
| 99 | - 'value' => '1', | ||
| 100 | - ], | ||
| 101 | - [ | ||
| 102 | [ | 93 | [ |
| 103 | 'specializationInput', | 94 | 'specializationInput', |
| 104 | 'paymentInput', | 95 | 'paymentInput', |
| 96 | + 'type' | ||
| 105 | ], | 97 | ], |
| 106 | 'safe', | 98 | 'safe', |
| 107 | ], | 99 | ], |
| @@ -554,4 +546,19 @@ | @@ -554,4 +546,19 @@ | ||
| 554 | return $this->hasMany(Gallery::className(), [ 'user_id' => 'id' ]); | 546 | return $this->hasMany(Gallery::className(), [ 'user_id' => 'id' ]); |
| 555 | } | 547 | } |
| 556 | 548 | ||
| 549 | + public function getOwner() | ||
| 550 | + { | ||
| 551 | + if($this->type == 1){ | ||
| 552 | + return $this->hasOne(UserInfo::className(), [ 'user_id' => 'id' ]); | ||
| 553 | + } else if($this->type == 2) { | ||
| 554 | + return $this->hasOne(CompanyInfo::className(), [ 'user_id' => 'id' ]); | ||
| 555 | + } | ||
| 556 | + | ||
| 557 | + } | ||
| 558 | + | ||
| 559 | + public function getName(){ | ||
| 560 | + return $this->firstname. ' '.$this->lastname; | ||
| 561 | + } | ||
| 562 | + | ||
| 563 | + | ||
| 557 | } | 564 | } |
common/models/UserInfo.php
| @@ -266,6 +266,10 @@ | @@ -266,6 +266,10 @@ | ||
| 266 | return parent::beforeSave($insert); | 266 | return parent::beforeSave($insert); |
| 267 | } | 267 | } |
| 268 | 268 | ||
| 269 | + public function getName(){ | ||
| 270 | + return $this->user->name(); | ||
| 271 | + } | ||
| 272 | + | ||
| 269 | public function getGeographies() | 273 | public function getGeographies() |
| 270 | { | 274 | { |
| 271 | return json_decode($this->geography); | 275 | return json_decode($this->geography); |
frontend/controllers/SiteController.php
| @@ -246,35 +246,51 @@ class SiteController extends Controller | @@ -246,35 +246,51 @@ class SiteController extends Controller | ||
| 246 | public function actionRegistration() | 246 | public function actionRegistration() |
| 247 | { | 247 | { |
| 248 | 248 | ||
| 249 | - $model = new SignupForm(); | 249 | + $post = Yii::$app->request->post(); |
| 250 | + | ||
| 251 | + if(!empty($post) && isset($post['SignupForm']) && isset($post['SignupForm']['type'])){ | ||
| 252 | + if($post['SignupForm']['type'] == 1 ){ | ||
| 253 | + | ||
| 254 | + $model = new SignupForm(['scenario' => SignupForm::SCENARIO_USER]); | ||
| 255 | + } else { | ||
| 256 | + | ||
| 257 | + $model = new SignupForm(['scenario' => SignupForm::SCENARIO_COMPANY]); | ||
| 258 | + } | ||
| 259 | + } else { | ||
| 260 | + $model = new SignupForm(); | ||
| 261 | + } | ||
| 262 | + | ||
| 250 | if ($model->load(Yii::$app->request->post())) { | 263 | if ($model->load(Yii::$app->request->post())) { |
| 251 | 264 | ||
| 265 | + | ||
| 252 | if ($user = $model->signup()) { | 266 | if ($user = $model->signup()) { |
| 253 | 267 | ||
| 268 | + | ||
| 269 | + | ||
| 254 | $user_info = new UserInfo(); | 270 | $user_info = new UserInfo(); |
| 255 | 271 | ||
| 256 | $user_info->load(Yii::$app->request->post(),'SignupForm'); | 272 | $user_info->load(Yii::$app->request->post(),'SignupForm'); |
| 257 | 273 | ||
| 258 | $user_info->user_id = $user->id; | 274 | $user_info->user_id = $user->id; |
| 259 | 275 | ||
| 260 | - | ||
| 261 | $user_info->save(); | 276 | $user_info->save(); |
| 262 | 277 | ||
| 263 | if($user->type == 2 ){ | 278 | if($user->type == 2 ){ |
| 264 | 279 | ||
| 265 | $company_info = new CompanyInfo(); | 280 | $company_info = new CompanyInfo(); |
| 266 | $company_info->load(Yii::$app->request->post(),'SignupForm'); | 281 | $company_info->load(Yii::$app->request->post(),'SignupForm'); |
| 267 | - $company_info->name = $user->id; | 282 | + $company_info->user_id = $user->id; |
| 268 | 283 | ||
| 269 | $company_info->save(); | 284 | $company_info->save(); |
| 285 | + | ||
| 270 | } | 286 | } |
| 271 | 287 | ||
| 272 | if (Yii::$app->getUser()->login($user)) { | 288 | if (Yii::$app->getUser()->login($user)) { |
| 273 | - return $this->goHome(); | 289 | + return $this->redirect('/accounts'); |
| 274 | } | 290 | } |
| 275 | } | 291 | } |
| 276 | } | 292 | } |
| 277 | - | 293 | + $model = new SignupForm(); |
| 278 | return $this->render('registration', [ | 294 | return $this->render('registration', [ |
| 279 | 'model' => $model, | 295 | 'model' => $model, |
| 280 | ]); | 296 | ]); |
frontend/models/SignupForm.php
| @@ -23,6 +23,11 @@ class SignupForm extends Model | @@ -23,6 +23,11 @@ class SignupForm extends Model | ||
| 23 | public $city; | 23 | public $city; |
| 24 | public $name; | 24 | public $name; |
| 25 | 25 | ||
| 26 | + | ||
| 27 | + | ||
| 28 | + const SCENARIO_USER = 'user'; | ||
| 29 | + const SCENARIO_COMPANY = 'company'; | ||
| 30 | + | ||
| 26 | /** | 31 | /** |
| 27 | * @inheritdoc | 32 | * @inheritdoc |
| 28 | */ | 33 | */ |
| @@ -41,8 +46,6 @@ class SignupForm extends Model | @@ -41,8 +46,6 @@ class SignupForm extends Model | ||
| 41 | ['email', 'email'], | 46 | ['email', 'email'], |
| 42 | ['email', 'string', 'max' => 255], | 47 | ['email', 'string', 'max' => 255], |
| 43 | ['email', 'unique', 'targetClass' => '\common\models\User', 'message' => 'This email address has already been taken.'], | 48 | ['email', 'unique', 'targetClass' => '\common\models\User', 'message' => 'This email address has already been taken.'], |
| 44 | - | ||
| 45 | - ['name', 'required'], | ||
| 46 | ['firstname', 'required'], | 49 | ['firstname', 'required'], |
| 47 | 50 | ||
| 48 | 51 | ||
| @@ -54,6 +57,21 @@ class SignupForm extends Model | @@ -54,6 +57,21 @@ class SignupForm extends Model | ||
| 54 | 57 | ||
| 55 | ['password', 'required'], | 58 | ['password', 'required'], |
| 56 | ['password', 'string', 'min' => 6], | 59 | ['password', 'string', 'min' => 6], |
| 60 | + [ | ||
| 61 | + 'name', | ||
| 62 | + 'required', | ||
| 63 | + 'on'=>[SignupForm::SCENARIO_COMPANY] | ||
| 64 | + ], | ||
| 65 | + [ | ||
| 66 | + 'name', | ||
| 67 | + 'safe', | ||
| 68 | + 'on'=>[SignupForm::SCENARIO_USER] | ||
| 69 | + ], | ||
| 70 | + [ | ||
| 71 | + 'name', | ||
| 72 | + 'required', | ||
| 73 | + 'on'=>[SignupForm::SCENARIO_DEFAULT] | ||
| 74 | + ], | ||
| 57 | ]; | 75 | ]; |
| 58 | } | 76 | } |
| 59 | 77 | ||
| @@ -71,6 +89,7 @@ class SignupForm extends Model | @@ -71,6 +89,7 @@ class SignupForm extends Model | ||
| 71 | $user->firstname = $this->firstname; | 89 | $user->firstname = $this->firstname; |
| 72 | $user->lastname = $this->lastname; | 90 | $user->lastname = $this->lastname; |
| 73 | $user->email = $this->email; | 91 | $user->email = $this->email; |
| 92 | + $user->type = $this->type; | ||
| 74 | $user->setPassword($this->password); | 93 | $user->setPassword($this->password); |
| 75 | $user->generateAuthKey(); | 94 | $user->generateAuthKey(); |
| 76 | 95 |
frontend/views/site/registration.php
| @@ -85,7 +85,7 @@ | @@ -85,7 +85,7 @@ | ||
| 85 | ], false); ?> | 85 | ], false); ?> |
| 86 | </div> | 86 | </div> |
| 87 | 87 | ||
| 88 | - | 88 | + <div id="register-company-block-target"></div> |
| 89 | <div class="input-blocks-wrapper register-company-block"> | 89 | <div class="input-blocks-wrapper register-company-block"> |
| 90 | <div class="input-blocks"> | 90 | <div class="input-blocks"> |
| 91 | <?= $form->field($model, 'name')->textInput(['class'=>'custom-input-2'])?> | 91 | <?= $form->field($model, 'name')->textInput(['class'=>'custom-input-2'])?> |
| @@ -171,15 +171,20 @@ | @@ -171,15 +171,20 @@ | ||
| 171 | var registerValCompany = $('.register-val-company .custom-radio:checked').attr('value'); | 171 | var registerValCompany = $('.register-val-company .custom-radio:checked').attr('value'); |
| 172 | var regHideBlock = $('.register-company-block .form-group') | 172 | var regHideBlock = $('.register-company-block .form-group') |
| 173 | if(registerValCompany==1) { | 173 | if(registerValCompany==1) { |
| 174 | - regHideBlock.css({display:'none'}) | 174 | + $('.register-company-block').css('display', 'none'); |
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | + | ||
| 178 | + | ||
| 177 | $('.register-val-company .custom-radio').change(function(){ | 179 | $('.register-val-company .custom-radio').change(function(){ |
| 178 | - var newRegisterValCompany = +$(this).attr('value') | 180 | + var newRegisterValCompany = +$(this).attr('value'); |
| 179 | if(newRegisterValCompany==1){ | 181 | if(newRegisterValCompany==1){ |
| 180 | - regHideBlock.css({display:'none'}) | 182 | + //human |
| 183 | + $('.register-company-block').css('display', 'none'); | ||
| 184 | + | ||
| 181 | } else { | 185 | } else { |
| 182 | - regHideBlock.css({display:'block'}) | 186 | + //company |
| 187 | + $('.register-company-block').css('display', 'block'); | ||
| 183 | } | 188 | } |
| 184 | 189 | ||
| 185 | }) | 190 | }) |
frontend/views/tender/view.php
| @@ -46,7 +46,7 @@ $this->title = 'My Yii Application'; | @@ -46,7 +46,7 @@ $this->title = 'My Yii Application'; | ||
| 46 | <div class="cabinet-message-read-foto"><img src="/images/ded-foto.jpg" alt=""/></div> | 46 | <div class="cabinet-message-read-foto"><img src="/images/ded-foto.jpg" alt=""/></div> |
| 47 | </div> | 47 | </div> |
| 48 | <div class="cab-mes-read-cont"> | 48 | <div class="cab-mes-read-cont"> |
| 49 | - <div class="cab-mes-read-cont-title">Петер Цумтор</div> | 49 | + <div class="cab-mes-read-cont-title"><?= $model->user->owner->name?></div> |
| 50 | <div class="cab-mes-read-cont-stars"> | 50 | <div class="cab-mes-read-cont-stars"> |
| 51 | <div class="rating"> | 51 | <div class="rating"> |
| 52 | <!--оценка--> | 52 | <!--оценка--> |