2019-09-20 12:57:06 +00:00
|
|
|
<?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;
|
2019-09-21 10:21:42 +00:00
|
|
|
/**
|
|
|
|
* @var Team $to_team
|
|
|
|
*/
|
2019-09-20 12:57:06 +00:00
|
|
|
private $to_team;
|
|
|
|
private $question_1;
|
|
|
|
private $question_2;
|
|
|
|
private $question_3;
|
|
|
|
private $question_4;
|
|
|
|
private $question_5;
|
2019-09-21 10:21:42 +00:00
|
|
|
private $question_6;
|
2019-09-20 12:57:06 +00:00
|
|
|
|
|
|
|
public function __construct($data)
|
|
|
|
{
|
|
|
|
foreach ($data as $key => $value) {
|
|
|
|
$this->$key = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function makeVerifications()
|
|
|
|
{
|
2019-09-21 10:21:42 +00:00
|
|
|
global $team;
|
|
|
|
|
|
|
|
$this->to_team = Team::fromTrigram($this->to);
|
2019-09-20 12:57:06 +00:00
|
|
|
ensure($this->to_team, "L'équipe indiquée n'existe pas.");
|
2019-09-21 10:21:42 +00:00
|
|
|
ensure($team->getProblem() == $this->to_team->getProblem(), "Les équipes ne travaillent pas sur le même problème.");
|
|
|
|
ensure($this->question_1 == null || $this->question_1 == "" || $this->question_2 == null || $this->question_2 == "" || $this->question_3 == null || $this->question_3 == "",
|
|
|
|
"Vous devez poser au moins 3 questions.");
|
2019-09-20 12:57:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function giveQuestions()
|
|
|
|
{
|
|
|
|
global $DB, $team;
|
|
|
|
|
2019-09-21 10:21:42 +00:00
|
|
|
$DB->exec("DELETE FROM `questions` WHERE `from` = " . $team->getId() . " AND `to` = " . $this->to_team->getId() . ";");
|
|
|
|
$req = $DB->prepare("INSERT INTO `questions`(`from`, `to`, `problem`, `question`) VALUES "
|
|
|
|
. "(?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?);");
|
|
|
|
$req->execute([$team->getId(), $this->to_team->getId(), $team->getProblem(), $this->question_1,
|
|
|
|
$team->getId(), $this->to_team->getId(), $team->getProblem(), $this->question_2,
|
|
|
|
$team->getId(), $this->to_team->getId(), $team->getProblem(), $this->question_3,
|
|
|
|
$team->getId(), $this->to_team->getId(), $team->getProblem(), $this->question_4,
|
|
|
|
$team->getId(), $this->to_team->getId(), $team->getProblem(), $this->question_5,
|
|
|
|
$team->getId(), $this->to_team->getId(), $team->getProblem(), $this->question_6]);
|
2019-09-20 12:57:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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";
|