mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2024-12-05 02:06:52 +00:00
Phase 2 : questions (en cours)
This commit is contained in:
parent
c3aa0386f2
commit
3b54b75395
@ -3,7 +3,9 @@
|
||||
require_once "server_files/config.php";
|
||||
|
||||
require_once "server_files/classes/Document.php";
|
||||
require_once "server_files/classes/DocumentType.php";
|
||||
require_once "server_files/classes/Phase.php";
|
||||
require_once "server_files/classes/Question.php";
|
||||
require_once "server_files/classes/Reason.php";
|
||||
require_once "server_files/classes/Role.php";
|
||||
require_once "server_files/classes/SchoolClass.php";
|
||||
@ -45,6 +47,7 @@ $ROUTES["^inscription/?$"] = ["server_files/controllers/inscription.php"];
|
||||
$ROUTES["^mon-compte/?$"] = ["server_files/controllers/mon_compte.php"];
|
||||
$ROUTES["^mon-equipe/(modifier)/?$"] = ["server_files/controllers/mon_equipe.php", "modifier"];
|
||||
$ROUTES["^mon-equipe/?$"] = ["server_files/controllers/mon_equipe.php"];
|
||||
$ROUTES["^poser-questions-2$"] = ["server_files/controllers/poser_questions.php"];
|
||||
$ROUTES["^probleme/([1-4])/?$"] = ["server_files/controllers/probleme.php", "probleme"];
|
||||
$ROUTES["^rejoindre_equipe/?$"] = ["server_files/controllers/rejoindre_equipe.php"];
|
||||
$ROUTES["^videos-solutions/?$"] = ["server_files/controllers/videos_solutions.php"];
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -1,8 +1,5 @@
|
||||
<?php
|
||||
|
||||
if ($_SESSION["role"] != Role::ADMIN)
|
||||
require_once "server_files/403.php";
|
||||
|
||||
$has_error = false;
|
||||
$error_message = null;
|
||||
|
||||
|
69
server_files/controllers/poser_questions.php
Normal file
69
server_files/controllers/poser_questions.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
if (!isset($_SESSION["user_id"]) || $_SESSION["role"] != Role::PARTICIPANT && $_SESSION["role"] != Role::ENCADRANT)
|
||||
require_once "server_files/403.php";
|
||||
|
||||
/** @var Team $team */
|
||||
$team = $_SESSION["team"];
|
||||
|
||||
if ($team == null)
|
||||
require_once "server_files/403.php";
|
||||
|
||||
$has_error = false;
|
||||
$error_message = null;
|
||||
|
||||
if (isset($_POST["give_questions"])) {
|
||||
$give_questions = new GiveQuestions($_POST);
|
||||
try {
|
||||
$give_questions->makeVerifications();
|
||||
$give_questions->giveQuestions();
|
||||
} catch (AssertionError $e) {
|
||||
$has_error = true;
|
||||
$error_message = $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
class GiveQuestions
|
||||
{
|
||||
private $to;
|
||||
private $to_team;
|
||||
private $question_0;
|
||||
private $question_1;
|
||||
private $question_2;
|
||||
private $question_3;
|
||||
private $question_4;
|
||||
private $question_5;
|
||||
|
||||
public function __construct($data)
|
||||
{
|
||||
foreach ($data as $key => $value) {
|
||||
$this->$key = $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function makeVerifications()
|
||||
{
|
||||
$this->to_team = Team::fromId($this->to);
|
||||
ensure($this->to_team, "L'équipe indiquée n'existe pas.");
|
||||
}
|
||||
|
||||
public function giveQuestions()
|
||||
{
|
||||
global $DB, $team;
|
||||
|
||||
$DB->exec("DELETE FROM `questions` WHERE `from` = " . $team->getId() . " AND `to` = $this->to;");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @var Team[] $receivers
|
||||
* @var Video[] $videos
|
||||
* @var Question[][] $questions
|
||||
*/
|
||||
$receivers = [Team::fromId($team->getVideoTeamIds()[0]), Team::fromId($team->getVideoTeamIds()[1])];
|
||||
$videos = [Video::getVideo(Reason::SOLUTION, $receivers[0], Video::ACCEPTED),
|
||||
Video::getVideo(Reason::SOLUTION, $receivers[1], Video::ACCEPTED)];
|
||||
$questions = [Question::getQuestions($team, $receivers[0]),
|
||||
Question::getQuestions($team, $receivers[1])];
|
||||
|
||||
require_once "server_files/views/poser_questions.php";
|
@ -60,6 +60,9 @@
|
||||
case Phase::PHASE1: ?>
|
||||
<li><a href="<?= $URL_BASE ?>/envoyer-video-1">Envoyer ma vidéo (phase 1)</a></li>
|
||||
<?php break;
|
||||
case Phase::PHASE2: ?>
|
||||
<li><a href="<?= $URL_BASE ?>/poser-questions-2">Poser des questions (phase 2)</a></li>
|
||||
<?php break;
|
||||
}
|
||||
} ?>
|
||||
<?php } ?>
|
||||
|
37
server_files/views/poser_questions.php
Normal file
37
server_files/views/poser_questions.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
require_once "header.php";
|
||||
|
||||
for ($i = 0; $i < 2; ++$i) {
|
||||
$receiver = $receivers[$i];
|
||||
$video = $videos[$i]; ?>
|
||||
<h2>Questions pour l'équipe <?= $receiver->getName() ?> (<?= $receiver->getTrigram() ?>) :</h2>
|
||||
Lien de la vidéo : <a href="<?= $video->getLink() ?>"><?= $video->getLink() ?></a><br/>
|
||||
<?php displayVideo($video->getLink()) ?>
|
||||
<br/>
|
||||
<form method="POST">
|
||||
<input type="hidden" name="to" value="<?= $receiver->getTrigram() ?>"/>
|
||||
<table style="width: 100%;">
|
||||
<tbody>
|
||||
<?php
|
||||
for ($j = 0; $j < 6; ++$j) { ?>
|
||||
<tr>
|
||||
<td style="width: 30%;">
|
||||
<label for="question_<?= $j + 1 ?>">Question <?= $j + 1 ?> :</label>
|
||||
</td>
|
||||
<td style="width: 70%;">
|
||||
<textarea style="width: 100%;" id="question_<?= $j + 1 ?>" name="question_<?= $j + 1 ?>"><?= $questions[$i][$j]->getQuestion() ?></textarea>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<input style="width: 100%;" type="submit" name="give_questions" value="Poser les questions" />
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
<hr/>
|
||||
<?php }
|
||||
|
||||
require_once "footer.php";
|
Loading…
Reference in New Issue
Block a user