/**
  * @param jSelectorDao $selector
  * @param string $localekey a locale key
  * @param array $localeParams parameters for the message (for sprintf)
  */
 public function __construct($selector, $localekey, $localeParams = array())
 {
     $localekey = 'jelix~daoxml.' . $localekey;
     $arg = array($selector->toString(), $selector->getPath());
     if (is_array($localeParams)) {
         $arg = array_merge($arg, $localeParams);
     } else {
         $arg[] = $localeParams;
     }
     parent::__construct($localekey, $arg);
 }
示例#2
0
 /**
  * compile the given class id.
  * @param jSelectorDao $selector
  */
 public function compile($selector)
 {
     $daoPath = $selector->getPath();
     // load the XML file
     $doc = new DOMDocument();
     if (!$doc->load($daoPath)) {
         throw new jException('jelix~daoxml.file.unknown', $daoPath);
     }
     if ($doc->documentElement->namespaceURI != JELIX_NAMESPACE_BASE . 'dao/1.0') {
         throw new jException('jelix~daoxml.namespace.wrong', array($daoPath, $doc->namespaceURI));
     }
     $tools = jApp::loadPlugin($selector->driver, 'db', '.dbtools.php', $selector->driver . 'DbTools');
     if (is_null($tools)) {
         throw new jException('jelix~db.error.driver.notfound', $selector->driver);
     }
     $parser = new jDaoParser($selector);
     $parser->parse(simplexml_import_dom($doc), $tools);
     $class = $selector->dbType . 'DaoBuilder';
     if (!jApp::includePlugin($selector->dbType, 'daobuilder', '.daobuilder.php', $class)) {
         throw new jException('jelix~dao.error.builder.notfound', $selector->dbType);
     }
     $generator = new $class($selector, $tools, $parser);
     // generation of PHP classes corresponding to the DAO definition
     $compiled = '<?php ';
     $compiled .= "\nif (jApp::config()->compilation['checkCacheFiletime']&&(\n";
     $compiled .= "\n filemtime('" . $daoPath . '\') > ' . filemtime($daoPath);
     $importedDao = $parser->getImportedDao();
     if ($importedDao) {
         foreach ($importedDao as $selimpdao) {
             $path = $selimpdao->getPath();
             $compiled .= "\n|| filemtime('" . $path . '\') > ' . filemtime($path);
         }
     }
     $compiled .= ")){ return false;\n}\nelse {\n";
     $compiled .= $generator->buildClasses() . "\n return true; }";
     jFile::write($selector->getCompiledFilePath(), $compiled);
     return true;
 }
示例#3
0
 public function run()
 {
     $this->loadAppConfig();
     #if ENABLE_OPTIMIZED_SOURCE
     require JELIX_LIB_PATH . 'dao/jDaoCompiler.class.php';
     // jDaoParser is in jDaoCompiler file
     #endif
     $path = $this->getModulePath($this->_parameters['module']);
     $filename = $path . 'forms/';
     $this->createDir($filename);
     $filename .= strtolower($this->_parameters['form']) . '.form.xml';
     if ($this->getOption('-createlocales')) {
         $locale_content = '';
         $locale_base = $this->_parameters['module'] . '~' . strtolower($this->_parameters['form']) . '.form.';
         $locale_filename_fr = $path . 'locales/fr_FR/';
         $this->createDir($locale_filename_fr);
         $locale_filename_fr .= strtolower($this->_parameters['form']) . '.UTF-8.properties';
         $locale_filename_en = $path . 'locales/en_EN/';
         $this->createDir($locale_filename_en);
         $locale_filename_en .= strtolower($this->_parameters['form']) . '.UTF-8.properties';
         $submit = "\n\n<submit ref=\"_submit\">\n\t<label locale='" . $locale_base . "ok' />\n</submit>";
     } else {
         $submit = "\n\n<submit ref=\"_submit\">\n\t<label>ok</label>\n</submit>";
     }
     $dao = $this->getParam('dao');
     if ($dao === null) {
         if ($this->getOption('-createlocales')) {
             $locale_content = "form.ok=OK\n";
             $this->createFile($locale_filename_fr, 'locales.tpl', array('content' => $locale_content));
             $this->createFile($locale_filename_en, 'locales.tpl', array('content' => $locale_content));
         }
         $this->createFile($filename, 'module/form.xml.tpl', array('content' => '<!-- add control declaration here -->' . $submit));
         return;
     }
     global $gJConfig;
     $gJConfig->startModule = $this->_parameters['module'];
     jContext::push($this->_parameters['module']);
     $tools = jDb::getConnection()->tools();
     // we're going to parse the dao
     $selector = new jSelectorDao($dao, '');
     $doc = new DOMDocument();
     $daoPath = $selector->getPath();
     if (!$doc->load($daoPath)) {
         throw new jException('jelix~daoxml.file.unknown', $daoPath);
     }
     if ($doc->documentElement->namespaceURI != JELIX_NAMESPACE_BASE . 'dao/1.0') {
         throw new jException('jelix~daoxml.namespace.wrong', array($daoPath, $doc->namespaceURI));
     }
     $parser = new jDaoParser($selector);
     $parser->parse(simplexml_import_dom($doc), $tools);
     // now 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->autoIncrement) {
             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 . '"';
         }
         $datatype = '';
         $tag = 'input';
         switch ($property->unifiedType) {
             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':
             case 'blob':
                 $tag = 'textarea';
                 break;
             case 'boolean':
                 $tag = 'checkbox';
                 break;
         }
         if ($datatype != '') {
             $attr .= ' type="' . $datatype . '"';
         }
         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.ok=OK\n";
         $this->createFile($locale_filename_fr, 'module/locales.tpl', array('content' => $locale_content));
         $this->createFile($locale_filename_en, 'module/locales.tpl', array('content' => $locale_content));
     }
     $this->createFile($filename, 'module/form.xml.tpl', array('content' => $content . $submit));
 }
示例#4
0
 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));
 }
 protected function import($xml, $tools)
 {
     if (isset($xml['import'])) {
         $import = (string) $xml['import'];
         jApp::pushCurrentModule($this->selector->module);
         // Keep the same driver as current used
         $importSel = new jSelectorDao($import, $this->selector->driver);
         jApp::popCurrentModule();
         $doc = new DOMDocument();
         if (!$doc->load($importSel->getPath())) {
             throw new jException('jelix~daoxml.file.unknown', $importSel->getPath());
         }
         $parser = new jDaoParser($importSel);
         $parser->parse(simplexml_import_dom($doc), $tools);
         $this->_properties = $parser->getProperties();
         $this->_tables = $parser->getTables();
         $this->_primaryTable = $parser->getPrimaryTable();
         $this->_methods = $parser->getMethods();
         $this->_ojoins = $parser->getOuterJoins();
         $this->_ijoins = $parser->getInnerJoins();
         $this->_eventList = $parser->getEvents();
         $this->_userRecord = $parser->getUserRecord();
         $this->_importedDao = $parser->getImportedDao();
         $this->hasOnlyPrimaryKeys = $parser->hasOnlyPrimaryKeys;
         if ($this->_importedDao) {
             $this->_importedDao[] = $importSel;
         } else {
             $this->_importedDao = array($importSel);
         }
     }
 }
示例#6
0
 protected function _execute(InputInterface $input, OutputInterface $output)
 {
     $module = $input->getArgument('module');
     $formName = $input->getArgument('form');
     $daoName = $input->getArgument('dao');
     require_once JELIX_LIB_PATH . 'dao/jDaoParser.class.php';
     $path = $this->getModulePath($module);
     $formdir = $path . 'forms/';
     $this->createDir($formdir);
     $formfile = strtolower($formName) . '.form.xml';
     if ($input->getOption('createlocales')) {
         $locale_content = '';
         $locale_base = $module . '~' . strtolower($formName) . '.form.';
         $locale_filename_fr = 'locales/fr_FR/';
         $this->createDir($path . $locale_filename_fr);
         $locale_filename_fr .= strtolower($formName) . '.UTF-8.properties';
         $locale_filename_en = 'locales/en_US/';
         $this->createDir($path . $locale_filename_en);
         $locale_filename_en .= strtolower($formName) . '.UTF-8.properties';
         $submit = "\n\n<submit ref=\"_submit\">\n\t<label locale='" . $locale_base . "ok' />\n</submit>";
     } else {
         $submit = "\n\n<submit ref=\"_submit\">\n\t<label>ok</label>\n</submit>";
     }
     if ($daoName === null) {
         if ($input->getOption('createlocales')) {
             $locale_content = "form.ok=OK\n";
             $this->createFile($path . $locale_filename_fr, 'locales.tpl', array('content' => $locale_content), "Locales file");
             $this->createFile($path . $locale_filename_en, 'locales.tpl', array('content' => $locale_content), "Locales file");
         }
         $this->createFile($formdir . $formfile, 'module/form.xml.tpl', array('content' => '<!-- add control declaration here -->' . $submit), "Form");
         return;
     }
     \Jelix\Core\App::config()->startModule = $module;
     \Jelix\Core\App::pushCurrentModule($module);
     $tools = \jDb::getConnection()->tools();
     // we're going to parse the dao
     $selector = new \jSelectorDao($daoName, '');
     $doc = new \DOMDocument();
     $daoPath = $selector->getPath();
     if (!$doc->load($daoPath)) {
         throw new \jException('jelix~daoxml.file.unknown', $daoPath);
     }
     if ($doc->documentElement->namespaceURI != JELIX_NAMESPACE_BASE . 'dao/1.0') {
         throw new \jException('jelix~daoxml.namespace.wrong', array($daoPath, $doc->namespaceURI));
     }
     $parser = new \jDaoParser($selector);
     $parser->parse(simplexml_import_dom($doc), $tools);
     // now 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->autoIncrement) {
             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 . '"';
         }
         $datatype = '';
         $tag = 'input';
         switch ($property->unifiedType) {
             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':
             case 'blob':
                 $tag = 'textarea';
                 break;
             case 'boolean':
                 $tag = 'checkbox';
                 break;
         }
         if ($datatype != '') {
             $attr .= ' type="' . $datatype . '"';
         }
         // use database comment to create form's label
         if ($property->comment != '' && $input->getOption('usecomments')) {
             if ($input->getOption('createlocales')) {
                 // replace special chars by dot
                 $locale_content .= 'form.' . $name . '=' . htmlspecialchars(utf8_decode($property->comment)) . "\n";
                 $content .= "\n\n<{$tag} ref=\"{$name}\"{$attr}>\n\t<label locale='" . $locale_base . $name . "' />\n</{$tag}>";
             } else {
                 // encoding special chars
                 $content .= "\n\n<{$tag} ref=\"{$name}\"{$attr}>\n\t<label>" . htmlspecialchars($property->comment) . "</label>\n</{$tag}>";
             }
         } else {
             if ($input->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 ($input->getOption('createlocales')) {
         $locale_content .= "form.ok=OK\n";
         $this->createFile($path . $locale_filename_fr, 'module/locales.tpl', array('content' => $locale_content), "Locales file");
         $this->createFile($path . $locale_filename_en, 'module/locales.tpl', array('content' => $locale_content), "Locales file");
     }
     $this->createFile($formdir . $formfile, 'module/form.xml.tpl', array('content' => $content . $submit), "Form file");
 }