public function actionCreate()
 {
     $model = new UserProfile();
     if ($model->load(\Yii::$app->request->post())) {
         $model->roles = $this->getParams($model, 'roles');
         if ($model->validate() && $model->save()) {
             return $this->redirect(['index']);
         }
     }
     return $this->render('form', ['model' => $model]);
 }
 public function actionEditProfile()
 {
     $teacherProfile = UserProfile::findOne(['user_id' => Yii::$app->user->id]);
     if (!isset($teacherProfile)) {
         $teacherProfile = new UserProfile();
         $teacherProfile->user_id = Yii::$app->user->id;
     }
     if ($teacherProfile->load(Yii::$app->request->post()) && $teacherProfile->save()) {
         Yii::$app->session->setFlash('info', 'Profile updated successfully');
         return $this->redirect(['/teacher']);
     }
     return $this->render('edit-profile', compact('teacherProfile'));
 }
Example #3
0
 public function init()
 {
     $this->modelClass = UserProfile::className();
     $this->findModel = UserController::className() . '::' . UserController::METHOD_FIND_MODEL;
     $this->checkAccess = UserController::className() . '::' . UserController::METHOD_CHECK_ACCESS;
     parent::init();
 }
 /**
  * Sends an email with a link, for resetting the password.
  *
  * @return boolean whether the email was send
  */
 public function sendEmail()
 {
     /* @var $user User */
     $user = \common\models\User::findOne(['status' => ['active', 'inactive'], 'email' => $this->email]);
     // \yii\helpers\VarDumper::dump($user);
     //  die;
     $data = array();
     $user->generatePasswordResetToken();
     $userProfile = \common\models\UserProfile::findOne(['user_id' => $user->id]);
     if ($user->user_type == 'admin') {
         $resetLink = Yii::$app->urlManager->createAbsoluteUrl(['auth/login/reset-password', 'token' => $user->ud_temp_password]);
         $data['user'] = $userProfile->first_name . ' ' . $userProfile->last_name;
     } else {
         $resetLink = Yii::$app->urlManager->createAbsoluteUrl(['auth/login/reset-password', 'token' => $user->ud_temp_password]);
         $data['user'] = $userProfile->first_name . ' ' . $userProfile->last_name;
     }
     if ($user->save(false)) {
         $resetLink = $resetLink;
         $data['to'] = $user->email;
         $data['link'] = $resetLink;
         $data['request'] = "forget_password";
         Utility::sendMail($data);
         return true;
     }
     return false;
 }
 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if (!$this->validate()) {
         return null;
     }
     $user = new User();
     $user->username = $this->username;
     $user->email = $this->email;
     $user->setPassword($this->password);
     $user->generateAuthKey();
     if ($user->save()) {
         $profile = new UserProfile();
         $profile->user_id = $user->id;
         return $profile->save() ? $user : null;
     }
     return null;
 }
Example #6
0
 public function actionDeleteMiddleName()
 {
     /* @var $modelProfile \common\models\UserProfile */
     $modelProfile = UserProfile::findOne(['user_id' => Yii::$app->user->id]);
     $modelProfile->middle_name = '';
     $modelProfile->save();
     return $this->render('index', ['middleName' => $modelProfile->middle_name]);
 }
Example #7
0
 public function run()
 {
     /* @var $modelProfile \common\models\UserProfile */
     $modelProfile = UserProfile::findOne(['user_id' => Yii::$app->user->id]);
     if ($this->modelProfile) {
         return $this->render('view', ['modelProfile' => $this->modelProfile]);
     }
     return $this->render('view', ['middleName' => $modelProfile->middle_name]);
 }
Example #8
0
 /**
  * Updates an existing User model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $model->setScenario('update');
     if ($model->profile) {
         $profile = $model->profile;
     } else {
         $profile = new UserProfile();
         $profile->user_id = $model->id;
     }
     $post = Yii::$app->request->post();
     if ($model->load($post) && $model->save()) {
         if ($profile->load($post) && $profile->save()) {
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'profile' => $profile]);
     }
 }
Example #9
0
 public function updateProfile()
 {
     $modelUserProfile = ($modelUserProfile = UserProfile::findOne(Yii::$app->user->id)) ? $modelUserProfile : new UserProfile();
     $modelUserProfile->user_id = Yii::$app->user->id;
     $modelUserProfile->first_name = $this->first_name;
     $modelUserProfile->last_name = $this->last_name;
     $modelUserProfile->middle_name = $this->middle_name;
     if ($modelUserProfile->save()) {
         return $modelUserProfile;
     }
     return false;
 }
Example #10
0
 /**
  * 获取我测试的过的数量
  * @param unknown $uid
  */
 public static function getTestingCount($uid)
 {
     static $testing_count = null;
     if ($testing_count !== null) {
         return $testing_count;
     }
     $model_UserProfile = UserProfile::findOne($uid);
     if ($model_UserProfile) {
         $testing_count = $model_UserProfile->testing_count;
         $testing_count = $testing_count ? intval($testing_count) : 0;
     }
     return $testing_count;
 }
Example #11
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = UserProfile::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'uid' => $this->uid, 'money' => $this->money, 'friend_money' => $this->friend_money, 'sex' => $this->sex, 'birthday' => $this->birthday]);
     $query->andFilterWhere(['like', 'nickname', $this->nickname])->andFilterWhere(['like', 'head_image', $this->head_image])->andFilterWhere(['like', 'intro', $this->intro])->andFilterWhere(['like', 'address', $this->address])->andFilterWhere(['like', 'qq', $this->qq])->andFilterWhere(['like', 'school', $this->school]);
     return $dataProvider;
 }
 /**
 * Creates data provider instance with search query applied
 *
 * @param array $params
 *
 * @return ActiveDataProvider
 */
 public function search($params)
 {
     $query = UserProfile::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'lesson_cost' => $this->lesson_cost, 'currency_id' => $this->currency_id, 'created_at' => $this->created_at, 'updated_ad' => $this->updated_ad]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'lastname', $this->lastname]);
     return $dataProvider;
 }
 /**
  * Deletes an existing User model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  *
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     if ($id == Yii::$app->user->id) {
         Yii::$app->session->setFlash('error', Yii::t('backend', 'You can not remove your own account.'));
     } else {
         // remove avatar
         $avatar = UserProfile::findOne($id)->avatar_path;
         if ($avatar) {
             unlink(Yii::getAlias('@storage/avatars/' . $avatar));
         }
         Yii::$app->authManager->revokeAll($id);
         $this->findModel($id)->delete();
         Yii::$app->session->setFlash('success', Yii::t('backend', 'User has been deleted.'));
     }
     return $this->redirect(['index']);
 }
Example #14
0
 public function getUserProfile()
 {
     return $this->hasOne(UserProfile::className(), array('user_id' => 'staff_id'));
 }
Example #15
0
 /**
  * @return string
  */
 public function actionDeleteAvatar()
 {
     $imageData = Json::decode(Yii::$app->request->post('imageData'));
     $modelImageForm = new ImageForm();
     $modelImageForm->deleteImage();
     if (Yii::$app->session->get('error')) {
         echo $error = Yii::$app->session->get('error');
     } else {
         $error = false;
     }
     /* @var $model \common\models\AdRealEstate */
     if ($imageData['modelName'] == 'AdRealEstate') {
         $model = AdRealEstate::findOne($imageData['object_id']);
     } elseif ($imageData['modelName'] == 'UserProfile') {
         $model = UserProfile::findOne($imageData['object_id']);
     }
     $imagesObject = $model->imagesOfObjects;
     return $this->render('@common/widgets/ImageLoad/views/_formAutoload', ['modelName' => $imageData['modelName'], 'id' => $imageData['id'], 'object_id' => $imageData['object_id'], 'images_num' => $imageData['images_num'], 'images_label' => $imageData['images_label'], 'images_temp' => $imageData['images_temp'], 'imageSmallWidth' => $imageData['imageSmallWidth'], 'imageSmallHeight' => $imageData['imageSmallHeight'], 'imagesObject' => $imagesObject, 'modelImageForm' => $modelImageForm, 'baseUrl' => $imageData['baseUrl'], 'imagePath' => $imageData['imagePath'], 'noImage' => $imageData['noImage'], 'imageClass' => $imageData['imageClass'], 'buttonDeleteClass' => $imageData['buttonDeleteClass'], 'imageContainerClass' => $imageData['imageContainerClass'], 'formImagesContainerClass' => $imageData['formImagesContainerClass'], 'error' => $error]);
 }
Example #16
0
 public function getProfile()
 {
     return $this->hasOne(UserProfile::className(), ['user_id' => 'id']);
 }
Example #17
0
			</td>
			<td class="td-3">
			     <div>

					<a class="a-left" href="<?php 
echo $url_user_setting;
?>
">设置</a>
					<a class="a-right" href="<?php 
echo $url_logout;
?>
">退出</a>
				</div>
				<div >
					测过<sapn class="common-color"><?php 
echo UserProfile::getTestingCount(ZCommonSessionFun::get_user_id());
?>
</sapn>次
				</div>
				<div onclick="javascript:window.top.document.location='<?php 
echo Yii::$app->urlManager->createUrl(['my/uid-fans', 'uid' => $sessionUser['uid']]);
?>
'">
					粉丝<sapn class="common-color"><?php 
echo UsersFriends::get_concern_count(ZCommonSessionFun::get_user_id());
?>
</sapn>人
				</div>
			</td>
		</tr>
	</table>
 /**
  * Finds the UserProfile model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return UserProfile the loaded model
  * @throws HttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = UserProfile::findOne($id)) !== null) {
         return $model;
     } else {
         throw new HttpException(404, 'The requested page does not exist.');
     }
 }
Example #19
0
 public function actionInterview()
 {
     $userdetails = \Yii::$app->user->identity;
     $model = InterviewVideo::find()->where(['user_id' => $userdetails->id])->one();
     //echo "<pre>";print_r($model->video);die;
     if (empty($model)) {
         $model = new InterviewVideo();
     }
     $video = new Video();
     $user = Userform::find()->where(['id' => $userdetails->id])->one();
     if (empty($user)) {
         $user = new Userform();
     }
     $userprofile = UserProfile::find()->where(['user_id' => $userdetails->id])->one();
     if (empty($userprofile)) {
         $userprofile = new UserProfile();
     }
     if (isset($_POST['Video'])) {
         $video->attributes = $_POST['Video'];
         $video->media_module_id = 5;
         // id 5 is interview video type in tlb_media_module table
         $model->user_id = $userdetails->id;
         if ($video->validate()) {
             $video->save();
             $model->video_id = $video->id;
             $model->save();
         }
     }
     return $this->render('interview', ['model' => $model, 'user' => $user, 'video' => $video, 'userprofile' => $userprofile]);
 }
 /**
  * Displays a single User model.
  *
  * @param int $id
  * @return mixed
  */
 public function actionView($id)
 {
     return $this->render('view', ['model' => $this->findModel($id), 'profile' => UserProfile::findOne($id)]);
 }
Example #21
0
 public function onAuthSuccess($client)
 {
     /* @var $client \yii\authclient\OAuth2*/
     /* @var $user \common\models\User */
     $attributes = $client->getUserAttributes();
     /* @var $auth Auth */
     $auth = Auth::find()->where(['source' => $client->getId(), 'source_id' => $attributes['id']])->one();
     if (Yii::$app->user->isGuest) {
         if ($auth) {
             // вход
             $user = $auth->user;
             if ($user->status == User::STATUS_NOT_ACTIVE && $user->email == '') {
                 Yii::$app->getSession()->setFlash('success', [Yii::t('app', "To complete registration, enter the phone number and confirm the e-mail address.")]);
                 return $this->redirectUser($url = Url::to(['/main/finish-reg', 'id' => $user->id]));
             } elseif ($user->status == User::STATUS_NOT_ACTIVE && $user->email != '') {
                 Yii::$app->getSession()->setFlash('success', [Yii::t('app', "To complete registration, enter a phone number.")]);
                 return $this->redirectUser($url = Url::to(['/main/finish-reg', 'id' => $user->id]));
             } elseif ($user->status == User::STATUS_DELETED) {
                 Yii::$app->getSession()->setFlash('error', [Yii::t('app', "This user is blocked.")]);
                 return $this->redirectUser($url = Url::to(['/ad/view/all']));
             }
             Yii::$app->user->login($user);
         } else {
             // регистрация
             if (isset($attributes['email']) && ($user = User::findOne(['email' => $attributes['email']]))) {
                 // Если пользователь регитрировался ранее через форму регистации.
                 if ($user) {
                     if ($user->status == User::STATUS_DELETED) {
                         Yii::$app->getSession()->setFlash('error', Yii::t('app', "User <strong> {email} </strong> blocked.", ['email' => $user->email]));
                     } elseif ($user->auths->source) {
                         Yii::$app->getSession()->setFlash('error', [Yii::t('app', "Authorization using the email address <strong> {email} </strong> is already happening through the account <strong> {auths} </strong>.\n                            Log on using the account <strong> {auths} </strong> or use the link <strong> Forgot your password? </strong> for email <strong> {email} </strong> to restore the password..", ['email' => $user->email, 'auths' => $user->auths->source])]);
                     } else {
                         Yii::$app->getSession()->setFlash('error', Yii::t('app', "Authorization using the email address <strong> {email} </strong> has successfully passed through the registration form. Click on the link <strong> Forgot your password? </strong> to restore the password.", ['email' => $user->email]));
                     }
                 }
                 return $this->redirectUser($url = Url::to(['/main/login']));
             } else {
                 // Полученные данные заносим в переменные
                 /* @var $email string */
                 /* @var $first_name string */
                 /* @var $last_name string */
                 if (Yii::$app->request->get('authclient') == 'google') {
                     $first_name = $attributes['name']['givenName'];
                     $last_name = $attributes['name']['familyName'];
                     $email = $attributes['emails'][0]['value'];
                 } elseif (Yii::$app->request->get('authclient') == 'yandex') {
                     $first_name = $attributes['first_name'];
                     $last_name = $attributes['last_name'];
                     $email = $attributes['default_email'];
                 } elseif (Yii::$app->request->get('authclient') == 'facebook') {
                     $names = explode(' ', $attributes['name']);
                     $first_name = $names[0];
                     $last_name = $names[1];
                     $email = $attributes['email'];
                 } elseif (Yii::$app->request->get('authclient') == 'vkontakte') {
                     $first_name = $attributes['first_name'];
                     $last_name = $attributes['last_name'];
                     $email = false;
                 } elseif (Yii::$app->request->get('authclient') == 'twitter') {
                     $names = $attributes['name'];
                     $names = explode(' ', $names);
                     $first_name = $names[0];
                     $last_name = $names[1];
                     $email = false;
                 } elseif (Yii::$app->request->get('authclient') == 'linkedin') {
                     $first_name = $attributes['first_name'];
                     $last_name = $attributes['last_name'];
                     $email = $attributes['email'];
                 }
                 $password = Yii::$app->security->generateRandomString(6);
                 if ($email == false) {
                     $email = '';
                 }
                 $user = new User(['email' => $email, 'password' => $password, 'status' => User::STATUS_NOT_ACTIVE, 'country_id' => 182]);
                 $user->generateAuthKey();
                 $user->generateSecretKey();
                 $transaction = $user->getDb()->beginTransaction();
                 if ($user->save()) {
                     $auth = new Auth(['user_id' => $user->id, 'source' => $client->getId(), 'source_id' => (string) $attributes['id']]);
                     if ($auth->save()) {
                         /* @var $modelProfile /common/models/UserProfile */
                         $modelProfile = new UserProfile();
                         $modelProfile->user_id = $user->id;
                         $modelProfile->first_name = $first_name;
                         $modelProfile->last_name = $last_name;
                         if ($modelProfile->save()) {
                             if (RbacHelper::assignRole($user->id)) {
                                 $modelUserPrivilege = new UserPrivilege();
                                 $modelUserPrivilege->link('user', $user);
                                 $transaction->commit();
                             }
                             // если нет емайл, делаем перенаправление на main/finish-reg
                             if ($email == false) {
                                 Yii::$app->getSession()->setFlash('success', [Yii::t('app', "To complete registration, enter the phone number and confirm the e-mail address.")]);
                                 return $this->redirectUser($url = Url::to(['/main/finish-reg', 'id' => $user->id]));
                             }
                             Yii::$app->getSession()->setFlash('success', [Yii::t('app', "To complete registration, enter a phone number.")]);
                             return $this->redirectUser($url = Url::to(['/main/finish-reg', 'id' => $user->id]));
                         }
                     } else {
                         d($auth->getErrors());
                     }
                 } else {
                     /* @var $user \common\models\User */
                     $user = User::findOne(['email' => $user->email]);
                     // Если пользователь регитрировался ранее через форму регистации.
                     if ($user) {
                         if ($user->status == User::STATUS_DELETED) {
                             Yii::$app->getSession()->setFlash('error', Yii::t('app', "User <strong> {email} </strong> blocked.", ['email' => $user->email]));
                         } elseif ($user->auths->source) {
                             Yii::$app->getSession()->setFlash('error', [Yii::t('app', "Authorization using the email address <strong> {email} </strong> is already happening through the account <strong> {auths} </strong>.\n                            Log on using the account <strong> {auths} </strong> or use the link <strong> Forgot your password? </strong> for email <strong> {email} </strong> to restore the password..", ['email' => $user->email, 'auths' => $user->auths->source])]);
                         } else {
                             Yii::$app->getSession()->setFlash('error', Yii::t('app', "Authorization using the email address <strong> {email} </strong> has successfully passed through the registration form. Click on the link <strong> Forgot your password? </strong> to restore the password.", ['email' => $user->email]));
                         }
                     }
                     return $this->redirectUser($url = Url::to(['/main/login']));
                 }
             }
         }
     } else {
         // user already logged in
         if (!$auth) {
             // add auth provider
             $auth = new Auth(['user_id' => Yii::$app->user->id, 'source' => $client->getId(), 'source_id' => $attributes['id']]);
             $auth->save();
         }
     }
     return true;
 }
Example #22
0
 /**
  * Creates user profile and application event
  * @param array $profileData
  */
 public function afterSignup(array $profileData = [])
 {
     TimelineEvent::log('user', 'signup', ['publicIdentity' => $this->getPublicIdentity(), 'userId' => $this->getId(), 'created_at' => $this->created_at]);
     $profile = new UserProfile();
     $profile->locale = Yii::$app->language;
     $profile->load($profileData, '');
     $this->link('userProfile', $profile);
     $this->trigger(self::EVENT_AFTER_SIGNUP);
     // Default role
     $auth = Yii::$app->authManager;
     $auth->assign($auth->getRole(User::ROLE_USER), $this->getId());
 }
 /**
  * Updates current users User and Profile model.
  * If update is successful, the browser will be redirected to the 'profile' page.
  * @return mixed
  */
 public function actionSettings()
 {
     $id = \Yii::$app->user->id;
     $user = User::findOne($id);
     if (!$user) {
         throw new NotFoundHttpException("The user was not found.");
     }
     $profile = UserProfile::findOne($user->userProfile->id);
     if (!$profile) {
         throw new NotFoundHttpException("The user has no profile.");
     }
     //$user->scenario = 'update';
     //$profile->scenario = 'update';
     if ($profile->load(Yii::$app->request->post())) {
         $isValid = $profile->validate();
         if ($isValid) {
             $profile->save(false);
             return $this->redirect('settings');
         }
     }
     return $this->render('settings', ['user' => $user, 'profile' => $profile]);
 }
Example #24
0
 /**
  * Creates user profile and application event.
  *
  * @param array $profileData
  */
 public function afterSignup(array $profileData = [])
 {
     $profile = new UserProfile();
     $profile->load($profileData, '');
     $this->link('userProfile', $profile);
     // Default role
     $auth = Yii::$app->authManager;
     $auth->assign($auth->getRole(self::ROLE_USER), $this->getId());
 }
Example #25
0
 /**
  * @inheritdoc
  */
 public function afterSave($insert, $changedAttributes)
 {
     if ($insert) {
         $profile = new UserProfile();
         $profile->owner_id = $this->id;
         $profile->tryInsert(false);
     }
     parent::afterSave($insert, $changedAttributes);
 }
Example #26
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUserProfile()
 {
     return $this->hasOne(\common\models\UserProfile::className(), ['user_id' => 'id']);
 }
Example #27
0
 /**
  * Creates user profile and application event
  * @param array $profileData
  */
 public function afterSignup(array $profileData = [])
 {
     Yii::$app->commandBus->handle(new AddToTimelineCommand(['category' => 'user', 'event' => 'signup', 'data' => ['publicIdentity' => $this->getPublicIdentity(), 'userId' => $this->getId(), 'created_at' => $this->created_at]]));
     $profile = new UserProfile();
     $profile->locale = Yii::$app->language;
     $profile->load($profileData, '');
     $this->link('userProfile', $profile);
     $this->trigger(self::EVENT_AFTER_SIGNUP);
     // Default role
     $auth = Yii::$app->authManager;
     $auth->assign($auth->getRole(User::ROLE_USER), $this->getId());
 }
Example #28
0
 /**
  * 分数型问题回答2
  */
 public function actionStep2Answer2($id)
 {
     $this->layout = false;
     $model = Survey::findOne($id);
     if (!$model) {
         //没找到
         $model = new Survey();
     }
     if ($model->is_publish < 1) {
         $this->popupMessage($model->title . '未发布,不能测试');
         exit;
     }
     $data = $model->FindAllQuestionsOptions($id);
     //                 ZCommonFun::print_r_debug($_POST);
     //                 exit;
     $posts = Yii::$app->request->post();
     $error = '';
     if (isset($posts['name'])) {
         is_array($posts['options']) ?: ($posts['options'] = array());
         $op = count($posts['options']) > 0 ? true : false;
         $res = isset($posts['res']) ? intval($posts['res']) : 0;
         $res_model_SurveyResulte = $res > 0 ? SurveyResulte::findOne($res) : null;
         if ($res_model_SurveyResulte && $res_model_SurveyResulte->s_id == $id) {
         } else {
             $res_model_SurveyResulte = null;
         }
         $total_score = 0;
         $save = 0;
         $result = null;
         //保存结果
         $transaction = Yii::$app->db->beginTransaction();
         try {
             $name = isset($posts['name']) ? $posts['name'] : '';
             $year = isset($posts['birth']['year']) ? $posts['birth']['year'] : 2015;
             $month = isset($posts['birth']['month']) ? $posts['birth']['month'] : '01';
             $day = isset($posts['birth']['day']) ? $posts['birth']['day'] : '01';
             $constellation = isset($posts['constellation']) ? intval($posts['constellation']) : 0;
             $constellation = $constellation > 0 && $constellation < 13 ? $constellation : 0;
             $birth = $year . '-' . $month . '-' . $day;
             $birth = date('Y-m-d', strtotime($birth));
             $model_AnswerUser = new AnswerUser();
             $model_AnswerUser->sid = $id;
             $model_AnswerUser->table = 'survey_resulte';
             $res_model_SurveyResulte ? $model_AnswerUser->table_id = $res_model_SurveyResulte->sr_id : null;
             $model_AnswerUser->answer_name = $name;
             $model_AnswerUser->answer_age = $birth;
             $model_AnswerUser->constellation = $constellation;
             $model_AnswerUser->ip = self::getUserIP();
             if (!$model_AnswerUser->save()) {
                 $error = '用户操作失败';
                 $transaction->rollBack();
             } else {
                 foreach ($data['options'] as $key => $value) {
                     foreach ($value as $option) {
                         foreach ($posts['options'] as $question_id => $row) {
                             //找到选项
                             if ($option->qo_id = $row[0]) {
                                 $model_Answer = new Answer();
                                 $model_Answer->table_id = $id;
                                 $model_Answer->question_id = $option->question_id;
                                 $model_Answer->qo_id = $row[0];
                                 $model_Answer->answer_score += $option->option_score;
                                 $model_Answer->au_id = $model_AnswerUser->au_id;
                                 $total_score += $model_Answer->answer_score;
                                 $model_Answer->save() ? $save++ : null;
                             }
                         }
                     }
                 }
                 if ($save > 0) {
                     $model_SurveyResulte = new SurveyResulte();
                     //如果直接选择了答案
                     if ($model_AnswerUser->table == 'survey_resulte' && $model_AnswerUser->table_id > 0) {
                         $result = $res_model_SurveyResulte;
                         //
                     } else {
                         $result = $model_SurveyResulte->getStep2Result($id, $model_AnswerUser->answer_score);
                     }
                     if ($result && !$res_model_SurveyResulte) {
                         //保存回答者结果,防止用户更改数据导致结果丢失
                         $mode_AnswerSurveyResulte = new AnswerSurveyResulte();
                         $mode_AnswerSurveyResulte->attributes = $result->attributes;
                         $mode_AnswerSurveyResulte->save();
                         $model_AnswerUser->table == 'answer_survey_resulte';
                         $model_AnswerUser->table_id = $mode_AnswerSurveyResulte->answer_sr_id;
                     }
                     $model_AnswerUser->save();
                     $transaction->commit();
                     //设置测试数量
                     $model->setAnswerCount($id);
                     $model_UserProfile = new UserProfile();
                     $model_UserProfile->setTestCount($model_AnswerUser->uid);
                     return $this->redirect(['resulte', 'au_id' => $model_AnswerUser->au_id]);
                 } else {
                     $error = '没有选项';
                     $transaction->rollBack();
                 }
             }
         } catch (\Exception $e) {
             $error = '事物异常';
             ZCommonFun::print_r_debug($e);
             $transaction->rollBack();
         }
     }
     $model_Users = null;
     $model_UsersProfile = null;
     if ($model->uid) {
         $zhao_condition['uid'] = $model->uid;
         $model_Users = User::findOne($zhao_condition);
         $model_UsersProfile = UserProfile::findOne($zhao_condition);
     }
     !$model_Users ? $model_Users = new User() : '';
     !$model_UsersProfile ? $model_UsersProfile = new UserProfile() : '';
     $model_UsersProfile->uid = $model->uid;
     //         echo $error;
     //         exit;
     //         ZCommonFun::print_r_debug($result);
     $model_SurveyOperation = new SurveyOperation();
     $models_SurveyOperation = $model_SurveyOperation->getIsTop();
     return $this->render('step2answer3', ['models_SurveyOperation' => $models_SurveyOperation, 'data' => $data, 'model' => $model, 'error' => $error, 'posts' => $posts, 'image' => Survey::getImageUrl($model), 'model_Users' => $model_Users, 'model_UsersProfile' => $model_UsersProfile, 'randSurvey' => $this->getRandSurvey()]);
     //         return $this->render('step2answer',[
     //             'data'=>$data,
     //             'model'=>$model,
     //             'error'=>$error,
     //             'posts'=>$posts,
     //             'image'=>Survey::getImageUrl($model),
     //             'model_Users'=>$model_Users,
     //             'model_UsersProfile'=>$model_UsersProfile,
     //         ]);
 }
Example #29
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUserProfiles()
 {
     return $this->hasMany(\common\models\UserProfile::className(), ['currency_id' => 'id']);
 }
Example #30
0
</b>
		                  </label>
		                  <div class="user-intro">
		                      <?php 
echo $model_UsersProfile->getIntro0();
?>
		                  </div>
		                  <div class="user-test-info">
		                                                  创建了<span class="red"><?php 
echo $model_UsersProfile->test_count;
?>
</span>个测试,被测试过<span class="red"><?php 
echo $model->answer_count;
?>
</span>次,准确率<span class="red"><?php 
echo UserProfile::getRate0();
?>
</span>。
		                  </div>
		              </td>
		          </tr>
		      </table>
		   </div>
		</div>
		
		<div class="user-info">
		  <div style="height: 3.5em;line-height: 3.5em;overflow: hidden;    font-size: 1.5em;">
		  下面这些测试页不错,你想试一下嘛
		  </div>
		   <?php 
foreach ($randSurvey as $key => $row) {