コード例 #1
0
ファイル: Router.php プロジェクト: rodacom/jelix
 /**
  * main method : launch the execution of the action.
  *
  * This method should be called in a entry point.
  *
  * @param  ClientRequest  $request the request object. It is required if a descendant of Router did not called setRequest before
  */
 public function process($request = null)
 {
     try {
         if ($request) {
             $this->setRequest($request);
         }
         \jSession::start();
         $ctrl = $this->getController($this->action);
     } catch (\jException $e) {
         $config = App::config();
         if ($config->urlengine['notfoundAct'] == '') {
             throw $e;
         }
         if (!\jSession::isStarted()) {
             \jSession::start();
         }
         try {
             $this->action = new \jSelectorAct($config->urlengine['notfoundAct']);
             $ctrl = $this->getController($this->action);
         } catch (\jException $e2) {
             throw $e;
         }
     }
     App::pushCurrentModule($this->moduleName);
     if (count($this->plugins)) {
         $pluginparams = array();
         if (isset($ctrl->pluginParams['*'])) {
             $pluginparams = $ctrl->pluginParams['*'];
         }
         if (isset($ctrl->pluginParams[$this->action->method])) {
             $pluginparams = array_merge($pluginparams, $ctrl->pluginParams[$this->action->method]);
         }
         foreach ($this->plugins as $name => $obj) {
             $result = $this->plugins[$name]->beforeAction($pluginparams);
             if ($result) {
                 $this->action = $result;
                 App::popCurrentModule();
                 App::pushCurrentModule($result->module);
                 $this->moduleName = $result->module;
                 $this->actionName = $result->resource;
                 $ctrl = $this->getController($this->action);
                 break;
             }
         }
     }
     $this->response = $ctrl->{$this->action->method}();
     if ($this->response == null) {
         throw new \jException('jelix~errors.response.missing', $this->action->toString());
     }
     foreach ($this->plugins as $name => $obj) {
         $this->plugins[$name]->beforeOutput();
     }
     $this->response->output();
     foreach ($this->plugins as $name => $obj) {
         $this->plugins[$name]->afterProcess();
     }
     App::popCurrentModule();
     \jSession::end();
 }
コード例 #2
0
ファイル: jApp.php プロジェクト: rodacom/jelix
 static function pushCurrentModule($module)
 {
     \Jelix\Core\App::pushCurrentModule($module);
 }
コード例 #3
0
ファイル: CreateForm.php プロジェクト: mdouchin/jelix
 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");
 }