コード例 #1
0
 public function add(Question $question)
 {
     $a = array(StudyPressDB::COL_CONTENT_QUESTION => $question->getContent(), StudyPressDB::COL_ID_QUIZ_QUESTION => $question->getQuizId(), StudyPressDB::COL_TYPE_QUESTION => $question->getType(), StudyPressDB::COL_ORDER_QUESTION => $this->getLastOrder($question->getQuizId()) + 1);
     $this->_access->insert(StudyPressDB::getTableNameQuestions(), $a);
     $idQuestion = $this->_access->getLastInsertId();
     $question->setId($idQuestion);
     return $idQuestion;
 }
コード例 #2
0
ファイル: Question.php プロジェクト: davidliuliuliu/sublite
 /**
  * If $recruiter is set, vanilla will be false. If $recruiter is null,
  * vanilla will be true.
  */
 private static function create($text, MongoId $recruiter = null)
 {
     // Check if question already exists (model function). If so, return
     // the question.
     $existingQuestion = QuestionModel::getByExactText($text);
     if (!is_null($existingQuestion)) {
         return self::parseRawData($existingQuestion);
     }
     // Construct question with parameters.
     $vanilla = is_null($recruiter);
     $question = new Question(['text' => $text, 'recruiter' => $recruiter, 'vanilla' => $vanilla]);
     // Pass (question object or raw data?) to model to store in database with
     // custom flag.
     $id = QuestionModel::insert($question->getData());
     $question->setId($id);
     // Return created question.
     return $question;
 }
コード例 #3
0
 /**
  * @return Question
  * @param int $id
  */
 public static function get($id)
 {
     $db = DB::getConn();
     $stm = $db->prepare('select * from Question where id = :id');
     $stm->bindParam(':id', $id);
     $stm->execute();
     $rs = $stm->fetchAll()[0];
     $q = new Question($rs['category'], $rs['point'], $rs['title'], $rs['explain']);
     $q->setId($id);
     $stm = $db->prepare('select * from Option where question = :id');
     $stm->bindParam(':id', $id);
     $stm->execute();
     $arr = $stm->fetchAll();
     foreach ($arr as $o) {
         $opt = new Option($o['question'], $o['title'], $o['isCorrect'] ? true : false);
         $opt->setId($o['id']);
         $q->addOpt($opt);
     }
     return $q;
 }
コード例 #4
0
        $c1 = 'selected';
    } else {
        $c2 = 'selected';
    }
}
if (isset($_POST['title']) && $_POST['title'] != '') {
    $cate = htmlspecialchars($_POST['cate']);
    $point = htmlspecialchars($_POST['point']);
    $title = htmlspecialchars($_POST['title']);
    $explain = htmlspecialchars($_POST['explain']);
    $q_tmp = new Question($cate, $point, $title, $explain);
    $update = false;
    if (isset($_POST['ques_id']) && $_POST['ques_id'] != '') {
        $update = true;
        $qid = $_POST['ques_id'];
        $q_tmp->setId($qid);
        QuestionCtrl::updateQuestion($q_tmp);
    } else {
        $qid = QuestionCtrl::addQuestion($q_tmp);
    }
    if ($qid > 0) {
        $opt1 = htmlspecialchars($_POST['opt1']);
        $optCR1 = isset($_POST['opt1-cr']);
        $o = new Option($qid, $opt1, $optCR1);
        if ($update) {
            $o->setId($_POST['o1-id']);
            QuestionCtrl::updateOption($o);
        } else {
            QuestionCtrl::addOption($o);
        }
        $opt2 = htmlspecialchars($_POST['opt2']);