diff --git a/controller/ControleurObjet.php b/controller/ControleurObjet.php index df12d81674f316ad0d89ddfce5a4cfec762f8170..039a97bc7fce2f3472a0237abfe25be4167f33cd 100644 --- a/controller/ControleurObjet.php +++ b/controller/ControleurObjet.php @@ -6,7 +6,7 @@ class ControleurObjet * Affiche la page de cration d'un objet et se charge également de sa création. * @return string */ - public static function creerObjet() : string + public static function createObject() : string { $createdObject = []; // Si reçoie une requête POST pour créer un objet et qu'on a plus d'une entrée @@ -36,8 +36,8 @@ class ControleurObjet */ public static function describeTable() : string { - if(!empty($_GET["describeTable"])){ - return json_encode(Objet::describeObject($_GET["describeTable"])); + if(!empty($_GET["tableName"])){ + return json_encode(Objet::describeObject($_GET["tableName"])); } else { return json_encode([ "status" => "fail", @@ -46,4 +46,12 @@ class ControleurObjet ]); } } + + public static function modifyObject() : string + { + if(!empty($_GET["tableName"]) && !empty($_GET["id"])){ + + } + return ""; + } } \ No newline at end of file diff --git a/index.php b/index.php index 1806364735a195ffb9b70a50c78f82c090720435..029da6f8a20b26b664f8a753cfe7a644024c5909 100644 --- a/index.php +++ b/index.php @@ -1,7 +1,8 @@ <?php +error_reporting(E_ALL); ini_set('display_errors', 1); ini_set('display_startup_errors', 1); -error_reporting(E_ALL); +ini_set('pcre.jit', 0); // Car sinon @content se bloque à 6196 require_once("app/helpers/config.php"); require_once("app/helpers/strings.php"); @@ -22,7 +23,7 @@ if (empty($_REQUEST["action"])) { echo match ($_REQUEST["action"]) { "lireAuteur" => ControleurAuteur::lireAuteur(), "lireAuteurs" => ControleurAuteur::lireAuteurs(), - "creerObjet" => ControleurObjet::creerObjet(), + "creerObjet" => ControleurObjet::createObject(), "lireAdherent" => ControleurAdherent::lireAdherent(), "lireAdherents" => ControleurAdherent::lireAdherents(), "lireLivre" => ControleurLivre::lireLivre(), diff --git a/models/Objet.php b/models/Objet.php index ad2df9037c695947eb8ef16a47b85eb4d0c24f1e..654d931af57f9ce32a271e9de0e0f1dc227964a1 100644 --- a/models/Objet.php +++ b/models/Objet.php @@ -54,7 +54,7 @@ class Objet // Maintenant on va vérifier que la table existe try{ - $tableExistsQuery = Database::pdo()->query("SELECT 1 FROM $tableName LIMIT 1"); + Database::pdo()->query("SELECT 1 FROM $tableName LIMIT 1"); } catch (PDOException $e) { return [ "status" => "fail", @@ -108,7 +108,7 @@ class Objet ]; }else{ try{ - $query = Database::pdo()->query("DESCRIBE $tableName"); + $query = Database::pdo()->query("SHOW FULL COLUMNS FROM $tableName"); $columns = $query->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e) { return [ diff --git a/resources/views/formulaire-creation-objet.php b/resources/views/formulaire-creation-objet.php index d5e49f3bdc94e07357084e2f6c562d5489f6a8d3..5ea204994ac50fab9087ea56436aebe700e6b508 100644 --- a/resources/views/formulaire-creation-objet.php +++ b/resources/views/formulaire-creation-objet.php @@ -56,7 +56,7 @@ async function loadObjectTypeForm(objectType){ objectForm.innerHTML = ""; - await fetch('?action=describeTable&describeTable=' + objectType) + await fetch('?action=describeTable&tableName=' + objectType) .then(res => res.json()) .then((out) => { console.log('Output: ', out); @@ -72,11 +72,25 @@ // On évite de proposer les clés primaires auto incrémentables if(out.columns[i].Extra !== "auto_increment"){ let columnType = out.columns[i].Type; - let match = columnType.match(/([a-z]*)/); + let typeMatch = columnType.match(/([a-z]*)/); + let comment = null; + + if(out.columns[i].Comment !== ""){ + let splitedComment = out.columns[i].Comment.split(','); + for(let c = 0; c<splitedComment.length; c++){ + let commentMatch = splitedComment[c].match(/(^[^%].*[^%]$)/); + if(commentMatch && commentMatch !== undefined){ + comment = commentMatch[1]; + } + } + + } + objectForm.appendChild( createInputDiv( - typesList[match[1]], - out.columns[i].Field + typesList[typeMatch[1]], + out.columns[i].Field, + comment ) ); } @@ -106,7 +120,7 @@ objectForm.appendChild(submitButton); } - function createInputDiv(type, name){ + function createInputDiv(type, name, description=null){ let mainContainer = document.createElement("div"); mainContainer.classList.add("mb-3"); @@ -129,6 +143,15 @@ mainContainer.appendChild(input); + if(description != null) { + let small = document.createElement("small"); + small.classList.add("form-text"); + small.classList.add("text-muted"); + small.innerText = description; + + mainContainer.appendChild(small); + } + return mainContainer; } </script>