/**
  * @param null $id
  * @param null $sentence
  * @return array|null|static
  * @throws \yii\db\Exception
  */
 protected function level1($id = NULL, $sentence = NULL)
 {
     if ($sentence == NULL) {
         $max = Level1::find()->count();
         $model = Level1::findOne(['id' => rand(1, $max)]);
         return $model;
     } else {
         $model = Level1::findOne(['id' => $id]);
         if (strcmp($this->checkSentence($sentence), $model->eng_phrase) !== 0) {
             $model->appeared++;
             $model->wrong++;
             if (!$model->save()) {
                 throw new \yii\db\Exception();
             }
             return ['eng_phrase' => ucfirst($model->eng_phrase), 'status' => false];
         } else {
             $model->appeared++;
             if (!$model->save()) {
                 throw new \yii\db\Exception();
             }
             return ['eng_phrase' => ucfirst($model->eng_phrase), 'status' => true];
         }
     }
 }
示例#2
0
 public static function getAllTranslatedCategory()
 {
     $all_categories = ArrayHelper::map(\app\models\Level1::find()->all(), 'id', 'name');
     foreach ($all_categories as $k => $v) {
         $all_categories[$k] = Yii::t('yii', $all_categories[$k]);
     }
     return $all_categories;
 }