Skip to content
Snippets Groups Projects
Commit ed87b442 authored by Sofiane Lasri's avatar Sofiane Lasri
Browse files

Début TP 7.

Contournement d'un problème à cause de l'usage de grandes regex, ajout du support des commentaires sur les colones.
parent b7f25bd6
Branches
No related tags found
No related merge requests found
......@@ -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
<?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(),
......
......@@ -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 [
......
......@@ -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>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment