本文整理汇总了PHP中Quiz::addQuestion方法的典型用法代码示例。如果您正苦于以下问题:PHP Quiz::addQuestion方法的具体用法?PHP Quiz::addQuestion怎么用?PHP Quiz::addQuestion使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Quiz
的用法示例。
在下文中一共展示了Quiz::addQuestion方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: convert
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));
}
}
示例2: explode
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
}
}
示例3: Quiz
$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
示例4: CreateAQuiz
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);
}