parent
c9f496e2ed
commit
f91b281a88
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
namespace Entity;
|
||||
|
||||
class ResultsEntity
|
||||
{
|
||||
private int $idQuiz;
|
||||
|
||||
public function getIdUser(): int
|
||||
{
|
||||
return $this->idUser;
|
||||
}
|
||||
|
||||
public function setIdUser(int $idUser): void
|
||||
{
|
||||
$this->idUser = $idUser;
|
||||
}
|
||||
|
||||
public function getIdQuiz(): int
|
||||
{
|
||||
return $this->idQuiz;
|
||||
}
|
||||
|
||||
public function setIdQuiz(int $idQuiz): void
|
||||
{
|
||||
$this->idQuiz = $idQuiz;
|
||||
}
|
||||
|
||||
public function getTime(): int
|
||||
{
|
||||
return $this->time;
|
||||
}
|
||||
|
||||
public function setTime(int $time): void
|
||||
{
|
||||
$this->time = $time;
|
||||
}
|
||||
|
||||
public function getNbPts(): int
|
||||
{
|
||||
return $this->nbPts;
|
||||
}
|
||||
|
||||
public function setNbPts(int $nbPts): void
|
||||
{
|
||||
$this->nbPts = $nbPts;
|
||||
}
|
||||
|
||||
private int $idUser;
|
||||
|
||||
private int $nbPts;
|
||||
|
||||
private int $time;
|
||||
|
||||
/**
|
||||
* @param int $idQuiz
|
||||
* @param int $idUser
|
||||
* @param int $time
|
||||
* @param int $nbPts
|
||||
*/
|
||||
public function __construct(int $idQuiz, int $idUser, int $time, int $nbPts)
|
||||
{
|
||||
$this -> idQuiz = $idQuiz;
|
||||
$this -> idUser = $idUser;
|
||||
$this -> time = $time;
|
||||
$this -> nbPts = $nbPts;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
<?php
|
||||
namespace Entity;
|
||||
|
||||
|
||||
class Result_quizEntity
|
||||
{
|
||||
private int $id_quiz;
|
||||
private int $nbQuestion;
|
||||
|
||||
/**
|
||||
* @param int $id_quiz
|
||||
* @param int $nbQuestion
|
||||
*/
|
||||
public function __construct(int $id_quiz, int $nbQuestion)
|
||||
{
|
||||
$this->id_quiz = $id_quiz;
|
||||
$this->nbQuestion = $nbQuestion;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getIdQuiz(): int
|
||||
{
|
||||
return $this->id_quiz;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id_quiz
|
||||
*/
|
||||
public function setIdQuiz(int $id_quiz): void
|
||||
{
|
||||
$this->id_quiz = $id_quiz;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getNbQuestion(): int
|
||||
{
|
||||
return $this->nbQuestion;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $nbQuestion
|
||||
*/
|
||||
public function setNbQuestion(int $nbQuestion): void
|
||||
{
|
||||
$this->nbQuestion = $nbQuestion;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace Gateway;
|
||||
|
||||
use PDO;
|
||||
|
||||
class ResultsGateway
|
||||
{
|
||||
private Connection $co;
|
||||
|
||||
public function __construct(Connection $co)
|
||||
{
|
||||
$this -> co = $co ;
|
||||
}
|
||||
|
||||
public function createResultsGateway(int $idQuiz, int $idUser, int $nbPts, int $time) : bool
|
||||
{
|
||||
$query = "
|
||||
INSERT INTO Results
|
||||
VALUES (:id_quiz, :id_user, :nb_pts, :time)
|
||||
";
|
||||
|
||||
return $this -> co -> executeQuery($query, [
|
||||
'id_quiz' => array($idQuiz, PDO::PARAM_INT),
|
||||
'id_user' => array($idUser, PDO::PARAM_INT),
|
||||
'nb_pts' => array($nbPts, PDO::PARAM_INT),
|
||||
'time' => array($time, PDO::PARAM_INT)
|
||||
]);
|
||||
}
|
||||
|
||||
public function findResultsByQuiz(int $idQuiz) : array
|
||||
{
|
||||
$query = "
|
||||
SELECT * FROM Results
|
||||
WHERE quiz_r = :id_quiz
|
||||
";
|
||||
|
||||
$this -> co -> executeQuery($query, ['id_quiz' => array($idQuiz, PDO::PARAM_INT)]);
|
||||
|
||||
return $this -> co -> getResults();
|
||||
}
|
||||
|
||||
public function findResultsByUser(int $idUser) : array
|
||||
{
|
||||
$query = "
|
||||
SELECT * FROM Results
|
||||
WHERE user_r = :id_user
|
||||
";
|
||||
|
||||
$this -> co -> executeQuery($query, ['id_user' => array($idUser, PDO::PARAM_INT)]);
|
||||
|
||||
return $this -> co -> getResults();
|
||||
}
|
||||
|
||||
public function findResultsById(int $idQuiz, int $idUser) : array
|
||||
{
|
||||
$query = "
|
||||
SELECT * FROM Results
|
||||
WHERE quiz_r = :id_quiz AND user_r = :id_user
|
||||
";
|
||||
|
||||
$this -> co -> executeQuery($query, [
|
||||
'id_user' => array($idUser, PDO::PARAM_INT),
|
||||
'id_quiz' => array($idQuiz, PDO::PARAM_INT)
|
||||
]);
|
||||
|
||||
return $this -> co -> getResults();
|
||||
}
|
||||
|
||||
public function findAllResults() : array
|
||||
{
|
||||
$query = "SELECT * FROM Results";
|
||||
|
||||
$this -> co -> executeQuery($query);
|
||||
|
||||
return $this -> co -> getResults();
|
||||
}
|
||||
|
||||
public function updateResults(int $idQuiz, int $idUser, ?int $score, ?int $time) : bool
|
||||
{
|
||||
if ($score && !$time)
|
||||
{
|
||||
$query = "
|
||||
UPDATE Results
|
||||
SET score = :score
|
||||
WHERE quiz_r = :id_quiz AND user_r = :id_user
|
||||
";
|
||||
|
||||
return $this -> co -> executeQuery($query, [
|
||||
'id_quiz' => array($idQuiz, PDO::PARAM_INT),
|
||||
'id_user' => array($idUser, PDO::PARAM_INT),
|
||||
'score' => array($score, PDO::PARAM_INT)
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
else if (!$score && $time)
|
||||
{
|
||||
$query = "
|
||||
UPDATE Results
|
||||
SET time = :time
|
||||
WHERE quiz_r = :id_quiz AND user_r = :id_user
|
||||
";
|
||||
|
||||
return $this -> co -> executeQuery($query, [
|
||||
'id_quiz' => array($idQuiz, PDO::PARAM_INT),
|
||||
'id_user' => array($idUser, PDO::PARAM_INT),
|
||||
'time' => array($time, PDO::PARAM_INT)
|
||||
]);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
$query = "
|
||||
UPDATE Results
|
||||
SET score = :score AND time = :time
|
||||
WHERE quiz_r = :id_quiz AND user_r = :id_user
|
||||
";
|
||||
|
||||
return $this -> co -> executeQuery($query, [
|
||||
'id_quiz' => array($idQuiz, PDO::PARAM_INT),
|
||||
'id_user' => array($idUser, PDO::PARAM_INT),
|
||||
'score' => array($score, PDO::PARAM_INT),
|
||||
'time' => array($time, PDO::PARAM_INT)
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace Model;
|
||||
|
||||
use Entity\ResultsEntity;
|
||||
use Gateway\ResultsGateway;
|
||||
|
||||
class ResultsModel
|
||||
{
|
||||
private ResultsGateway $gw;
|
||||
|
||||
public function __construct(ResultsGateway $gw)
|
||||
{
|
||||
$this -> gw = $gw;
|
||||
}
|
||||
|
||||
public function createResultsModel(int $idQuiz, int $idUser, int $score, int $time) : bool
|
||||
{
|
||||
return $this -> gw -> createResultsGateway($idQuiz, $idUser, $score, $time);
|
||||
}
|
||||
|
||||
public function getResultsByQuiz(int $idQuiz) : array
|
||||
{
|
||||
$res = $this -> gw -> findResultsByQuiz($idQuiz);
|
||||
|
||||
$results = [];
|
||||
|
||||
foreach ($res as $result)
|
||||
{
|
||||
$results[] = new ResultsEntity (
|
||||
$result['user_r'],
|
||||
$result['quiz_r'],
|
||||
$result['score'],
|
||||
$result['time']
|
||||
);
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function getResultsByUser(int $idUser) : array
|
||||
{
|
||||
$res = $this -> gw -> findResultsByUser($idUser);
|
||||
|
||||
$results = [];
|
||||
|
||||
foreach ($res as $result)
|
||||
{
|
||||
$results[] = new ResultsEntity (
|
||||
$result['user_r'],
|
||||
$result['quiz_r'],
|
||||
$result['score'],
|
||||
$result['time']
|
||||
);
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function getResultsById(int $idQuiz, int $idUser) : ?ResultsEntity
|
||||
{
|
||||
$res = $this -> gw -> findResultsById($idQuiz, $idUser);
|
||||
|
||||
if ($res)
|
||||
{
|
||||
return new ResultsEntity (
|
||||
$res['user_r'],
|
||||
$res['quiz_r'],
|
||||
$res['score'],
|
||||
$res['time']
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getAllResults() : array
|
||||
{
|
||||
$res = $this -> gw -> findAllResults();
|
||||
|
||||
$results = [];
|
||||
|
||||
foreach ($res as $result)
|
||||
{
|
||||
$results[] = new ResultsEntity (
|
||||
$result['user_r'],
|
||||
$result['quiz_r'],
|
||||
$result['score'],
|
||||
$result['time']
|
||||
);
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function updateResultsModel(int $idQuiz, int $idUser, ?int $score, ?int $time) : bool
|
||||
{
|
||||
return $this -> gw -> updateResults($idQuiz, $idUser, $score, $time);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue