예제 #1
0
 public function update()
 {
     if ($this->provinceId == "" || $this->majorJobId == "") {
         CommonFunctions::createAlertMessage("省份或者专业类型不能为空", "error");
         return false;
     }
     $user = Yii::$app->session->get('user');
     $majorJob = MajorJob::findOne($this->majorJobId);
     if ($this->provinceId != $majorJob['provinceId']) {
         CommonFunctions::createAlertMessage("专业类型与所处省份不一致,请重新选择", "error");
         return false;
     }
     //修改省份或专业岗位,需要清除用户的在线练习相关信息
     if ($this->provinceId != $user['provinceId'] || $this->majorJobId != $user['majorJobId']) {
         CurrentTestLibrary::deleteAll(['userId' => $user['userId']]);
         //删除当前记录
         ErrorQuestion::deleteAll(['userId' => $user['userId']]);
         //删除错题记录
         Collection::deleteAll(['userId' => $user['userId']]);
         //删除收藏
     }
     /** @var $user \common\models\Users */
     $user = Users::findOne($user['userId']);
     $user->nickname = $this->nickname;
     $user->realname = $this->realname;
     $user->provinceId = $this->provinceId;
     $user->majorJobId = $this->majorJobId;
     $user->company = $this->company;
     $user->address = $this->address;
     if (!$user->save()) {
         throw new Exception("UpdateInfoForm update Save Error");
     }
     Yii::$app->session->set('user', $user);
     return true;
 }
 /**
  * 错题练习
  * @return string
  */
 public function actionWrongTest()
 {
     $session = Yii::$app->session;
     $user = $session->get('user');
     $testLibraries = ErrorQuestion::findAllByUserWithTestLibrary($user['userId']);
     $countNumber = count($testLibraries);
     if ($countNumber == 0) {
         //避免没有题目生成出题页面出错
         $url = Url::to(['site/test-library-wrong-zero']);
         header("Location:{$url}");
         exit;
     }
     //将一些必要参数存入session,方便后续页面调用
     $session->set('testLibraries', $testLibraries);
     //所有题目
     $session->set('totalNumber', $countNumber);
     //总题数
     $session->set('testTitle', "错题练习");
     //测试标题
     $session->set('majorJob', $user['nickname']);
     //测试岗位使用用户昵称
     $session->set('testType', 6);
     //测试类型,6表示错题练习
     //取出特定的题目量
     $defaultOnceNumber = Yii::$app->params['defaultOnceNumber'];
     $testLibraries = array_slice($testLibraries, 0, $defaultOnceNumber);
     return $this->render('test', ['testLibraries' => $testLibraries, 'startNumber' => 0, 'currentNumber' => 0]);
 }
예제 #3
0
 public static function findAllByUserWithTestLibrary($userId)
 {
     $table_a = ErrorQuestion::tableName();
     $table_b = TestLibrary::tableName();
     return (new \yii\db\Query())->from([$table_a, $table_b])->where(["{$table_a}.userId" => $userId])->andWhere("{$table_b}.testLibraryId = {$table_a}.testLibraryId")->orderBy(["{$table_a}.createDate" => SORT_DESC])->all();
 }