public function getAnswersByDay() { $answers = []; $query = QuizVote::find()->select(['answerID', 'votes' => 'COUNT(*)', 'answersDate' => 'FROM_UNIXTIME(`date`,\'%Y-%m-%d\')'])->where(['quizID' => $this->id])->groupBy(['answerID', 'answersDate'])->asArray(); foreach ($query->each() as $answer) { $answers[$answer['answersDate']][$answer['answerID']] = $answer['votes']; } ksort($answers); return $answers; }
/** * @return \yii\db\ActiveQuery */ public function getVotes() { return $this->hasMany(QuizVote::className(), ['quizID' => 'id']); }
public function init() { $this->ip = \Yii::$app->request->userIP; return parent::init(); }
public function down() { Yii::$app->db->createCommand()->truncateTable(\common\models\QuizVote::tableName())->execute(); }