Quick links: Content - sections - sub sections
EN FR
Quick Search Advanced search
 
Page

  [Opened] Utiliser les commentaires Mysql pour les labels jForms

Posted by YvesTan on 09/11/2012 10:30

Bonjour à tous,

Je me disais qu'il pourrait être sympathique que la commande "createform" utilise les commentaires SQL pour les labels des champs.

Exemple : `dateenvoi` timestamp NULL DEFAULT NULL COMMENT 'Date envoi',

Ceci impliquerait un nouvel attribut "comment" dans les descriptions des champs dans les fichiers DAO et la modification des scripts createdao et createform

Sur une instance jelix 1.3, j'ai modifié un chouilla les fichiers suivants (commentaire YVES) :

./jelix-scripts/commands/createform.cmd.php

            // YVES                                                                                                                                                                                                      
            if(isset($property->comment) && $property->comment!='') {
                if ($this->getOption('-createlocales')) {
                    $locale_content .= 'form.'.$name.'='.$property->comment."\n";
                    $content.="\n\n<$tag ref=\"$name\"$attr>\n\t<label locale='".$locale_base.$name."' />\n</$tag>";
                } else {
                    $content.="\n\n<$tag ref=\"$name\"$attr>\n\t<label>".$property->comment."</label>\n</$tag>";
                }
            } else {
                if ($this->getOption('-createlocales')) {
                    $locale_content .= 'form.'.$name.'='. ucwords(str_replace('_',' ',$name))."\n";
                    $content.="\n\n<$tag ref=\"$name\"$attr>\n\t<label locale='".$locale_base.$name."' />\n</$tag>";
                } else {
                    $content.="\n\n<$tag ref=\"$name\"$attr>\n\t<label>".ucwords(str_replace('_',' ',$name))."</label>\n</$tag>";
                }
            }
            /*if ($this->getOption('-createlocales')) {
                $locale_content .= 'form.'.$name.'='. ucwords(str_replace('_',' ',$name))."\n";
                $content.="\n\n<$tag ref=\"$name\"$attr>\n\t<label locale='".$locale_base.$name."' />\n</$tag>";
            } else {
                $content.="\n\n<$tag ref=\"$name\"$attr>\n\t<label>".ucwords(str_replace('_',' ',$name))."</label>\n</$tag>";
            }*/
            // END YVES

./jelix/plugins/db/mysql/mysql.dbtools.php

        // YVES
        //$rs = $this->_conn->query ('SHOW FIELDS FROM `'.$tableName.'`');
        $rs = $this->_conn->query ('SHOW FULL FIELDS FROM `'.$tableName.'`');
        // END YVES

./jelix/dao/jDaoProperty.class.php

    // YVES
    public $comment = null;
    // END YVES

    /**
    * constructor.
    * @param array  $attributes  list of attributes of a simpleXmlElement
    * @param jDaoParser $parser the parser on the dao file
    * @param jDbTools $tools
    */
    function __construct ($aAttributes, $parser, $tools){
        // YVES => Ajout de "comment" dans le tableau
        $needed = array('name', 'fieldname', 'table', 'datatype', 'required',                                                                                                                                            
                        'minlength', 'maxlength', 'regexp', 'sequence', 'default','autoincrement','comment');

        $params = $parser->getAttr($aAttributes, $needed);

        if ($params['name']===null){
            throw new jDaoXmlException ($parser->selector, 'missing.attr', array('name', 'property'));
        }
        $this->name       = $params['name'];

        if(!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $this->name)){
            throw new jDaoXmlException ($parser->selector, 'property.invalid.name', $this->name);
        }

        // YVES
        if(!empty($params['comment'])) {
            $this->comment  = $params['comment'];
        }
        // END YVES

Et ça fonctionne.

Qu'en pensez-vous ?

  [Opened] Utiliser les commentaires Mysql pour les labels jForms

Reply #1 Posted by laurentj on 09/11/2012 10:45

Salut,

clone le dépot et fait un pull request sur github...

  [Opened] Utiliser les commentaires Mysql pour les labels jForms

Reply #2 Posted by YvesTan on 09/11/2012 13:18

OK. Dès que j'ai quelques minutes pour capter comment générer un build et tout le toutim, je fais ça.

 
Page
  1. Version 1.7 accéder au répertoire files depuis un template >
  2. RESOLU: Affichage des sous item de menu dans master admin >
  3. ScreenCast : Créer une application Jelix en moins d'une minute >
  4. Jelix 1.1 now in German, Spanish and Chinease and dutch >
  5. Nouveaux plugin jDb Queries asynchrones avec PostgreSQL >
  6. [Résolu] Erreur lors de l'installation de master_admin >
  7. Proposition d'une nouvelle politique de support et d'une roadmap >
  8. Utiliser les commentaires Mysql pour les labels jForms