mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2025-06-24 09:08:47 +02:00
Phase 2 : questions (en cours)
This commit is contained in:
@ -96,29 +96,3 @@ class Document
|
||||
return $docs;
|
||||
}
|
||||
}
|
||||
|
||||
class DocumentType
|
||||
{
|
||||
const PHOTO_CONSENT = 0;
|
||||
|
||||
public static function getTranslatedName($type) {
|
||||
switch ($type) {
|
||||
default:
|
||||
return "Autorisation de droit à l'image";
|
||||
}
|
||||
}
|
||||
|
||||
public static function getName($type) {
|
||||
switch ($type) {
|
||||
default:
|
||||
return "PHOTO_CONSENT";
|
||||
}
|
||||
}
|
||||
|
||||
public static function fromName($name) {
|
||||
switch ($name) {
|
||||
default:
|
||||
return self::PHOTO_CONSENT;
|
||||
}
|
||||
}
|
||||
}
|
28
server_files/classes/DocumentType.php
Normal file
28
server_files/classes/DocumentType.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
|
||||
class DocumentType
|
||||
{
|
||||
const PHOTO_CONSENT = 0;
|
||||
|
||||
public static function getTranslatedName($type) {
|
||||
switch ($type) {
|
||||
default:
|
||||
return "Autorisation de droit à l'image";
|
||||
}
|
||||
}
|
||||
|
||||
public static function getName($type) {
|
||||
switch ($type) {
|
||||
default:
|
||||
return "PHOTO_CONSENT";
|
||||
}
|
||||
}
|
||||
|
||||
public static function fromName($name) {
|
||||
switch ($name) {
|
||||
default:
|
||||
return self::PHOTO_CONSENT;
|
||||
}
|
||||
}
|
||||
}
|
91
server_files/classes/Question.php
Normal file
91
server_files/classes/Question.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
|
||||
class Question
|
||||
{
|
||||
private $id;
|
||||
private $from;
|
||||
private $to;
|
||||
private $problem;
|
||||
private $question;
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public static function fromId($id)
|
||||
{
|
||||
global $DB;
|
||||
|
||||
$req = $DB->prepare("SELECT * FROM `questions` WHERE `id` = ?;");
|
||||
$req->execute(htmlspecialchars($id));
|
||||
$data = $req->fetch();
|
||||
|
||||
if ($data === false)
|
||||
return null;
|
||||
|
||||
$question = new Question();
|
||||
$question->fill($data);
|
||||
return $question;
|
||||
}
|
||||
|
||||
public function fill($data)
|
||||
{
|
||||
foreach ($data as $key => $value)
|
||||
$this->$key = $value;
|
||||
}
|
||||
|
||||
public static function getQuestions(Team $from, Team $to)
|
||||
{
|
||||
global $DB;
|
||||
|
||||
ensure($from->getProblem() == $to->getProblem(), "Les deux équipes doivent travailler sur le même problème.");
|
||||
|
||||
$req = $DB->prepare("SELECT * FROM `questions` WHERE `from` = ? AND `to` = ?;");
|
||||
$req->execute([$from->getId(), $to->getId()]);
|
||||
|
||||
$questions = [];
|
||||
|
||||
while (($data = $req->fetch()) !== false) {
|
||||
$question = new Question();
|
||||
$question->fill($data);
|
||||
$questions[] = $question;
|
||||
}
|
||||
|
||||
if (sizeof($questions) == 0) {
|
||||
$default_questions = ["Slogan ?", "Est-ce que les blagues de R-ev sont drôles ?", "C'est où le WEI ?", "Qui est le plus lourd ?", "Quelle est la réponse à la vie, à l'univers et à tout le reste ?", "Que préférez-vous entre la pratique et la théorie ?"];
|
||||
for ($_ = 0; $_ < 6; ++$_) {
|
||||
$req = $DB->prepare("INSERT INTO `questions`(`from`, `to`, `problem`, `question`) VALUES (?, ?, ?, ?);");
|
||||
$req->execute([$from->getId(), $to->getId(), $from->getProblem(), $default_questions[$_]]);
|
||||
}
|
||||
return self::getQuestions($from, $to);
|
||||
}
|
||||
|
||||
return $questions;
|
||||
}
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getFrom()
|
||||
{
|
||||
return $this->from;
|
||||
}
|
||||
|
||||
public function getTo()
|
||||
{
|
||||
return $this->to;
|
||||
}
|
||||
|
||||
public function getProblem()
|
||||
{
|
||||
return $this->problem;
|
||||
}
|
||||
|
||||
public function getQuestion()
|
||||
{
|
||||
return $this->question;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user