/**
  * compile the given class id.
  */
 public function compile($selector)
 {
     jDaoCompiler::$daoId = $selector->toString();
     jDaoCompiler::$daoPath = $selector->getPath();
     jDaoCompiler::$dbType = $selector->driver;
     // chargement du fichier XML
     $doc = new DOMDocument();
     if (!$doc->load(jDaoCompiler::$daoPath)) {
         throw new jException('jelix~daoxml.file.unknow', jDaoCompiler::$daoPath);
     }
     if ($doc->documentElement->namespaceURI != JELIX_NAMESPACE_BASE . 'dao/1.0') {
         throw new jException('jelix~daoxml.namespace.wrong', array(jDaoCompiler::$daoPath, $doc->namespaceURI));
     }
     $parser = new jDaoParser();
     $parser->parse(simplexml_import_dom($doc));
     global $gJConfig;
     if (!isset($gJConfig->_pluginsPathList_db[$selector->driver]) || !file_exists($gJConfig->_pluginsPathList_db[$selector->driver])) {
         throw new jException('jelix~db.error.driver.notfound', $selector->driver);
     }
     require_once $gJConfig->_pluginsPathList_db[$selector->driver] . $selector->driver . '.daobuilder.php';
     $class = $selector->driver . 'DaoBuilder';
     $generator = new $class($selector->getDaoClass(), $selector->getDaoRecordClass(), $parser);
     // génération des classes PHP correspondant à la définition de la DAO
     $compiled = '<?php ' . $generator->buildClasses() . "\n?>";
     jFile::write($selector->getCompiledFilePath(), $compiled);
     return true;
 }
 public function run()
 {
     jxs_init_jelix_env();
     $path = $this->getModulePath($this->_parameters['module']);
     $filename = $path . 'forms/';
     $this->createDir($filename);
     $filename .= strtolower($this->_parameters['form']) . '.form.xml';
     $submit = "\n\n<submit ref=\"_submit\">\n\t<label>ok</label>\n</submit>";
     if (($dao = $this->getParam('dao')) === null) {
         $this->createFile($filename, 'form.xml.tpl', array('content' => '<!-- add control declaration here -->' . $submit));
         return;
     }
     global $gJConfig;
     $gJConfig->startModule = $this->_parameters['module'];
     jContext::push($this->_parameters['module']);
     // we're going to parse the dao
     $selector = new jSelectorDao($dao, '', false);
     jDaoCompiler::$daoId = $selector->toString();
     jDaoCompiler::$daoPath = $selector->getPath();
     jDaoCompiler::$dbType = $selector->driver;
     $doc = new DOMDocument();
     if (!$doc->load(jDaoCompiler::$daoPath)) {
         throw new jException('jelix~daoxml.file.unknow', jDaoCompiler::$daoPath);
     }
     if ($doc->documentElement->namespaceURI != JELIX_NAMESPACE_BASE . 'dao/1.0') {
         throw new jException('jelix~daoxml.namespace.wrong', array(jDaoCompiler::$daoPath, $doc->namespaceURI));
     }
     $parser = new jDaoParser();
     $parser->parse(simplexml_import_dom($doc));
     // know we generate the form file
     $properties = $parser->GetProperties();
     $table = $parser->GetPrimaryTable();
     $content = '';
     foreach ($properties as $name => $property) {
         if (!$property->ofPrimaryTable) {
             continue;
         }
         if ($property->isPK && ($property->datatype == 'autoincrement' || $property->datatype == 'bigautoincrement')) {
             continue;
         }
         $attr = '';
         if ($property->required) {
             $attr .= ' required="true"';
         }
         if ($property->defaultValue !== null) {
             $attr .= ' defaultvalue="' . htmlspecialchars($property->defaultValue) . '"';
         }
         if ($property->maxlength !== null) {
             $attr .= ' maxlength="' . $property->maxlength . '"';
         }
         if ($property->minlength !== null) {
             $attr .= ' minlength="' . $property->minlength . '"';
         }
         //if(false)
         //    $attr.=' defaultvalue=""';
         $datatype = '';
         $tag = 'input';
         switch ($property->datatype) {
             case 'autoincrement':
             case 'bigautoincrement':
             case 'int':
             case 'integer':
             case 'numeric':
                 $datatype = 'integer';
                 break;
             case 'datetime':
                 $datatype = 'datetime';
                 break;
             case 'time':
                 $datatype = 'time';
                 break;
             case 'date':
                 $datatype = 'date';
                 break;
             case 'double':
             case 'float':
                 $datatype = 'decimal';
                 break;
             case 'text':
                 $tag = 'textarea';
                 break;
             case 'boolean':
                 $tag = 'checkbox';
                 break;
         }
         if ($datatype != '') {
             $attr .= ' type="' . $datatype . '"';
         }
         $content .= "\n\n<{$tag} ref=\"{$name}\"{$attr}>\n\t<label>{$name}</label>\n</{$tag}>";
     }
     $this->createFile($filename, 'form.xml.tpl', array('content' => $content . $submit));
 }