You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
3.01-QCM_MuscuMaths/Website/gateways/GatewayJouer.php

71 lines
2.2 KiB

<?php
namespace gateways;
use usages\Connection;
use \PDO;
class GatewayJouer
{
private $con;
public function __construct()
{
global $dns, $user, $pass;
$this->con = new Connection($dns, $user, $pass);
}
public function addJouer($jouer)
{
$query = "INSERT into jouer(idChapter,idPlayer,numScore) values (:idChapter,:idPlayer,:numScore);";
$this->con->executeQuery(
$query,
array(
'idChapter' => array($jouer['idChapter'], PDO::PARAM_STR),
'idPlayer' => array($jouer['idPlayer'], PDO::PARAM_STR),
':numScore' => array($jouer['numScore'], PDO::PARAM_INT)
)
);
}
public function getJouerByPlayerAndChapter(int $idPlayer, int $idChapter)
{
$query = "SELECT jouer.numScore FROM jouer,player WHERE jouer.idPlayer = :idPlayer AND jouer.idPlayer = player.id AND jouer.idChapter = :idChapter AND jouer.idChapter = chapter.id ;";
$this->con->executeQuery(
$query,
array(
':idChapter' => array($idChapter, PDO::PARAM_INT),
':idPlayer' => array($idPlayer, PDO::PARAM_INT)
)
);
$results = $this->con->getResults();
return $results[0];
}
public function updateJouer($idPlayer, $idChapter, $jouer)
{
$query = "UPDATE jouer SET numScore = :numScore WHERE idPlayer = :idPlayer AND idChapter = :idChapter;";
$this->con->executeQuery(
$query,
array(
':idChapter' => array($idChapter, PDO::PARAM_INT),
':idPlayer' => array($idPlayer, PDO::PARAM_INT),
':numScore' => array($jouer['numScore'], PDO::PARAM_INT)
)
);
}
public function verifyJouer($idChapter, $idPlayer)
{
$query = "SELECT jouer.idChapter, jouer.idPlayer FROM jouer WHERE idPlayer = :idPlayer AND idChapter = :idChapter";
$this->con->executeQuery(
$query,
array(
':idChapter' => array($idChapter, PDO::PARAM_STR),
':idPlayer' => array($idPlayer, PDO::PARAM_STR)
)
);
$results = $this->con->getResults();
return $results[0];
}
}