예제 #1
0
 /**
  * Сохранение записи о свободном приёме в дату <b>$date</b> на время <b>$time</b>
  * к специалисту <b>$spec</b>
  * @param string $date дата записи
  * @param integer $spec номер специалиста
  * @param integer $time время приёма
  */
 public function actionSaveRecord($date, $spec, $time)
 {
     $isDouble = self::hasRecord($date, $spec, $time);
     if (!$isDouble) {
         $record = new Records();
         $record->specialist_id = $spec;
         $record->reserved = 0;
         $record->visited = 0;
         $record->updated_at = date('Y-m-d H:i:s');
         $record->created_at = date('Y-m-d H:i:s');
         $record->user_id = Yii::$app->user->id;
         $minute = $time % 60;
         $hour = ($time - $minute) / 60;
         $strTime = explode('-', $date);
         $year = $strTime[0];
         $month = $strTime[1];
         $day = $strTime[2];
         $strTime = mktime($hour, $minute, 0, $month, $day, $year);
         $strTime = date('Y-m-d H:i:s', $strTime);
         $record->start_time = $strTime;
         $record->insurer_id = null;
         $record->visit_type = null;
         $result;
         if ($record->validate()) {
             $result = $record->save();
         } else {
             Yii::$app->session->setFlash('error', 'Произошла ошибка при записи данных');
             $result = false;
         }
     } else {
         $result = false;
     }
     return $result;
 }
 public function actionCheck()
 {
     $result = [];
     $request = Yii::$app->request;
     $test_id = $request->post('test_id');
     $word_id = $request->post('word_id');
     $answer_id = $request->post('answer_id');
     $language = $request->post('language');
     $username = $request->post('username');
     $user = User::findByUsername($username);
     $test = Test::findOne($test_id);
     $dictionaries = Dictionary::findAll([$language . '_id' => $word_id]);
     if (!$user || !$test) {
         return ['error' => true, 'message' => 'Either the user or test not found'];
     }
     foreach ($dictionaries as $dictionary) {
         $error = $language == 'ru' ? $dictionary->en_id != $answer_id : $dictionary->ru_id != $answer_id;
         if ($error) {
             continue;
         } else {
             break;
         }
     }
     if ($error) {
         $result['error'] = $error;
     }
     if (Records::hasMaxErrors($test_id)) {
         $result['maxErrors'] = true;
         return $result;
     }
     $lang_record = Languages::findOne(['lang' => $language]);
     $testRecord = new Records();
     $testRecord->attributes = ['test_id' => $test_id, 'dictionary_id' => $dictionary->id, 'language' => $lang_record->id, 'is_error' => (int) $error, 'wrong_answer_id' => $error ? $answer_id : null];
     $testRecord->save();
     // Check once again for max errors after the save
     if (Records::hasMaxErrors($test_id)) {
         $result['maxErrors'] = true;
         return $result;
     }
     if (!$error) {
         // Increase the score by 1
         $test->scoreUp();
     }
     return $result;
 }