2023-06-27 14:31:55 +02:00
|
|
|
<?php
|
|
|
|
class Database {
|
|
|
|
public PDO $pdo_article;
|
2023-06-28 20:38:52 +02:00
|
|
|
public PDO $pdo_teams;
|
2023-06-27 14:31:55 +02:00
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
$data_path = "/../data/";
|
|
|
|
try {
|
2023-09-02 01:00:27 +02:00
|
|
|
// Création des bases de données
|
|
|
|
// Base des énigmes :
|
2023-06-27 14:31:55 +02:00
|
|
|
$this->pdo_article = new PDO("sqlite:" . dirname(__FILE__) . $data_path . "article.db");
|
2023-06-28 20:38:52 +02:00
|
|
|
$this->pdo_article->query('CREATE TABLE IF NOT EXISTS "puzzles" (
|
|
|
|
"id" INTEGER NOT NULL UNIQUE,
|
2023-09-02 01:00:27 +02:00
|
|
|
"title" TEXT NOT NULL,
|
2023-06-28 20:38:52 +02:00
|
|
|
"text" TEXT NOT NULL,
|
|
|
|
"hint" TEXT,
|
2023-09-02 01:00:27 +02:00
|
|
|
"answer" TEXT NOT NULL,
|
|
|
|
"location" TEXT NOT NULL,
|
2023-06-28 20:38:52 +02:00
|
|
|
"code" TEXT NOT NULL,
|
|
|
|
PRIMARY KEY("id" AUTOINCREMENT)
|
|
|
|
)');
|
|
|
|
|
2023-09-02 01:00:27 +02:00
|
|
|
// Base des équipes :
|
2023-06-28 20:38:52 +02:00
|
|
|
$this->pdo_teams = new PDO("sqlite:" . dirname(__FILE__) . $data_path . "teams.db");
|
|
|
|
$this->pdo_teams->query('CREATE TABLE IF NOT EXISTS "teams" (
|
|
|
|
"id" INTEGER NOT NULL UNIQUE,
|
2023-09-02 01:00:27 +02:00
|
|
|
"bonus" INTEGER NOT NULL,
|
2023-06-28 20:38:52 +02:00
|
|
|
PRIMARY KEY("id" AUTOINCREMENT)
|
|
|
|
)');
|
2023-06-28 21:20:16 +02:00
|
|
|
|
|
|
|
$this->pdo_teams->query('CREATE TABLE IF NOT EXISTS "solved" (
|
|
|
|
"puzzle_id" INTEGER NOT NULL,
|
|
|
|
"team_id" INTEGER NOT NULL
|
|
|
|
)');
|
2023-09-02 01:00:27 +02:00
|
|
|
|
|
|
|
$this->pdo_teams->query('CREATE TABLE IF NOT EXISTS "members" (
|
|
|
|
"name" TEXT NOT NULL,
|
|
|
|
"team_id" INTEGER NOT NULL
|
|
|
|
)');
|
2023-06-27 14:31:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
catch (PDOException $exception) {
|
|
|
|
var_dump($exception);
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-02 02:36:37 +02:00
|
|
|
public function checkTeamExists(int $id) {
|
|
|
|
$stmt = $this->pdo_teams->prepare("SELECT * FROM teams WHERE id == :id");
|
|
|
|
$stmt->bindValue(":id", $id);
|
|
|
|
$stmt->execute();
|
|
|
|
return !empty($stmt->fetch());
|
|
|
|
}
|
|
|
|
|
2023-09-02 06:19:09 +02:00
|
|
|
public function getArticleNb() {
|
|
|
|
$query = $this->pdo_article->query("SELECT COUNT(*) FROM puzzles");
|
|
|
|
return $query->fetch()["COUNT(*)"];
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkTeamBonus(int $team) {
|
|
|
|
// $team doit être une équipe existante :
|
|
|
|
$query = $this->pdo_teams->query("SELECT bonus FROM teams WHERE id = " . $team);
|
|
|
|
return $query->fetch()[0] == 1;
|
|
|
|
}
|
2023-06-28 20:38:52 +02:00
|
|
|
|
2023-09-02 01:00:27 +02:00
|
|
|
// public function getTeamsNb() {
|
|
|
|
// $query = $this->pdo_teams->query("SELECT COUNT(*) FROM teams");
|
|
|
|
// return $query->fetch()["COUNT(*)"];
|
|
|
|
// }
|
2023-06-27 14:31:55 +02:00
|
|
|
}
|
|
|
|
?>
|