Exemplo n.º 1
0
 /**
  * @inheritdoc
  */
 public function bootstrap($app)
 {
     /** @var $module Module */
     if ($app->hasModule('qa') && ($module = $app->getModule('qa')) instanceof Module) {
         if ($app instanceof ConsoleApplication) {
             $module->controllerNamespace = 'artkost\\qa\\commands';
         } else {
             if (!class_exists($app->get('user')->identityClass)) {
                 throw new InvalidConfigException('Yii::$app->user->identityClass does not exist');
             }
         }
     }
     $app->i18n->translations[Module::TRANSLATION . '*'] = ['class' => PhpMessageSource::className(), 'basePath' => __DIR__ . '/messages', 'fileMap' => [Module::TRANSLATION . 'main' => 'main.php', Module::TRANSLATION . 'model' => 'model.php']];
     Yii::$container->set('artkost\\qa\\models\\AnswerInterface', Answer::className());
     Yii::$container->set('artkost\\qa\\models\\QuestionInterface', Question::className());
 }
Exemplo n.º 2
0
 /**
  * Answer Relation
  * @return \yii\db\ActiveQueryInterface
  */
 public function getAnswers()
 {
     return $this->hasMany(Answer::className(), ['question_id' => 'id']);
 }
 public function down()
 {
     $this->dropTable(Answer::tableName());
 }
Exemplo n.º 4
0
 /**
  * @param $id
  * @return string|Response
  */
 public function actionAnswer($id)
 {
     $model = new Answer(['question_id' => $id]);
     /** @var Question $question */
     $question = $model->question;
     if (!$question) {
         $this->notFoundException();
     }
     if ($model->load($_POST) && $model->save()) {
         Yii::$app->session->setFlash('answerFormSubmitted');
         return $this->redirect(['view', 'id' => $question->id, 'alias' => $question->alias]);
     } else {
         return $this->render('answer', compact('model', 'question'));
     }
 }
 public function down()
 {
     $this->dropColumn(Answer::tableName(), 'is_correct');
 }