Exemple #1
0
 public function getActions()
 {
     $dictionaryModel = new Dictionary();
     $dictionary = $dictionaryModel->findOne($this->id_dictionary);
     if ($dictionary->is_system) {
         return array();
     } else {
         return parent::getActions();
     }
 }
Exemple #2
0
 protected function _updateDictionary($form, $id)
 {
     $dictionary = new Dictionary();
     $data = $dictionary->findOne($id);
     $values = $form->getValues();
     $data->setFromArray($values);
     $output = $data->save();
     $logger = Zend_Registry::get('logger');
     $message['messages']['Dictionary'][$id] = 'Dictionary updated.';
     Zend_Registry::set('logger', array_merge($logger, $message));
     return $output;
 }
 public function actionCheck()
 {
     $result = [];
     $request = Yii::$app->request;
     $username = $request->post('username');
     $testId = $request->post('testId');
     $word = $request->post('word');
     $translation = $request->post('translation');
     $order = $request->post('order');
     $user = Users::findByUsername($username);
     $test = Test::findOne($testId);
     if ($order) {
         $dictionary = Dictionary::findOne(['translation' => $word]);
     } else {
         $dictionary = Dictionary::findOne(['word' => $word]);
     }
     if (!$user || !$test) {
         return ['error' => true, 'message' => 'Either the user or test not found'];
     }
     $error = $order ? $dictionary->word !== $translation : $dictionary->translation !== $translation;
     if ($error) {
         $result['error'] = $error;
     }
     if (TestRecords::hasMaxErrors($testId)) {
         $result['maxErrors'] = true;
         return $result;
     }
     // TODO: transaction here
     $testRecord = new TestRecords();
     $testRecord->attributes = ['user_id' => $user->id, 'test_id' => $testId, 'dictionary_id' => $dictionary->id, 'order' => $order, 'is_error' => (int) $error, 'wrong_translation' => $error ? $translation : null];
     $testRecord->save();
     // Check once again for max errors after the save
     if (TestRecords::hasMaxErrors($testId)) {
         $result['maxErrors'] = true;
         return $result;
     }
     if (!$error) {
         // Increase the score by 1
         $test->scoreUp();
     }
     return $result;
 }