public function delete() { if (empty($this->id)) { return false; } $answer = QuizAnswer::findOne($this->id); $answer->deleted = 1; return $answer->save(false); }
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; }
/** * @return \yii\db\ActiveQuery */ public function getAnswers() { return $this->hasMany(QuizAnswer::className(), ['quizID' => 'id']); }
/** * @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(); }