This commit is contained in:
Daniel Mason 2017-01-01 00:23:57 +13:00
parent b6876e601e
commit 0824aca6b9
4 changed files with 42 additions and 9 deletions

View File

@ -28,4 +28,9 @@ class Answer extends DataItem
{ {
return $this->answerdata_correct; return $this->answerdata_correct;
} }
public static function checkIfCorrect($answer)
{
}
} }

View File

@ -8,10 +8,11 @@ class DataItem {
$this->_db = new db(); //Will optimise this to get existing conn at some point. $this->_db = new db(); //Will optimise this to get existing conn at some point.
} }
public function getById($id) { public static function getById($id) {
$this->_db->query("SELECT * FROM `".static::_getType()."` WHERE ".static::_getType()."_id = :id"); $db = new db();
$this->_db->bind(":id", $id); $db->query("SELECT * FROM `".static::_getType()."` WHERE ".static::_getType()."_id = :id");
return $this->_db->getObject(); $db->bind(":id", $id);
return $db->getObject();
} }
private function _getAllWhere($where = false, $orderBy = false, $join = false, $limit = false) { private function _getAllWhere($where = false, $orderBy = false, $join = false, $limit = false) {

View File

@ -38,6 +38,11 @@ class Question extends DataItem {
return Answer::getAllWhere("answerdata_question = ".$this->getId()); return Answer::getAllWhere("answerdata_question = ".$this->getId());
} }
public function getCorrectAnswer()
{
return Answer::getWhere("answerdata_question = ".$this->getId()." and answerdata_correct = 1");
}
public function getImage() public function getImage()
{ {
return $this->questiondata_image; return $this->questiondata_image;

View File

@ -1,7 +1,10 @@
<?php <?php
require_once('includes/include.php'); require_once('includes/include.php');
define('QUESTION_COUNT', 60); //How many questions to ask. $questions = [];
$questions = Question::getQuestions(QUESTION_COUNT); if(!isset($_POST['mark'])) {
define('QUESTION_COUNT', 60); //How many questions to ask.
$questions = Question::getQuestions(QUESTION_COUNT);
}
?><!doctype html> ?><!doctype html>
<html class="no-js" lang=""> <html class="no-js" lang="">
<head> <head>
@ -20,7 +23,23 @@ $questions = Question::getQuestions(QUESTION_COUNT);
<div id="container"> <div id="container">
<div id="header"><h1>Unofficial NZART Practice Exam</h1></div> <div id="header"><h1>Unofficial NZART Practice Exam</h1></div>
<div id="body" class="center"> <div id="body" class="center">
<?php if(isset($_POST['mark'])) {
?><a href="/">Return to new Questions</a><br/><br/><?php
unset($_POST['mark']);
foreach($_POST as $i=>$q) {
$question = Question::getById($i);
$answer = Answer::getById($q);
echo $question->getQuestion()."<br>";
if($answer->isCorrect()) {
echo "Correct - ".$answer->getAnswer()."<br>";
} else {
$corAnswer = $question->getCorrectAnswer();
echo "Wrong.<br>Your Answer: ".$answer->getAnswer()."<br>Correct Answer:".$corAnswer->getAnswer();
}
}
} else { ?>
60 Questions 60 Questions
<form action="/" method="POST">
<table> <table>
<tbody> <tbody>
<?php <?php
@ -28,7 +47,7 @@ $questions = Question::getQuestions(QUESTION_COUNT);
foreach($questions as $i=>$q) { foreach($questions as $i=>$q) {
echo "<tr>"; echo "<tr>";
echo "<td>".($i+1)."</td>"; echo "<td>".($i+1)."</td>";
echo "<td>".$q->getQuestion()."</td>"; echo "<td style='padding-left:10px'>".$q->getQuestion()."</td>";
echo "</tr>"; echo "</tr>";
if(!empty($q->getImage())) { if(!empty($q->getImage())) {
echo "<tr>"; echo "<tr>";
@ -37,15 +56,18 @@ $questions = Question::getQuestions(QUESTION_COUNT);
} }
foreach($q->answers as $x=>$ans) { foreach($q->answers as $x=>$ans) {
echo "<tr>"; echo "<tr>";
echo "<td style='padding-left:10px'>".$letters[$x]."</td>"; echo "<td></td>";
echo "<td style='padding-left:10px'>".$ans->getAnswer()."</td>"; echo "<td style='padding-left:10px'><input type='radio' name='".$q->getId()."' value='".$ans->getId()."'> ".($letters[$x]." ".$ans->getAnswer())."</td>";
echo "</tr>"; echo "</tr>";
} }
echo "<tr><td>&nbsp;</td><td></td></tr>"; echo "<tr><td>&nbsp;</td><td></td></tr>";
} }
?> ?>
<tr><td></td><td><input type="hidden" name="mark" value="1"><button type="submit">Submit</button></td></tr>
</tbody> </tbody>
</table> </table>
</form>
<?php } ?>
</div> </div>
<div id="footer"> <div id="footer">
All Questions and images from NZART question bank located All Questions and images from NZART question bank located