Пример #1
0
 protected function loadModel($id)
 {
     /**
      * TODO или сделать в один запрос?
      */
     $criteria = new CDbCriteria();
     $criteria->compare('t.active', Quiz::STATUS_ACTIVE);
     /** @var $quiz Quiz */
     $quiz = Quiz::model()->findByPk($id, $criteria);
     if ($quiz === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     $criteria = new CDbCriteria(array('with' => 'answers', 'order' => 't.sequence ASC, answers.sequence ASC'));
     $criteria->compare('t.id_quiz', $id);
     $questions = QuizQuestion::model()->findAll($criteria);
     if (empty($questions)) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     $quiz->addRelatedRecord('questions', $questions, false);
     return $quiz;
 }