Ejemplo n.º 1
0
 public function convert()
 {
     foreach (glob("Model/Json/*.json") as $filename) {
         $oldquiz = json_decode(file_get_contents($filename), true);
         $newquiz = new Quiz($oldquiz["name"], $oldquiz["description"]);
         foreach ($oldquiz["questions"] as $q) {
             $newquiz->addQuestion(new QuizQuestion($q["question"], $q["option"], $q["correct"]));
         }
         file_put_contents("Model/quizes/" . basename($filename) . ".bin", serialize($newquiz));
     }
 }
 if ($mode == "simple" || $mode == "accurate") {
     require "../modules/variables.php";
     $numResults = $quiz->getResultsMulti("count");
     //function in quiz.php
     // Insert the questions and options
     $questionArray = explode("_", $_POST['optionCounts']);
     //array explode ( string $delimiter , string $string [, int $limit ] )
     //explode a string by the delimitor to array
     $question = array();
     for ($i = 0; $i < $_POST['questionCount']; $i++) {
         if (isset($_POST['question_' . $i])) {
             if (isset($_POST['uq' . $i])) {
                 // uq:updateQuestion
                 $question_id = $quiz->updateQuestion($_POST['question_' . $i], $_POST['uq' . $i], $member->id);
             } else {
                 $question_id = $quiz->addQuestion($_POST['question_' . $i], $member->id);
             }
         }
         if ($mode == "simple") {
             for ($j = 0; $j < $questionArray[$i]; $j++) {
                 if (isset($_POST['q' . $i . 'o' . $j]) && isset($_POST['q' . $i . 'r' . $j])) {
                     if (isset($_POST['uq' . $i . 'o' . $j])) {
                         $quiz->updateOptionMulti($_POST['q' . $i . 'o' . $j], $_POST['q' . $i . 'r' . $j], 1, $_POST['uq' . $i . 'o' . $j], $member->id);
                         //default of weightage = 1
                     }
                     if (!isset($_POST['uq' . $i . 'o' . $j])) {
                         //function from quiz.php: addOptionMulti($option, $result, $weightage, $question, $memberID)
                         $quiz->addOptionMulti($_POST['q' . $i . 'o' . $j], $_POST['q' . $i . 'r' . $j], 1, $question_id, $member->id);
                         //default of weightage = 1
                     }
                 }
Ejemplo n.º 3
0
                        $quiz = new Quiz();
                        //get the quiz_id here to use for inserting questions
                        $quiz_id = $quiz->createQuiz($title, $des, $cat, $quiz_picture, $memberid, 'Admin', $display_mode, 2);
                    }
                    //check if the question is null. If not, insert into database.
                    if ($question != null) {
                        ?>
  <tr bgcolor="#FFCCFF">
    <td><span class="style5">Question:</span></td>
    <td><?php 
                        echo $question;
                        ?>
</td>
  </tr>
  <?php 
                        $question_id = $quiz->addQuestion($question, $memberid);
                    }
                    //check if the option is null. If not, insert into database with reference
                    if ($option != null) {
                        ?>
  <tr>
    <td align="right"><span class="style5"><input type="radio" disabled="disabled"/></span></td>
    <td><?php 
                        echo $option;
                        ?>
</td>
    <td><span class="style5">Result contributed to? </span></td>
    <td><?php 
                        echo $result_t;
                        ?>
</td><td><?php 
Ejemplo n.º 4
0
 public function CreateAQuiz($data)
 {
     // denna skapar quizen
     $title = "";
     // sätter titeln till tom
     $description = "no description";
     if (isset($data["title"]) && trim($data["title"]) != "") {
         $title = $data["title"];
     }
     if (isset($data["description"]) && trim($data["description"]) != "") {
         $description = $data["description"];
     }
     $quiz = new Quiz($title, $description);
     if ($data["questions"] == null || $title == "") {
         throw new Exception("No questions in quiz");
     }
     if (strip_tags($title) != $title || strip_tags($description) != $description) {
         throw new Exception("No tags in my quiz");
     }
     $questioncount = 0;
     foreach ($data["questions"] as $q) {
         if (strip_tags($q["title"]) != $q["title"]) {
             throw new Exception("No tags in questions in my quiz");
         }
         if (!isset($q["options"])) {
             continue;
         }
         $options = array();
         $correcModifier = 0;
         $currentOption = 1;
         foreach ($q["options"] as $o) {
             if (trim($o) == "") {
                 if ($q["correct"] > $currentOption) {
                     // om den optionen man är på är mindre än den option som är rätt så plussar den på correct svaret
                     $correcModifier++;
                 }
                 $currentOption++;
                 //och plussar på den man är på så man kan kolla nästa
                 continue;
             }
             if (strip_tags($o) != $o) {
                 throw new Exception("No tags in option in my quiz");
             }
             $currentOption++;
             array_push($options, $o);
             //lägger in allt i arrayen
         }
         if (count($options) == 0) {
             continue;
         }
         $correct = min($q["correct"] - 1 - $correcModifier, count($options) - 1);
         //denna modifiererar den tar det lägsta i options och sätter om det rätta till den nya anpassade listan (Fick hjälp med denna!)
         $questioncount++;
         $quiz->addQuestion(new QuizQuestion($q["title"], $options, $correct));
     }
     if ($questioncount == 0) {
         throw new Exception("No questions in quiz");
     }
     $count = "";
     while (file_exists("Model/quizes/" . $quiz->getTitle() . $count . ".bin")) {
         if ($count == "") {
             $count = 1;
         } else {
             $count++;
         }
     }
     $this->quizDAL->writeToBin("Model/quizes/" . $quiz->getTitle() . $count . ".bin", $quiz);
 }