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; }
/** * 查询用户当前做到哪种题型的第几题 * @param $user * @param $testTypeId * @return mixed */ public static function findCurrentNumber($user, $testTypeId) { $current = CurrentTestLibrary::findByUserAndTestType($user['userId'], $testTypeId); if (!$current) { return 0; } $table = TestLibrary::tableName(); if ($testTypeId == -1) { $subQuery = (new Query())->select('testLibraryId')->from($table)->where(['provinceId' => $user['provinceId'], 'majorJobId' => $user['majorJobId']]); } else { $subQuery = (new Query())->select('testLibraryId')->from($table)->where(['provinceId' => $user['provinceId'], 'majorJobId' => $user['majorJobId'], 'testTypeId' => $testTypeId]); } $query = (new Query())->select('count(*)')->from([$subQuery])->where(['<=', 'testLibraryId', $current['testLibraryId']]); $result = $query->one(); return $result['count(*)']; }
public static function deleteAllByUser($userId) { CurrentTestLibrary::deleteAll(['userId' => $userId]); }
/** * 练习模式下一题点击后操作 * @throws Exception */ public function actionNext() { $request = Yii::$app->request; if ($request->isAjax) { $session = Yii::$app->session; $testLibraryId = $request->post('testLibraryId'); $type = $request->post('type'); $testTypeId = $session->get('testTypeId'); $user = $session->get('user'); if ($testTypeId == -1 || $testTypeId == 1 || $testTypeId == 2 || $testTypeId == 3 || $testTypeId == 4) { //只有这五种练习方式记录当前练习到哪一题 CurrentTestLibrary::saveOrUpdate($user['userId'], $testTypeId, $testLibraryId); } if ($type == 0) { ErrorQuestion::saveOrUpdate($user['userId'], $testLibraryId); } } else { throw new Exception("非法提交"); } }