widgets en écriture, fonctions de sérialisation (appellées lors d'un set).

This commit is contained in:
Georges Dupéron 2010-10-16 20:56:01 +02:00
parent 129dc91905
commit de1f853520
7 changed files with 139 additions and 22 deletions

View File

@ -12,13 +12,20 @@
- Pouvoir ajouter des types plutôt que des widgets. Type = widget affichage + wiget modification (affichage/modification) + sérialisation (stockage) (+ autre chose ?) - Pouvoir ajouter des types plutôt que des widgets. Type = widget affichage + wiget modification (affichage/modification) + sérialisation (stockage) (+ autre chose ?)
- r_field : read-only field
- widgets en écriture. Un form pour chaque champ. 2h
- if_perm() 3h
- modules pour le site 4h - modules pour le site 4h
- squelette 1h - squelette 1h
- css pour le site 2h - css pour le site 2h
==== OK. ==== OK.
- authentification 3h
- if_perm() 3h
- chercher le form parent, s'il n'y en a pas, créer un nouveau. 1h - chercher le form parent, s'il n'y en a pas, créer un nouveau. 1h
- sécurité : if_perm quand on get_prop_direct() ou set_prop_direct() 1h - sécurité : if_perm quand on get_prop_direct() ou set_prop_direct() 1h
- import / export de la BDD. 2h - import / export de la BDD. 2h
- refactor : une classe par type (2 widgets + serialize), dans un fichier séparé de document.
OK :
- widgets en écriture. Un form pour chaque champ. 2h (real : 3h)

View File

@ -200,6 +200,9 @@ class BDDCell {
public function toString() { public function toString() {
return toString($this->valeur); return toString($this->valeur);
} }
public function name_for_set() {
return "set_" . $this->page->uid() . "_" . $this->nom_attribut;
}
} }
?> ?>

View File

@ -187,8 +187,10 @@ ElementDocument::add_type("tr", "td th");
ElementDocument::add_type("td", $inline_elems, "", "colspan rowspan"); ElementDocument::add_type("td", $inline_elems, "", "colspan rowspan");
ElementDocument::add_type("th", $inline_elems); ElementDocument::add_type("th", $inline_elems);
ElementDocument::add_type("li", $inline_elems); ElementDocument::add_type("li", $inline_elems);
ElementDocument::add_type("form", "input_text_line input_text_multi input_text_rich input_file input_submit", "action"); ElementDocument::add_type("form", $inline_elems . " input_text_line input_text_multi input_text_rich input_file input_submit", "action");
ElementDocument::add_type("input_text_line", "", "value"); ElementDocument::add_type("input_text_line", "", "name value");
ElementDocument::add_type("input_text_rich", "", "name value");
ElementDocument::add_type("input_file", "name");
ElementDocument::add_type("input_submit", "", "label"); ElementDocument::add_type("input_submit", "", "label");
ElementDocument::add_type("a", $inline_elems, "href"); ElementDocument::add_type("a", $inline_elems, "href");
ElementDocument::add_type("span", $inline_elems, "", "class"); ElementDocument::add_type("span", $inline_elems, "", "class");
@ -258,49 +260,104 @@ function fn_w_r_field($d, $cell) {
return call_user_func(array($d, "w_r_" . $cell->type()), $cell); return call_user_func(array($d, "w_r_" . $cell->type()), $cell);
} }
/* ==== Types ==== */
// text_line
function fn_w_r_text_line($d, $cell) { function fn_w_r_text_line($d, $cell) {
return $d->text(toString($cell)); return $d->text(toString($cell));
} }
function fn_w_w_text_line($d, $cell) { function fn_w_w_text_line($d, $cell) {
$f = $d->form($d->url()); $f = $d->form($d->url());
$f->input_text_line(toString($cell)); $f->input_text_line($cell->name_for_set(), toString($cell));
$f->input_submit("Ok"); $f->input_submit("Ok");
return $f; return $f;
} }
function fn_serialize_text_line($input) {
return preg_replace("/\n/", " ", $input);
}
// text_nix
function fn_w_r_text_nix($d, $cell) { function fn_w_r_text_nix($d, $cell) {
// Texte naze (sans espaces etc.) à la *nix. // Texte naze (sans espaces etc.) à la *nix.
// TODO : modification si on a les droits.
// TODO : vérifier que ça match [a-zA-Z][-a-zA-Z0-9_]*
return $d->text(toString($cell)); return $d->text(toString($cell));
} }
function fn_w_w_text_nix($d, $cell) {
return $d->form()->input_text($cell->name_for_set(), toString($cell)); // TODO !!!
}
function fn_serialize_text_nix($input) {
return str_to_nix($input);
}
// text_rich
function fn_w_r_text_rich($d, $cell) { function fn_w_r_text_rich($d, $cell) {
// TODO : modification si on a les droits.
// TODO : rendu du texte riche. // TODO : rendu du texte riche.
return $d->p()->text(toString($cell)); return $d->p()->text(toString($cell));
} }
function fn_w_w_text_rich($d, $cell) {
// TODO : modification du texte riche.
return $d->form()->input_text_rich($cell->name_for_set(), toString($cell));
}
function fn_serialize_text_rich($input) {
return $input;
}
// bool
function fn_w_r_bool($d, $cell) { function fn_w_r_bool($d, $cell) {
// checkbox
return $d->text("w_bool(" . toString($cell) . ")"); return $d->text("w_bool(" . toString($cell) . ")");
} }
function fn_w_r_img_file($d, $cell) { function fn_w_w_bool($d, $cell) {
// Le widget w_img_file doit gérer le stockage de l'image dans un dossier, // TODo : checkbox
// la création de la miniature et le stockage dans la BDD du chemin vers l'image.
// TODO : modification si on a les droits.
// input[file] et <img>
return $d->img(toString($cell_description), toString($cell_img));
} }
function fn_serialize_bool($input) {
return ($input == "true") ? "true" : "false";
}
// img_file
function fn_w_r_img_file($d, $cell) {
return $d->img(toString($cell));
}
function fn_w_w_img_file($d, $cell) {
$f = $d->form($d->url());
fn_w_r_img_file($f, $cell);
$f->input_file($cell->name_for_set());
return $f;
}
function fn_serialize_img_file($input) {
// Doit gérer le stockage de l'image dans un dossier,
// la création de la miniature et renvoyer le chemin vers l'image.
// TODO !!! comment faire ?
return $input;
}
// date
function fn_w_r_date($d, $cell) { function fn_w_r_date($d, $cell) {
// affichage localisé. // affichage localisé.
return $d->text("w_date(" . toString($cell) . ")"); return $d->text(strftime("%Y-%m-%d %H:%M:%S", toString($cell)));
}
function fn_w_w_date($d, $cell) {
// affichage localisé.
return $d->form()->input_text_line($cell->name_for_set(), strftime("%Y-%m-%d %H:%M:%S", toString($cell)));
}
function fn_serialize_date($input) {
// TODO
return toString(strtotime($input));
} }
ElementDocument::add_widget("titre", "fn_w_titre"); ElementDocument::add_widget("titre", "fn_w_titre");

View File

@ -127,6 +127,7 @@ class Module {
public static function add_type($nom) { public static function add_type($nom) {
ElementDocument::add_widget("r_" . $nom); ElementDocument::add_widget("r_" . $nom);
ElementDocument::add_widget("w_" . $nom); ElementDocument::add_widget("w_" . $nom);
// fn_serialize_$nom
self::$types[$nom] = array(); self::$types[$nom] = array();
} }
} }

View File

@ -282,7 +282,15 @@ class mPage {
public function set_prop_direct($nom, $val) { public function set_prop_direct($nom, $val) {
// Modifie l'attribut "$nom" dans la BDD. // Modifie l'attribut "$nom" dans la BDD.
$update_table = (self::est_attribut_global($nom)) ? "_pages" : $this->nom_module(); if (self::est_attribut_global($nom)) {
$update_table = "_pages";
$type = Module::$attributs_globaux[$nom]['type'];
} else {
$update_table = $this->nom_module();
$type = $this->module['attributs'][$nom]['type'];
}
$fn_serialize = "fn_serialize_" . $type;
$val = $fn_serialize($val);
$update = "update " . BDD::table($update_table) . " set $nom = '" . BDD::escape(toString($val)) . "' where _uid_page = " . $this->uid(); $update = "update " . BDD::table($update_table) . " set $nom = '" . BDD::escape(toString($val)) . "' where _uid_page = " . $this->uid();
BDD::unbuf_query($update); BDD::unbuf_query($update);
if ($nom != "date_modification") { if ($nom != "date_modification") {

View File

@ -45,6 +45,43 @@ function toString($obj) {
} }
} }
function correspondance_accents(&$arr_ascii, &$arr_accents, $ascii, $accents) {
$_accents = explode(".", $accents);
foreach ($_accents as $k=>$v) {
array_push($arr_accents, $v);
array_push($arr_ascii, $ascii);
}
}
// Transforme en une chaîne qui match [a-zA-Z][-a-zA-Z0-9_]*
function str_to_nix($input) {
$ascii = array();
$accents = array();
correspondance_accents($ascii, $accents, "a", "à.á.â.ä.ã.ǎ.å");
correspondance_accents($ascii, $accents, "e", "è.é.ê.ë.ě.ẽ");
correspondance_accents($ascii, $accents, "i", "ì.í.î.ï.ĩ.ǐ");
correspondance_accents($ascii, $accents, "o", "ò.ó.ô.ö.õ.ǒ.ø");
correspondance_accents($ascii, $accents, "u", "ù.ú.û.ü.ũ.ǔ.ů");
correspondance_accents($ascii, $accents, "y", "ỳ.ý.ŷ.ÿ.ỹ.ẙ");
correspondance_accents($ascii, $accents, "c", "ç");
correspondance_accents($ascii, $accents, "A", "À.Á.Â.Ä.Ã.Ǎ.Å");
correspondance_accents($ascii, $accents, "E", "È.É.Ê.Ë.Ě.Ẽ");
correspondance_accents($ascii, $accents, "I", "Ì.Í.Î.Ï.Ĩ.Ǐ");
correspondance_accents($ascii, $accents, "O", "Ò.Ó.Ô.Ö.Õ.ǒ.Ø");
correspondance_accents($ascii, $accents, "U", "Ù.Ú.Û.Ü.Ũ.Ů.ǔ");
correspondance_accents($ascii, $accents, "Y", "Ŷ.Ý.Ŷ.Ÿ.Ỹ");
correspondance_accents($ascii, $accents, "C", "Ç");
correspondance_accents($ascii, $accents, "ae", "æ");
correspondance_accents($ascii, $accents, "oe", "œ");
correspondance_accents($ascii, $accents, "AE", "Æ");
correspondance_accents($ascii, $accents, "OE", "Œ");
correspondance_accents($ascii, $accents, "-", " ");
$input = str_replace($accents, $ascii, $input);
$first = preg_replace("/[^a-zA-Z]/", "a", substr($input, 0, 1));
$rest = preg_replace("/[^-a-zA-Z0-9_]/", "-", substr($input, 1));
return $first . $rest;
}
/**** Début PATH ****/ /**** Début PATH ****/
// http://www.liranuna.com/php-path-resolution-class-relative-paths-made-easy/ // http://www.liranuna.com/php-path-resolution-class-relative-paths-made-easy/

View File

@ -37,6 +37,10 @@
<input type="text" value="{@value}"/> <input type="text" value="{@value}"/>
</xsl:template> </xsl:template>
<xsl:template match="input_text_rich">
<input type="text" value="{@value}"/>
</xsl:template>
<xsl:template match="input_submit"> <xsl:template match="input_submit">
<input type="submit" value="{@label}"/> <input type="submit" value="{@label}"/>
</xsl:template> </xsl:template>