makeVerifications(); $give_questions->giveQuestions(); } catch (AssertionError $e) { $has_error = true; $error_message = $e->getMessage(); } } class GiveQuestions { private $to; /** * @var Team $to_team */ private $to_team; private $question_1; private $question_2; private $question_3; private $question_4; private $question_5; private $question_6; private $no_drawing; private $files; public function __construct($data, $files) { foreach ($data as $key => $value) { $this->$key = $value; } $this->files = []; for ($i = 1; $i <= 6; ++$i) $this->files[] = strlen($files["file_$i"]["name"]) > 0 ? $files["file_$i"] : null; } public function makeVerifications() { global $LOCAL_PATH, $team; $this->to_team = Team::fromTrigram($this->to); ensure($this->to_team, "L'équipe indiquée n'existe pas."); 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."); ensure(sizeof($_FILES) == 0 || $this->no_drawing, "Vous devez confirmer ne pas avoir inclus de texte dans vos pièces jointes."); for ($i = 0; $i < 6; ++$i) { ensure($this->files[$i]["size"] <= 2e6, "Le fichier doit peser moins que 2 Mo."); ensure(!$this->files[$i]["error"], "Une erreur est survenue."); //ensure(finfo_file(finfo_open(FILEINFO_MIME_TYPE), $this->files[$i]["tmp_name"]) == "application/pdf", "Le fichier doit être au format PDF."); } ensure(is_dir("$LOCAL_PATH/files") || mkdir("$LOCAL_PATH/files"), "Un problème est survenue dans l'envoi du fichier. Veuillez contacter l'administrateur du serveur."); } public function giveQuestions() { global $DB, $LOCAL_PATH, $team; $attached_file = []; for ($i = 0; $i < 5; ++$i) { if ($this->files[$i] == null) $attached_file[] = null; else { do $id = genRandomPhrase(64); while (file_exists("$LOCAL_PATH/files/$id")); if (!rename($this->files[$i]["tmp_name"], "$LOCAL_PATH/files/$id")) throw new AssertionError("Une erreur est survenue lors de l'envoi du fichier."); $attached_file[] = $id; } } $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`, `attached_file`) VALUES " . "(?, ?, ?, ?, ?), (?, ?, ?, ?, ?), (?, ?, ?, ?, ?), (?, ?, ?, ?, ?), (?, ?, ?, ?, ?), (?, ?, ?, ?, ?);"); $req->execute([$team->getId(), $this->to_team->getId(), $team->getProblem(), $this->question_1, $attached_file[0], $team->getId(), $this->to_team->getId(), $team->getProblem(), $this->question_2, $attached_file[1], $team->getId(), $this->to_team->getId(), $team->getProblem(), $this->question_3, $attached_file[2], $team->getId(), $this->to_team->getId(), $team->getProblem(), $this->question_4, $attached_file[3], $team->getId(), $this->to_team->getId(), $team->getProblem(), $this->question_5, $attached_file[4], $team->getId(), $this->to_team->getId(), $team->getProblem(), $this->question_6, $attached_file[5]]); } } /** * @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";