protected function hydrate(array $record) : QuestionInterface
 {
     $question = new Question();
     $question->setID($record['id']);
     $question->setName($record['name']);
     $question->setQuestion($record['question']);
     $question->setTime(new DateTimeImmutable('@' . $record['time']));
     return $question;
 }
示例#2
0
/**
 * Renvoi un objet Conteneur de news
 * Les données sont stockées dans un fichier yaml, pour faire un peu standard... quand même...
 */
function lectureNewsYaml($nomFichier)
{
    // Création du conteneur à retourner
    $conteneur = new ConteneurNews();
    // Lecture du fichier yaml
    $array = Spyc::YAMLLoad($nomFichier);
    // on commence par le noeud racine: la liste des news
    foreach ($array as $noeudRacine) {
        // on chope la news
        $news = new News();
        $news->setNouvelAttribut("titre", $noeudRacine["titre"]);
        $news->setNouvelAttribut("dateDebut", $noeudRacine["dateDebut"]);
        $news->setNouvelAttribut("dateFin", $noeudRacine["dateFin"]);
        $news->setNouvelAttribut("image", $noeudRacine["image"]);
        $news->setNouvelAttribut("imageInformation", $noeudRacine["imageInformation"]);
        $news->setNouvelAttribut("important", $noeudRacine["important"]);
        $news->setNouvelAttribut("resume", isset($noeudRacine["resume"]) ? $noeudRacine["resume"] : null);
        // on chope le formulaire à saisir, s'il existe
        if (isset($noeudRacine["include"])) {
            $news->ajouteInclude($noeudRacine["include"]);
        }
        // on chope les questions si elles existent
        if (isset($noeudRacine["questions"])) {
            $questions = $noeudRacine["questions"];
            foreach ($questions as $question) {
                $questionReponse = new Question();
                $questionReponse->setQuestion($question["q"]);
                $questionReponse->setReponse(isset($question["r"]) ? $question["r"] : null);
                $questionReponse->setReponseImage(isset($question["rimg"]) ? $question["rimg"] : null);
                $news->ajouteQuestionReponse($questionReponse);
            }
        }
        // On chope les fichiers attachés, s'ils existent
        if (isset($noeudRacine["fichiersAttaches"])) {
            $fichiers = $noeudRacine["fichiersAttaches"];
            foreach ($fichiers as $fichier) {
                $fic = new FichierAttache();
                $fic->setTitre($fichier["titre"]);
                $fic->setUrlFichier($fichier["url"]);
                $news->ajouteFichierAttache($fic);
            }
        }
        $conteneur->ajouteNews($news);
    }
    return $conteneur;
}
示例#3
0
 public function newQuestion($id)
 {
     try {
         $report = new Report($id);
         if (!$report->allowQuestion()) {
             throw new fValidationException('Not allowed to ask question.');
         }
         $category = fRequest::get('category', 'integer');
         if ($category == 0) {
             throw new fValidationException('Please choose a category.');
         }
         $question = new Question();
         $question->setUsername(fAuthorization::getUserToken());
         $question->setReportId($report->getId());
         if ($category < 0) {
             $question->setCategory($category);
         } else {
             $question->setCategory(Question::ABOUT_PROBLEM_HIDDEN);
             $problem = new Problem($category);
             $question->setProblemId($problem->getId());
         }
         $question->setAskTime(new fTimestamp());
         $question->setQuestion(trim(fRequest::get('question')));
         if (strlen($question->getQuestion()) < 10) {
             throw new fValidationException('Question too short (minimum 10 bytes).');
         }
         if (strlen($question->getQuestion()) > 500) {
             throw new fValidationException('Question too long (maximum 500 bytes).');
         }
         $question->store();
         fMessaging::create('success', 'Question saved.');
     } catch (fExpectedException $e) {
         fMessaging::create('warning', $e->getMessage());
     } catch (fUnexpectedException $e) {
         fMessaging::create('error', $e->getMessage());
     }
     Util::redirect("/contest/{$id}");
 }
示例#4
0
         $questionManager = new QuestionManager($bdd);
         $questionManager->delete($_GET['id']);
         header('Location: ?controler=question&action=list');
     } else {
         header('Location: ?controler=question&action=list');
     }
     break;
 case 'csvImport':
     $adminLvlThisControler = 4;
     require_once 'lib/checkRights.php';
     if (isset($_POST['file']) && !empty($_POST['theme'])) {
         if ($file = fopen('web/csv/' . $_POST['file'], 'r')) {
             $questionManager = new QuestionManager($bdd);
             $question = new Question(array());
             while ($ligne = fgetcsv($file, 0, '|', '"')) {
                 $question->setQuestion(stripslashes($ligne[0]));
                 $question->setRep1($ligne[1]);
                 $question->setRep2($ligne[2]);
                 $question->setRep3($ligne[3]);
                 $question->setRep4($ligne[4]);
                 $question->setRep($ligne[5]);
                 $question->setThemeid($_POST['theme']);
                 $question->setUserid($ligne[6]);
                 $questionManager->add($question);
             }
             header('Location: ?controler=question&action=list');
         }
     } else {
         $directory = 'web/csv/';
         $files = array_diff(scandir($directory), array('..', '.'));
         $themeManager = new ThemeManager($bdd);