Exemple #1
0
 public static function get($DaoId, $profile = '')
 {
     $sel = new jSelectorDao($DaoId, $profile);
     $DaoId = $sel->toString();
     if (!isset(self::$_daoSingleton[$DaoId])) {
         self::$_daoSingleton[$DaoId] = self::create($sel, $profile);
     }
     return self::$_daoSingleton[$DaoId];
 }
 /**
  * @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);
 }
 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));
 }