php-test/classes/quiz.class.php

65 lines
1.1 KiB
PHP

<?php
namespace TestProject;
/*
* Quiz class
*/
class Quiz {
private const tb_str = 'quiz';
private const resulTb_str = 'quiz_result';
private $id_int;
private $name_str;
private $maxScore_int;
/**
* Load quiz
*
* @param int $id_int ID of quiz to load
*/
public function __construct( int $id_int ){
$db = DB::getDB();
$rows_arr = $db->select( self::tb_str, array(), array( 'id' => $id_int ) );
if ( empty( $rows_arr ) ){
throw new \RuntimeException( 'Invalid quiz ID' );
}
$this->id_int = $rows_arr[0]['id'];
$this->name_str = $rows_arr[0]['name'];
$this->maxScore_int = $rows_arr[0]['max_score'];
}
/**
* Get a list of quiz IDs and names
*
* @return string[] Array of quiz names keyed by id
*/
public static function getList(){
$db = DB::getDB();
$quiz_arr = $db->select( self::tb_str, array( 'id', 'name' ) );
return $quiz_arr;
}
/**
* Get name of Quiz
*
* @return string Name
*/
public function getName(){
return $this->name_str;
}
/**
* Get Maximum possible Score of quiz
*
* @return int Max score
*/
public function getMaxScore(){
return $this->maxScore_int;
}
}