Source for file generate.php
Documentation is available at generate.php
* Fichier utilitaire pour la génération des fichiers de DAO et de Logic
* Ce fichier permet de regénérer les fichier du répertoire lodel/scripts/dao et ceux du
* répertoire lodel/scripts/logic. Les modifications ne sont pas perdus car seul les parties
* entre les blocs "// begin{publicfields} automatic generation //" et "// end{publicfields}
* automatic generation //" sont régénérés (pour les logiques).
* Ce script est à lancer en ligne de commande
* LODEL - Logiciel d'Edition ELectronique.
* Copyright (c) 2001-2002, Ghislain Picard, Marin Dacos
* Copyright (c) 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
* Copyright (c) 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
* Copyright (c) 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
* Copyright (c) 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
* Copyright (c) 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
* Home page: http://www.lodel.org
* E-Mail: lodel@lodel.org
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* @author Ghislain Picard
* @copyright 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
* @copyright 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
* @copyright 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
* @licence http://www.gnu.org/copyleft/gpl.html
require_once 'generatefunc.php';
## to be launch from lodel/scripts
$files = array("init-site.xml", "init.xml");
* Cette méthode est appélée quand le parser XML rencontre le début d'un élément.
* Récupère la liste des champs, leurs propriétés pour tous les éléments table
* @param object $parser le parser XML
* @param string $name le nom de l'élement qui débute
* @param array $attrs les attributs de l'élément
global $table, $tables, $fp, $varlist, $publicfields, $rights, $uniqueid;
global $currentunique, $uniquefields;
die('nom de table introuvable');
$uniqueid = isset ($attrs['uniqueid']);
if ($attrs['writeright']) $rights[] = "'write'=>LEVEL_". strtoupper($attrs['writeright']);
if ($attrs['protectright']) $rights[] = "'protect'=>LEVEL_". strtoupper($attrs['protectright']);
$varlist[] = $attrs['name'];
if (!isset ($attrs['edittype'])) {
if (isset ($attrs['label']) || (isset ($attrs['visibility']) && $attrs['visibility'] == 'hidden')) {
$condition = $attrs['required'] == 'true' ? '+' : '';
$publicfields[] = '\''. $attrs['name']. '\' => array(\''. $attrs['edittype']. '\', \''. $condition. '\')';
$currentunique = $attrs['name'];
$uniquefields[$currentunique] = array();
$uniquefields[$currentunique][]= $attrs['name'];
* Cette méthode est appélée quand le parser XML rencontre la fin de l'élément.
* lorsque on détecte la fin d'un élément table alors on génère la DAO et la logic associée
* @param object $parser le parser XML
* @param string $name le nom de l'élement qui débute
if ($tables[$table]) break;
if ($tables[$table]) break;
//buildDAO(); // don't build DAO for virtual table
foreach($files as $file) {
if (!($fp = fopen($file, "r"))) {
die("could not open XML input");
while ($data = fread($fp, 4096)) {
die(sprintf("XML error: %s at line %d",
* Construction des fichiers de DAO.
* Pour chaque table du fichier XML init-site.xml, un fichier contenant la classe VO et la
* classe DAO de la table est créé.
global $table, $uniqueid, $varlist, $rights;
* Classe d\'objet virtuel de la table SQL '. $table. '
* @author Ghislain Picard
* @copyright 2001-2002, Ghislain Picard, Marin Dacos
* @copyright 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
* @copyright 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
* @copyright 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
* @copyright 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
* @copyright 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
* @licence http://www.gnu.org/copyleft/gpl.html
* @since Classe ajoutée depuis la version 0.8
foreach ($varlist as $var) {
$text.= "\tvar $". $var. ";\n";
* Classe d\'abstraction de la base de données de la table '. $table. '
* @author Ghislain Picard
* @copyright 2001-2002, Ghislain Picard, Marin Dacos
* @copyright 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
* @copyright 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
* @copyright 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
* @copyright 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
* @copyright 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
* @licence http://www.gnu.org/copyleft/gpl.html
* @since Classe ajoutée depuis la version 0.8
class '. $table. 'DAO extends DAO
* <p>Appelle le constructeur de la classe mère DAO en lui passant le nom de la classe.
* Renseigne aussi le tableau rights des droits.
function '. $table. 'DAO()
$this->DAO("'. $table. '", '. ($uniqueid ? "true" : "false"). ');
$this->rights = array('. join(", ", $rights). ');
$daofile = "../scripts/dao/class.". $table. ".php";
$beginre = '\/\/\s*begin\{definitions\}[^\n]+?\/\/';
$endre = '\n\s*\/\/\s*end\{definitions\}[^\n]+?\/\/';
$fp = fopen($daofile, "w");
* Construction des logics des classes
* Pour chaque table du fichier XML init-site.xml, les fichiers de logic sont modifiés
* pour mettre à jour les fonctions _publicfields et _uniquefields
global $table,$publicfields,$uniquefields;
$filename = '../scripts/logic/class.'. $table. '.php';
$beginre = '\/\/\s*begin\{publicfields\}[^\n]+?\/\/';
$endre = '\n\s*\/\/\s*end\{publicfields\}[^\n]+?\/\/';
* Retourne la liste des champs publics
return array('. join(",\n\t\t\t\t\t\t\t\t\t", $publicfields). ");
$beginre = '\/\/\s*begin\{uniquefields\}[^\n]+?\/\/';
$endre = '\n\s*\/\/\s*end\{uniquefields\}[^\n]+?\/\/';
* Retourne la liste des champs uniques
foreach ($uniquefields as $unique) {
$newunique.= 'array(\''. join('\', \'',$unique). '\'), ';
* Texte de la notice pour les fichiers DAO
* @param string $table le nom de la table
* Fichier DAO de la table SQL '. $table. '.
* LODEL - Logiciel d\'Edition ELectronique.
* Copyright (c) 2001-2002, Ghislain Picard, Marin Dacos
* Copyright (c) 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
* Copyright (c) 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
* Copyright (c) 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
* Copyright (c) 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
* Copyright (c) 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
* Home page: http://www.lodel.org
* E-Mail: lodel@lodel.org
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* @author Ghislain Picard
* @copyright 2001-2002, Ghislain Picard, Marin Dacos
* @copyright 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
* @copyright 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
* @copyright 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
* @copyright 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
* @copyright 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
* @licence http://www.gnu.org/copyleft/gpl.html
* @since Fichier ajouté depuis la version 0.8
* @version CVS:$Id: generate.php 4006 2007-10-05 11:53:41Z malafosse $
// Fichier généré automatiquement le '. date('d-m-Y'). '.
|