Exemple #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();
 }
Exemple #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;
 }
 public static function render($params = [])
 {
     $method = false;
     $activeFunction = false;
     if (isset($_POST['translate'])) {
         $method = 'translate';
     }
     if (isset($_POST['new'])) {
         $method = 'erase';
     }
     if (isset($_POST['open'])) {
         $method = 'open';
     }
     if (isset($_POST['save'])) {
         $method = 'save';
     }
     if (isset($_POST['backup'])) {
         $method = 'backup';
     }
     if (isset($_POST['share'])) {
         $method = 'share';
     }
     if (isset($_POST['askForHelp'])) {
         $method = 'askForHelp';
     }
     if ($method) {
         self::$method();
         die;
     }
     $id = NULL;
     $pseudoCode = '';
     if (isset($params[0])) {
         $id = $params[0];
     }
     $language = 'php';
     $user = AppController::getUser();
     $privateFunctions = [];
     $userStructures = [];
     $selectedUserStructures = [];
     if (isset($_POST['selectedStructures'])) {
         $selectedUserStructures = $_POST['selectedStructures'];
     } else {
         if ($user) {
             $structures = \Root\Src\Model\StructureModel::loadStructureByUser($user->getId());
             foreach ($structures as $structure) {
                 array_push($selectedUserStructures, $structure->getId());
             }
         }
     }
     if (isset($_POST['id'])) {
         $id = $_POST['id'];
     }
     if ($user) {
         $privateFunctions = \Root\Src\Model\AlgorithmModel::loadFunctionByUser($user->getId());
         $userStructures = \Root\Src\Model\StructureModel::loadStructureByUser($user->getId());
         if ($id) {
             $function = \Root\Src\Model\AlgorithmModel::loadFunctionById($id);
             if ($function) {
                 if ($function->getOwnerId() != $user->getId()) {
                     $pseudoCode = '';
                     $id = '';
                     $_POST['id'] = NULL;
                 } else {
                     if ($pseudoCode == "") {
                         $pseudoCode = $function->getContent();
                         $activeFunction = $function;
                     }
                 }
             }
         }
     }
     $publicFunctions = [];
     $allPublicFunctions = \Root\Src\Model\AlgorithmModel::loadPublicFunction();
     foreach ($allPublicFunctions as $currentFunction) {
         if (!in_array($currentFunction, $privateFunctions)) {
             array_push($publicFunctions, $currentFunction);
         }
     }
     $selectedPrivateFunctions = [];
     if (isset($_POST['privateFunctions'])) {
         $selectedPrivateFunctions = $_POST['privateFunctions'];
     }
     $selectedPublicFunctions = [];
     if (isset($_POST['publicFunctions'])) {
         $selectedPublicFunctions = $_POST['publicFunctions'];
     }
     if (isset($_POST['language'])) {
         $language = $_POST['language'];
     }
     if (isset($_POST['pseudoCode'])) {
         $pseudoCode = $_POST['pseudoCode'];
     }
     $helpMsgs = \Root\Src\Model\MailModel::getMsgBySubject($id);
     parent::render(['id' => $id, 'selectedLanguage' => $language, 'pseudoCode' => $pseudoCode, 'user' => $user, 'privateFunctions' => $privateFunctions, 'publicFunctions' => $publicFunctions, 'selectedPrivateFunctions' => $selectedPrivateFunctions, 'selectedPublicFunctions' => $selectedPublicFunctions, 'userStructures' => $userStructures, 'selectedUserStructures' => $selectedUserStructures, 'activeFunction' => $activeFunction, 'helpMsgs' => $helpMsgs]);
 }