mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2025-06-25 07:00:29 +02:00
Phase 2 : questions (en cours)
This commit is contained in:
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";
|
Reference in New Issue
Block a user