Inital quiz page
This commit is contained in:
parent
ccc1a23e84
commit
9e917e0f8a
|
@ -49,4 +49,22 @@ namespace TestProject;
|
|||
return $id_arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get question text
|
||||
*
|
||||
* @return string Question text
|
||||
*/
|
||||
public function getText(){
|
||||
return $this->text_str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if answer is correct
|
||||
*
|
||||
* @return bool if is correct
|
||||
*/
|
||||
public function isCorrect(){
|
||||
return $this->correct_bln;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
15
index.php
15
index.php
|
@ -1,7 +1,14 @@
|
|||
<?php
|
||||
use TestProject\User;
|
||||
use TestProject\Quiz;
|
||||
require_once 'init.php';
|
||||
|
||||
if ( ! empty( $_SESSION['user_id'] ) ){
|
||||
$user = new User( $_SESSION['user_id'] );
|
||||
$name_str = $user->getName();
|
||||
$email_str = $user->getEmail();
|
||||
}
|
||||
|
||||
$quizzes_arr = Quiz::getList();
|
||||
?>
|
||||
<!doctype html>
|
||||
|
@ -24,11 +31,11 @@ $quizzes_arr = Quiz::getList();
|
|||
<div class="form-row">
|
||||
<div class="form-group col-md-6">
|
||||
<label for="name">Name</label>
|
||||
<input class="form-control" id="name" name="name" type="text" placeholder="<?php echo $_SESSION['name'] ?? ''; ?>" required>
|
||||
<input class="form-control" id="name" name="name" type="text" value="<?php echo $name_str ?? ''; ?>" />
|
||||
</div>
|
||||
<div class="form-group col-md-6">
|
||||
<label for="email">Email</label>
|
||||
<input class="form-control" id="email" name="email" type="email" placeholder="<?php echo $_SESSION['email'] ?? ''; ?>" required>
|
||||
<label for="email">Email<span class="text-danger">*</span></label>
|
||||
<input class="form-control" id="email" name="email" type="email" value="<?php echo $email_str ?? ''; ?>" required />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
|
@ -49,5 +56,7 @@ $quizzes_arr = Quiz::getList();
|
|||
</form>
|
||||
</main>
|
||||
</div>
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
67
quiz.php
Normal file
67
quiz.php
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
use TestProject\User;
|
||||
use TestProject\Quiz;
|
||||
use TestProject\Question;
|
||||
require_once 'init.php';
|
||||
|
||||
$user = User::find( $_POST['email'], $_POST['name'] );
|
||||
$quiz = new Quiz( $_POST['quiz'] );
|
||||
|
||||
$questID_arr = Question::getList( $quiz->getID() );
|
||||
|
||||
$quest1 = new Question( $questID_arr[0] );
|
||||
|
||||
$_SESSION['user_id'] = $user->getID();
|
||||
?>
|
||||
<html lang=en_GB>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<title>Basic PHP Quiz</title>
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
||||
<script>
|
||||
let id = {
|
||||
user : <?php echo $user->getID(); ?>,
|
||||
quiz : <?php echo $quiz->getID(); ?>,
|
||||
quest : <?php echo json_encode( $questID_arr ); ?>
|
||||
};
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h1 class="text-center"><?php echo $quiz->getName(); ?></h1>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h2 class="text-center" id="question-text"><?php echo $quest1->getText(); ?></h2>
|
||||
</div>
|
||||
</div>
|
||||
<form id="question">
|
||||
<div class="form-row" id="answers">
|
||||
<?php foreach( $quest1->getAnswers() as $answer ){
|
||||
$id = $answer->getID();
|
||||
$text = $answer->getText();
|
||||
?>
|
||||
<div class="col-md-6">
|
||||
<label class="w-100">
|
||||
<input type="checkbox" name="answer" value="<?php echo $id; ?>" />
|
||||
<?php echo $text; ?>
|
||||
</label>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="col">
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
||||
<script src="quiz.js"></script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue