Example #1
0
 public function delete()
 {
     if (empty($this->id)) {
         return false;
     }
     $answer = QuizAnswer::findOne($this->id);
     $answer->deleted = 1;
     return $answer->save(false);
 }
Example #2
0
 public function getAnswersWithCount()
 {
     $answers = QuizAnswer::find()->where(['in', 'id', array_keys($this->votesWithCount)])->all();
     $return = [];
     foreach ($answers as $answer) {
         $return[$answer->id] = ['text' => $answer->text, 'count' => array_key_exists($answer->id, $this->votesWithCount) ? $this->votesWithCount[$answer->id] : 0];
     }
     return $return;
 }
Example #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAnswers()
 {
     return $this->hasMany(QuizAnswer::className(), ['quizID' => 'id']);
 }
Example #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAnswer()
 {
     return $this->hasOne(QuizAnswer::className(), ['id' => 'answerID']);
 }
 public function down()
 {
     Yii::$app->db->createCommand()->truncateTable(\common\models\QuizAnswer::tableName())->execute();
 }