Beispiel #1
0
 public function init()
 {
     global $wpdb;
     $rawQuestion = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPSQT_TABLE_QUESTIONS . "` WHERE id = %d", array($_GET['questionid'])), ARRAY_A);
     $prepdQuestion = array();
     foreach (Wpsqt_System::unserializeQuestion($rawQuestion, $_GET['subsection']) as $key => $value) {
         $prepdQuestion["wpsqt_" . $key] = $value;
     }
     $this->_action = "edit";
     $this->_question = $prepdQuestion;
 }
 /**
  * Handles showing the section.
  *
  * @since 2.0
  */
 public function showSection()
 {
     global $wpdb;
     $quizName = $_SESSION["wpsqt"]["current_id"];
     $sectionKey = $this->_key;
     if (isset($_POST['wpsqt-save-state']) && isset($_SESSION['wpsqt'][$quizName]['details']['save_resume']) && $_SESSION['wpsqt'][$quizName]['details']['save_resume'] == 'yes') {
         Wpsqt_Core::saveCurrentState($sectionKey);
         _e('Saved the current state. You can resume by revisiting the quiz.', 'wp-survey-and-quiz-tool');
         $sectionKey--;
         $show = false;
     } else {
         $show = true;
     }
     $section = $_SESSION["wpsqt"][$quizName]["sections"][$sectionKey];
     $orderBy = $section["order"] == "random" ? "RAND()" : "`order` " . strtoupper($section["order"]);
     $_SESSION["wpsqt"][$quizName]["sections"][$sectionKey]["questions"] = array();
     if (!empty($_SESSION["wpsqt"][$quizName]["sections"][$sectionKey]['limit'])) {
         $end = " LIMIT 0," . $_SESSION["wpsqt"][$quizName]["sections"][$sectionKey]['limit'];
     } else {
         $end = '';
     }
     $rawQuestions = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPSQT_TABLE_QUESTIONS . "` WHERE section_id = %d ORDER BY " . $orderBy . $end, array($section["id"])), ARRAY_A);
     foreach ($rawQuestions as $rawQuestion) {
         $_SESSION["wpsqt"][$quizName]["sections"][$sectionKey]["questions"][] = Wpsqt_System::unserializeQuestion($rawQuestion, $this->_type);
     }
     if ($show) {
         require Wpsqt_Core::pageView('site/' . $this->_type . '/section.php');
     }
 }
			</tr>
		</tfoot>
		<tbody class="wpsqt_questions_content">
			<?php 
if (empty($questions)) {
    ?>
			
				<tr>
					<td colspan="5"><div style="text-align: center;">No questions yet!</div></td>
				</tr>
			<?php 
} else {
    $count = 0;
    foreach ($questions as $rawQuestion) {
        $count++;
        $question = Wpsqt_System::unserializeQuestion($rawQuestion, $_GET['subsection']);
        ?>
			<tr class="<?php 
        echo $count % 2 ? 'wpsqt-odd' : 'wpsqt-even';
        ?>
" id="<?php 
        echo $question['id'];
        ?>
">
				<td><?php 
        echo $question['id'];
        ?>
</td>
				<td><?php 
        echo stripslashes($question['name']);
        ?>
 /**
  * Tests the serialization of the Questions array first 
  * serializes and then it unserilizes and then checks 
  * to see if they are the same.
  * 
  * @since 2.0
  */
 public function testQuestionsSerializationBothways()
 {
     $question = array("text" => "Test Question", "section" => "Section One", "points" => "3", "difficulty" => "easy", "add_text" => "Fix this.", "type" => "question");
     $serializedQuestion = array();
     list($serializedQuestion['text'], $serializedQuestion['type'], $serializedQuestion['difficulty'], $serializedQuestion['section'], $serializedQuestion['meta']) = Wpsqt_System::serializeQuestion($question, $_GET['subsection'], 'quiz');
     $unserializedQuestion = Wpsqt_System::unserializeQuestion($serializedQuestion, 'quiz');
     $this->assertEquals($question, $unserializedQuestion, "Arrays don't match up.");
 }
 /**
  * Handles showing the section.
  *
  * @since 2.0
  */
 public function showSection()
 {
     global $wpdb;
     $quizName = $_SESSION["wpsqt"]["current_id"];
     $sectionKey = $this->_key;
     $section = $_SESSION["wpsqt"][$quizName]["sections"][$sectionKey];
     $orderBy = $section["order"] == "random" ? "RAND()" : "`order` " . strtoupper($section["order"]);
     $_SESSION["wpsqt"][$quizName]["sections"][$sectionKey]["questions"] = array();
     if (!empty($_SESSION["wpsqt"][$quizName]["sections"][$sectionKey]['limit'])) {
         $end = " LIMIT 0," . $_SESSION["wpsqt"][$quizName]["sections"][$sectionKey]['limit'];
     } else {
         $end = '';
     }
     $rawQuestions = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPSQT_TABLE_QUESTIONS . "` WHERE section_id = %d ORDER BY " . $orderBy . $end, array($section["id"])), ARRAY_A);
     foreach ($rawQuestions as $rawQuestion) {
         $_SESSION["wpsqt"][$quizName]["sections"][$sectionKey]["questions"][] = Wpsqt_System::unserializeQuestion($rawQuestion, $this->_type);
     }
     require Wpsqt_Core::pageView('site/' . $this->_type . '/section.php');
 }