Your IP : 216.73.216.48


Current Path : /srv/www/sick/test/includes/libs/
Upload File :
Current File : //srv/www/sick/test/includes/libs/Questions.class.php

<?php

class Questions {

    private $_dbAdapter;
    private $_table;
    private $_answersTable;

    public function __construct() {
        $this->_dbAdapter = new MySQL();
        $this->_table = TABLE_PREFIX . 'questions';
        $this->_answersTable = TABLE_PREFIX . 'answers';
    }

    public function addQuestion($quizID, $question) {
        $insert = $this->_dbAdapter->runQuery('INSERT INTO ' . $this->_table . '
		(quiz_id,question)
		VALUES ("' . $quizID . '", "' . $question . '")');
        return $this->_dbAdapter->getLastInsertedID();
    }

    public function getQuestions($whereClause = '') {
        if ($whereClause != '') {
            $selectQuestions = $this->_dbAdapter->runQuery('SELECT * FROM ' . $this->_table . '
                WHERE ' . $whereClause);
        } else {
            $selectQuestions = $this->_dbAdapter->runQuery('SELECT * FROM ' . $this->_table);
        }

        $data['count']['questions'] = $this->_dbAdapter->countRows($selectQuestions);
        
        if ($this->_dbAdapter->countRows($selectQuestions) > 0) {
            while ($questionInfo = $this->_dbAdapter->fetchRows($selectQuestions)) {
                $selectAnswers = $this->_dbAdapter->runQuery('SELECT * FROM ' . $this->_answersTable . ' WHERE question_id="' . $questionInfo['question_id'] . '"');
                if ($this->_dbAdapter->countRows($selectAnswers) > 0) {
                    while ($answerInfo = $this->_dbAdapter->fetchRows($selectAnswers)) {
                        $data['answers'][$questionInfo['question_id']][] = $answerInfo;
                    }
                }
                $data['questions'][] = $questionInfo;
            }

            return $data;
        }
    }

}