Exemplo n.º 1
0
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     $auth = Yii::$app->authManager;
     if ($insert) {
         $location = new \common\models\Locations();
         //$location->scenario = \common\models\Locations::SCENARIO_REGISTER;
         if ($location->load(Yii::$app->request->post())) {
             $location->user_id = $this->id;
             if ($location->save()) {
                 // USER CREDIT
                 $userCredit = new \common\models\UserCredit();
                 $userCredit->user_id = $this->id;
                 $userCredit->time = date('Y-m-d H:i:s');
                 $userCredit->save();
                 // USER DETAILS
                 $userDetails = new \common\models\UserDetails();
                 $userDetails->user_id = $this->id;
                 $userDetails->loc_id = $location->id;
                 $userDetails->file_id = 2;
                 $userDetails->lang_code = 'SR';
                 $userDetails->currency_id = 1;
                 $userDetails->role_id = 1;
                 $userDetails->time_role_set = date('Y-m-d H:i:s');
                 $userDetails->update_time = date('Y-m-d H:i:s');
                 $userDetails->save();
                 // USER LOCATIONS
                 $user_location = new \common\models\UserLocations();
                 $user_location->loc_id = $location->id;
                 $user_location->user_id = $this->id;
                 $user_location->save();
                 // USER LOG
                 $userLog = new \common\models\UserLog();
                 $userLog->user_id = $this->id;
                 $userLog->action = $this->is_provider == 0 ? 'user_registered' : 'provider_registered';
                 $userLog->alias = $this->id;
                 $userLog->time = date('Y-m-d H:i:s');
                 $userLog->save();
                 // USER NOTIFICATONS
                 $userNotifications = new \common\models\UserNotifications();
                 $userNotifications->user_id = $this->id;
                 $userNotifications->update_time = date('Y-m-d H:i:s');
                 $userNotifications->save();
                 if ($this->is_provider == 1) {
                     $model = new \common\models\RegistrationProviderForm();
                     if ($model->load(Yii::$app->request->post())) {
                         // PROVIDER
                         $provider = new \common\models\Provider();
                         $provider->user_id = $this->id;
                         $provider->industry_id = $model->industry;
                         $provider->loc_id = $location->id;
                         $provider->legal_form = 'freelancer';
                         $provider->type = 'service_provider';
                         $provider->department_type = 'hq';
                         $provider->status = 'active';
                         $provider->registration_time = date('Y-m-d H:i:s');
                         $provider->save();
                         $userRole = $auth->getRole('provider');
                         $auth->assign($userRole, $this->id);
                     }
                 } else {
                     $userRole = $auth->getRole('user');
                     $auth->assign($userRole, $this->id);
                 }
             }
         }
     } else {
         $this->updated_at = time();
     }
 }
 public function currentProvider($model)
 {
     if ($user = \common\models\User::findOne(Yii::$app->user->id)) {
         $user->is_provider = 1;
         $user->member = 0;
         $user->role = 'provider';
         if ($user->save()) {
             // create temp provider
             $provider = new \common\models\Provider();
             $provider->user_id = $user->id;
             $provider->industry_id = $model->industry_id;
             $provider->loc_id = 1;
             $provider->legal_form = 'freelancer';
             $provider->type = 'service_provider';
             $provider->department_type = 'hq';
             $provider->status = 'inactive';
             $provider->is_active = 0;
             $provider->registration_time = date('Y-m-d H:i:s');
             //$provider->save();
             if ($provider->save()) {
                 // provider Industry
                 if ($providerIndustry = \common\models\ProviderIndustries::findOne($provider->initialIndustry->id)) {
                     $proserv = new \common\models\ProviderServices();
                     $proserv->provider_industry_id = $providerIndustry->id;
                     $proserv->provider_id = $provider->id;
                     $proserv->industry_id = $model->industry_id;
                     $proserv->service_id = $model->id;
                     $proserv->is_set = 1;
                     $proserv->update_time = date('Y-m-d H:i:s');
                     $proserv->save();
                 }
             }
         }
         return $user;
     }
     return false;
 }
Exemplo n.º 3
0
 public function currentProvider($model)
 {
     $user = \common\models\User::findOne(Yii::$app->user->id);
     // create temp provider
     $provider = new \common\models\Provider();
     $provider->user_id = $user->id;
     $provider->industry_id = $model->industry_id;
     $provider->loc_id = 1;
     $provider->legal_form = 'freelancer';
     $provider->type = 'service_provider';
     $provider->department_type = 'hq';
     $provider->status = 'inactive';
     $provider->is_active = 0;
     $provider->registration_time = date('Y-m-d H:i:s');
     $provider->save();
     if ($provider->save()) {
         // provider Industry
         $providerIndustry = new \common\models\ProviderIndustries();
         $providerIndustry->provider_id = $provider->id;
         $providerIndustry->industry_id = $model->industry_id;
         $providerIndustry->main = 1;
         if ($providerIndustry->save()) {
             $proserv = new \common\models\ProviderServices();
             $proserv->provider_industry_id = $providerIndustry->id;
             $proserv->provider_id = $provider->id;
             $proserv->industry_id = $model->industry_id;
             $proserv->service_id = $model->id;
             $proserv->is_set = 1;
             $proserv->update_time = date('Y-m-d H:i:s');
             $proserv->save();
         }
         // provider Industry Terms
         $providerIndustryTerm = new \common\models\ProviderIndustryTerms();
         $providerIndustryTerm->provider_industry_id = $providerIndustry->id;
         $providerIndustryTerm->update_time = date('Y-m-d H:i:s');
         $providerIndustryTerm->save();
         // provider Language
         $providerLanguage = new \common\models\ProviderLanguages();
         $providerLanguage->provider_id = $provider->id;
         $providerLanguage->lang_code = 'SR';
         $providerLanguage->save();
         // provider Portfolio
         $providerPortfolio = new \common\models\ProviderPortfolio();
         $providerPortfolio->provider_id = $provider->id;
         $providerPortfolio->name = 'Moj portfolio';
         $providerPortfolio->save();
         // provider Terms
         $providerTerms = new \common\models\ProviderTerms();
         $providerTerms->provider_id = $provider->id;
         $providerTerms->update_time = date('Y-m-d H:i:s');
         $providerTerms->save();
         // provider Notifications
         $providerNotifications = new \common\models\ProviderNotifications();
         $providerNotifications->provider_id = $provider->id;
         $providerNotifications->notification_type = 'matching';
         $providerNotifications->time = date('Y-m-d H:i:s');
         $providerNotifications->save();
     }
     return $user;
 }