phpDocumentor lodel-install
[ class tree: lodel-install ] [ index: lodel-install ] [ all elements ]

Source for file generate.php

Documentation is available at generate.php

  1. <?php
  2. /**
  3.  * Fichier utilitaire pour la génération des fichiers de DAO et de Logic
  4.  *
  5.  *
  6.  * Ce fichier permet de regénérer les fichier du répertoire lodel/scripts/dao et ceux du
  7.  * répertoire lodel/scripts/logic. Les modifications ne sont pas perdus car seul les parties
  8.  * entre les blocs "// begin{publicfields} automatic generation  //" et "// end{publicfields}
  9.  * automatic generation  //" sont régénérés (pour les logiques).
  10.  *
  11.  * Ce script est à lancer en ligne de commande
  12.  *
  13.  * PHP versions 4 et 5
  14.  *
  15.  * LODEL - Logiciel d'Edition ELectronique.
  16.  *
  17.  * Copyright (c) 2001-2002, Ghislain Picard, Marin Dacos
  18.  * Copyright (c) 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
  19.  * Copyright (c) 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
  20.  * Copyright (c) 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
  21.  * Copyright (c) 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
  22.  * Copyright (c) 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
  23.  *
  24.  * Home page: http://www.lodel.org
  25.  *
  26.  * E-Mail: lodel@lodel.org
  27.  *
  28.  * All Rights Reserved
  29.  *
  30.  * This program is free software; you can redistribute it and/or modify
  31.  * it under the terms of the GNU General Public License as published by
  32.  * the Free Software Foundation; either version 2 of the License, or
  33.  * (at your option) any later version.
  34.  *
  35.  * This program is distributed in the hope that it will be useful,
  36.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  37.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  38.  * GNU General Public License for more details.
  39.  *
  40.  * You should have received a copy of the GNU General Public License
  41.  * along with this program; if not, write to the Free Software
  42.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  43.  *
  44.  * @author Ghislain Picard
  45.  * @author Jean Lamy
  46.  * @copyright 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
  47.  * @copyright 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
  48.  * @copyright 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
  49.  * @licence http://www.gnu.org/copyleft/gpl.html
  50.  * @version CVS:$Id:
  51.  * @package lodel/install
  52.  */
  53.  
  54. require_once 'generatefunc.php';
  55. ## to be launch from lodel/scripts
  56.  
  57. $files array("init-site.xml""init.xml");
  58. $table '';
  59. $uniqueid false;
  60. $rights array();
  61. $uniquefields array();
  62.  
  63.  
  64. /**
  65.  * Cette méthode est appélée quand le parser XML rencontre le début d'un élément.
  66.  *
  67.  * Récupère la liste des champs, leurs propriétés pour tous les éléments table
  68.  *
  69.  * @param object $parser le parser XML
  70.  * @param string $name le nom de l'élement qui débute
  71.  * @param array $attrs les attributs de l'élément
  72.  */
  73. function startElement($parser$name$attrs)
  74. {
  75.     global $table$tables$fp$varlist$publicfields$rights$uniqueid;
  76.     global $currentunique$uniquefields;
  77.     switch($name{
  78.     case "table" :
  79.     case "vtable" :
  80.         $table $attrs['name'];
  81.         if ($tables[$table]{
  82.             break;
  83.         }
  84.         if (!$table{
  85.             die('nom de table introuvable');
  86.         }
  87.         $uniqueid = isset($attrs['uniqueid']);
  88.         $rights=array();
  89.         if ($attrs['writeright']$rights["'write'=>LEVEL_"strtoupper($attrs['writeright']);
  90.         if ($attrs['protectright']$rights["'protect'=>LEVEL_"strtoupper($attrs['protectright']);
  91.         $varlist      array();
  92.         $publicfields array();
  93.         $uniquefields array();
  94.         break;
  95.     case "column" :
  96.         $varlist[$attrs['name'];
  97.         if (!isset($attrs['edittype'])) {
  98.             break;
  99.         }
  100.         if (isset($attrs['label']|| (isset($attrs['visibility']&& $attrs['visibility'== 'hidden')) {
  101.             $condition $attrs['required'== 'true' '+' '';
  102.             $publicfields['\''$attrs['name']'\' => array(\''$attrs['edittype']'\', \''.$condition'\')';
  103.         }
  104.         break;
  105.     case "unique" :
  106.         $currentunique $attrs['name'];
  107.         $uniquefields[$currentuniquearray();
  108.         break;
  109.     case "unique-column" :
  110.         $uniquefields[$currentunique][]=$attrs['name'];
  111.         break;
  112.     }
  113. }
  114.  
  115. /**
  116.  * Cette méthode est appélée quand le parser XML rencontre la fin de l'élément.
  117.  *
  118.  * lorsque on détecte la fin d'un élément table alors on génère la DAO et la logic associée
  119.  *
  120.  * @param object $parser le parser XML
  121.  * @param string $name le nom de l'élement qui débute
  122.  */
  123. function endElement($parser$name)
  124. {
  125.     global $table$tables;
  126.     switch($name{
  127.     case "table" :
  128.         if ($tables[$table]break;
  129.         $tables[$tabletrue;
  130.         buildDAO();
  131.         buildLogic();
  132.         $table="";
  133.         break;
  134.     case "vtable" :
  135.         if ($tables[$table]break;
  136.         $tables[$tabletrue;
  137.         //buildDAO(); // don't build DAO for virtual table
  138.         buildLogic();
  139.         $table="";
  140.         break;
  141.     }
  142. }
  143.  
  144. //Lancement du parser
  145. foreach($files as $file{
  146.     $xml_parser xml_parser_create();
  147.     xml_set_element_handler($xml_parser'startElement''endElement');
  148.     xml_parser_set_option($xml_parserXML_OPTION_CASE_FOLDING0);
  149.     if (!($fp fopen($file"r"))) {
  150.         die("could not open XML input");
  151.     }
  152.  
  153.     while ($data fread($fp4096)) {
  154.         if (!xml_parse($xml_parser$datafeof($fp))) {
  155.             die(sprintf("XML error: %s at line %d",
  156.             xml_error_string(xml_get_error_code($xml_parser)),
  157.             xml_get_current_line_number($xml_parser)));
  158.         }
  159.     }
  160.     xml_parser_free($xml_parser);
  161. }
  162.  
  163. /**
  164.  * Construction des fichiers de DAO.
  165.  *
  166.  * Pour chaque table du fichier XML init-site.xml, un fichier contenant la classe VO et la
  167.  * classe DAO de la table est créé.
  168.  */
  169. function buildDAO(
  170. {
  171.     global $table$uniqueid$varlist$rights;
  172.     echo "table=$table\n";
  173.     $text.='
  174.  
  175. /**
  176.  * Classe d\'objet virtuel de la table SQL '.$table.'
  177.  *
  178.  * @package lodel/dao
  179.  * @author Ghislain Picard
  180.  * @author Jean Lamy
  181.  * @copyright 2001-2002, Ghislain Picard, Marin Dacos
  182.  * @copyright 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
  183.  * @copyright 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
  184.  * @copyright 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
  185.  * @copyright 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
  186.  * @copyright 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
  187.  * @licence http://www.gnu.org/copyleft/gpl.html
  188.  * @since Classe ajoutée depuis la version 0.8
  189.  * @see dao.php
  190.  */
  191. class '.$table.'VO 
  192. {
  193.     /**#@+
  194.      * @access public
  195.      */
  196. ';
  197.       foreach ($varlist as $var{
  198.     $text.= "\tvar $".$var.";\n";
  199.       }
  200.       $text.= '    /**#@-*/
  201. }
  202.  
  203. /**
  204.  * Classe d\'abstraction de la base de données de la table '.$table.'
  205.  *
  206.  * Fille de la classe DAO
  207.  *
  208.  * @package lodel/dao
  209.  * @author Ghislain Picard
  210.  * @author Jean Lamy
  211.  * @copyright 2001-2002, Ghislain Picard, Marin Dacos
  212.  * @copyright 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
  213.  * @copyright 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
  214.  * @copyright 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
  215.  * @copyright 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
  216.  * @copyright 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
  217.  * @licence http://www.gnu.org/copyleft/gpl.html
  218.  * @since Classe ajoutée depuis la version 0.8
  219.  * @see dao.php
  220.  */
  221. class '$table'DAO extends DAO 
  222. {
  223.     /**
  224.      * Constructeur
  225.      *
  226.      * <p>Appelle le constructeur de la classe mère DAO en lui passant le nom de la classe.
  227.      * Renseigne aussi le tableau rights des droits.
  228.      * </p>
  229.      */
  230.     function '$table'DAO()
  231.     {
  232.         $this->DAO("'$table'", '($uniqueid "true" "false")');
  233.         $this->rights = array('join(", "$rights).');
  234.     }
  235. ';
  236.     $daofile "../scripts/dao/class.".$table.".php";
  237.     if (file_exists($daofile)) {
  238.         // unique fields
  239.         $beginre '\/\/\s*begin\{definitions\}[^\n]+?\/\/';
  240.         $endre   '\n\s*\/\/\s*end\{definitions\}[^\n]+?\/\/';
  241.         $file file_get_contents($daofile);
  242.         if (preg_match("/$beginre/"$file)) {
  243.             replaceInFile($daofile$beginre$endre$text);
  244.             return;
  245.         }
  246.     }
  247.  
  248.     // create the file
  249.     $fp fopen($daofile"w");
  250.     fwrite($fp"<""?php"getnotice($table)$text.'
  251. }
  252.  
  253. ?'.'>');
  254.     fclose($fp);
  255. }
  256.  
  257.  
  258. /**
  259.  * Construction des logics des classes
  260.  *
  261.  * Pour chaque table du fichier XML init-site.xml, les fichiers de logic sont modifiés
  262.  * pour mettre à jour les fonctions _publicfields et _uniquefields
  263.  */
  264. function buildLogic()
  265. {
  266.     global $table,$publicfields,$uniquefields;
  267.  
  268.     $filename '../scripts/logic/class.'.$table.'.php';
  269.  
  270.     if (!file_exists($filename)) return;
  271.     $file file_get_contents($filename);
  272.  
  273.     // public fields
  274.     $beginre '\/\/\s*begin\{publicfields\}[^\n]+?\/\/';
  275.     $endre   '\n\s*\/\/\s*end\{publicfields\}[^\n]+?\/\/';
  276.     if (preg_match("/$beginre/"$file)) {
  277.         $newpublicfields='
  278.     /**
  279.      * Retourne la liste des champs publics
  280.      * @access private
  281.      */
  282.     function _publicfields() 
  283.     {
  284.         return array('.join(",\n\t\t\t\t\t\t\t\t\t"$publicfields).");
  285.     }";
  286.     replaceInFile($filename$beginre$endre$newpublicfields);
  287.     }
  288.  
  289.     // unique fields
  290.     $beginre '\/\/\s*begin\{uniquefields\}[^\n]+?\/\/';
  291.     $endre   '\n\s*\/\/\s*end\{uniquefields\}[^\n]+?\/\/';
  292.     if (preg_match("/$beginre/"$file)) {
  293.         if ($uniquefields{
  294.             $newunique='
  295.     /**
  296.      * Retourne la liste des champs uniques
  297.      * @access private
  298.      */
  299.     function _uniqueFields() 
  300.     { 
  301.         return array(';
  302.             foreach ($uniquefields as $unique{
  303.                 $newunique.='array(\''.join('\', \'',$unique).'\'), ';
  304.             }
  305.             $newunique.=");
  306.     }";
  307.       }
  308.         replaceInFile($filename,$beginre,$endre,$newunique);
  309.   }
  310. }
  311.  
  312. /**
  313.  * Texte de la notice pour les fichiers DAO
  314.  *
  315.  * @param string $table le nom de la table
  316.  */
  317. function getnotice($table
  318. {
  319.     return '
  320. /**
  321.  * Fichier DAO de la table SQL '.$table.'.
  322.  *
  323.  * PHP versions 4 et 5
  324.  *
  325.  * LODEL - Logiciel d\'Edition ELectronique.
  326.  *
  327.  * Copyright (c) 2001-2002, Ghislain Picard, Marin Dacos
  328.  * Copyright (c) 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
  329.  * Copyright (c) 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
  330.  * Copyright (c) 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
  331.  * Copyright (c) 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
  332.  * Copyright (c) 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
  333.  *
  334.  * Home page: http://www.lodel.org
  335.  *
  336.  * E-Mail: lodel@lodel.org
  337.  *
  338.  * All Rights Reserved
  339.  *
  340.  * This program is free software; you can redistribute it and/or modify
  341.  * it under the terms of the GNU General Public License as published by
  342.  * the Free Software Foundation; either version 2 of the License, or
  343.  * (at your option) any later version.
  344.  *
  345.  * This program is distributed in the hope that it will be useful,
  346.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  347.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  348.  * GNU General Public License for more details.
  349.  *
  350.  * You should have received a copy of the GNU General Public License
  351.  * along with this program; if not, write to the Free Software
  352.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  353.  *
  354.  * @author Ghislain Picard
  355.  * @author Jean Lamy
  356.  * @copyright 2001-2002, Ghislain Picard, Marin Dacos
  357.  * @copyright 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
  358.  * @copyright 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
  359.  * @copyright 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
  360.  * @copyright 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
  361.  * @copyright 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
  362.  * @licence http://www.gnu.org/copyleft/gpl.html
  363.  * @since Fichier ajouté depuis la version 0.8
  364.  * @version CVS:$Id: generate.php 4006 2007-10-05 11:53:41Z malafosse $
  365.  * @package lodel/dao
  366.  */
  367.  
  368. //
  369. // Fichier généré automatiquement le '.date('d-m-Y').'.
  370. //
  371. ';
  372. }
  373. ?>

Documentation generated on Thu, 19 Jun 2008 05:07:47 +0200 by phpDocumentor 1.4.0a2