예제 #1
0
 public static function saveAnswer($request)
 {
     $userId = Yii::app()->user->id;
     if ($userId && isset($request['answerId'])) {
         $currentAnswer = Answers::model()->current()->find('userId=?', [$userId]);
         if ($currentAnswer) {
             $currentAnswer->isCurrent = false;
             if ($request['answerId'] != $currentAnswer->dictonaryId) {
                 $currentAnswer->isError = true;
                 $errAns = new ErrorAnswers();
                 $errAns->userId = $userId;
                 $errAns->dictonaryId = $currentAnswer->dictonaryId;
                 $errAns->answerId = $request['answerId'];
                 if ($errAns->save()) {
                     return ['success' => true, 'reenter' => true, 'error' => $currentAnswer->isError];
                     Yii::app()->end();
                 } else {
                     var_dump($errAns->getErrors());
                 }
             } else {
                 $currentAnswer->isOk = true;
             }
             if ($currentAnswer->save()) {
                 return ['success' => true, 'reenter' => false, 'question' => Dictonary::getQuestion($userId), 'error' => $currentAnswer->isError, 'ok' => $currentAnswer->isOk];
                 Yii::app()->end();
             } else {
                 var_dump($currentAnswer->getErrors());
             }
         }
     }
     return ['success' => false, 'error' => 'ошибка при сохранении ответа'];
 }