select( self::tb_str, array(), array( 'id' => $id_int ) ); if ( empty( $rows_arr ) ){ throw new \RuntimeException( 'Invalid question ID' ); } $this->id_int = $rows_arr[0]['id']; $this->text_str = $rows_arr[0]['text']; $answerID_arr = Answer::getList( $this->id_int ); $this->answers_arr = array(); foreach( $answerID_arr as $answerID_int ){ $this->answers_arr[] = new Answer( $answerID_int ); } } /** * Get a list of question IDs for a quiz * * @param int $quizID_int ID of quiz to load questions for * * @return int[] Array of question IDs */ public static function getList( int $quizID_int ){ $db = DB::getDB(); $rows_arr = $db->select( self::tb_str, array( 'id' ), array( 'quiz' => $quizID_int ) ); $id_arr = array(); foreach( $rows_arr as $row_arr ){ $id_arr[] = $row_arr['id']; } return $id_arr; } /** * Get question text * * @return string Question text */ public function getText(){ return $this->text_str; } /** * Get Answers for question * * @return TestProject\Answer[] Array of answer objects */ public function getAnswers(){ return $this->answers_arr; } }