enigme_gateway = new EnigmeGateway(); $this->nettoyage = new Nettoyage(); $this->validation = new Validation(); } public function addNewEnigmeSolo(string $nom,string $enonce,string $aide,string $rappel,string $exemple,string $test,string $solution) : Enigme { $enigme = new Enigme(1,$nom, $enonce, $aide, $rappel, $exemple, $solution, $test); $this->enigme_gateway->insert($enigme); $tabEnigme = $this->enigme_gateway->findLastEnigma(); $js = fopen("View/src/JS/$nom.js", "w"); if (is_resource($js)) { fwrite($js, "//~ Function that test the user code async function submit(){ var test = editor.getValue()+`\\n\n". $solution . "\n". $test . "\n`; exec(\"print ('True')\", \"code\"); exec(test, \"solution\"); result.innerHTML = \"Test en cours...\"; await new Promise(r => setTimeout(r, 1500)); check(); }"); fclose($js); } else { throw new Exception("Impossible d'ouvrir le fichier"); } return $tabEnigme[0]; } }