Beispiel #1
0
 public static function render($params = [])
 {
     $user = AppController::getUser();
     if (!$user) {
         AppController::setMsg('warning', "La zone demandée n'est pas autorisé pour les personnes non inscrites.");
         AppController::redirect('index');
     }
     $algorithms = \Root\Src\Model\AlgorithmModel::loadFunctionByUser($user->getId());
     $structures = \Root\Src\Model\StructureModel::loadStructureByUser($user->getId());
     $translationOfC = \Root\Src\Model\TranslationModel::loadTranslationByLanguage('c');
     $translationOfJava = \Root\Src\Model\TranslationModel::loadTranslationByLanguage('java');
     $translationOfJavascript = \Root\Src\Model\TranslationModel::loadTranslationByLanguage('javascript');
     $translationOfPhp = \Root\Src\Model\TranslationModel::loadTranslationByLanguage('php');
     $translationOfPython = \Root\Src\Model\TranslationModel::loadTranslationByLanguage('python');
     parent::getHeader();
     self::call('Render', ['algorithms' => $algorithms, 'structures' => $structures, 'translations' => ['c' => $translationOfC, 'java' => $translationOfJava, 'javascript' => $translationOfJavascript, 'php' => $translationOfPhp, 'python' => $translationOfPython]]);
     parent::getFooter();
 }
Beispiel #2
0
 /**
  * Traduit le pseudoCode dans un langage avec une liste de structure privée donnée
  * @param type $pseudoCode
  * @param type $language
  * @param type $structures
  * @return type
  */
 public static function translate($pseudoCode, $language, $structures = [])
 {
     $result = $pseudoCode;
     $translations = \Root\Src\Model\TranslationModel::loadTranslationByLanguage($language);
     $publicStructures = \Root\Src\Model\StructureModel::loadStructureByUser(\Root\Src\Model\AlgorithmModel::PUBLIC_USER);
     foreach ($publicStructures as $publicStructure) {
         if (!in_array($publicStructure, $structures)) {
             array_push($structures, $publicStructure);
         }
     }
     foreach ($structures as $structure) {
         if (isset($translations[$structure->getId()])) {
             $result = preg_replace(self::interpret($structure->getCode()), $translations[$structure->getId()]->getCode(), $result);
         } else {
             $result = preg_replace(self::interpret($structure->getCode()), 'ERR', $result);
         }
     }
     return $result;
 }
Beispiel #3
0
 /**
  * Méthode de chargement d'une structure
  * @param type $params
  */
 public static function load($params = [])
 {
     if (isset($params[0])) {
         $_POST['idStructure'] = $params[0];
         $structure = \Root\Src\Model\StructureModel::loadStructureById($_POST['idStructure']);
         $user = AppController::getUser();
         if ($structure && $user && $structure->getOwnerId() == $user->getId()) {
             $_POST['idStructure'] = $structure->getId();
             $_POST['structure'] = $structure->getCode();
             $tranlsationToC = \Root\Src\Model\TranslationModel::loadTranslationByIdAndLanguage($structure->getId(), 'c');
             if ($tranlsationToC) {
                 $_POST['translationToC'] = $tranlsationToC->getCode();
             }
             $tranlsationToPhp = \Root\Src\Model\TranslationModel::loadTranslationByIdAndLanguage($structure->getId(), 'php');
             if ($tranlsationToPhp) {
                 $_POST['translationToPhp'] = $tranlsationToPhp->getCode();
             }
             $tranlsationToJava = \Root\Src\Model\TranslationModel::loadTranslationByIdAndLanguage($structure->getId(), 'java');
             if ($tranlsationToJava) {
                 $_POST['translationToJava'] = $tranlsationToJava->getCode();
             }
             $tranlsationToJavascript = \Root\Src\Model\TranslationModel::loadTranslationByIdAndLanguage($structure->getId(), 'javascript');
             if ($tranlsationToJavascript) {
                 $_POST['translationToJavascript'] = $tranlsationToJavascript->getCode();
             }
             $tranlsationToPython = \Root\Src\Model\TranslationModel::loadTranslationByIdAndLanguage($structure->getId(), 'python');
             if ($tranlsationToPython) {
                 $_POST['translationToPython'] = $tranlsationToPython->getCode();
             } else {
                 unset($_POST['idStructure']);
             }
         }
     }
     self::render();
 }