]> git.nbdom.net Git - nb.git/commitdiff
www/dbq/dbq.php template
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Sat, 9 Dec 2017 04:30:11 +0000 (04:30 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Sat, 9 Dec 2017 04:30:11 +0000 (04:30 +0000)
lib/php/db/table.php
www/dbq/dbq.php

index 72c4f19081fe6cdc2d3c4efbcb6ea2d350aaad7e..e3c0abe940b6cdc4314f26d734af1889ea9e8ad7 100644 (file)
@@ -39,7 +39,7 @@ Class Table extends nb {
   public $fields = [];
   public $indexes;
 
-  public $itemplate_id;
+  public $idtemplate;
 
   # hidden, sort, ... fields
   public $show_hidden_params = true;
@@ -1270,7 +1270,7 @@ Class Table extends nb {
     Template
   -----------------------------------------------------------------*/
   public function rows_begin_template($fields,&$o) {
-    $id = $this->template_id();
+    $id = $this->idtemplate();
 
     $id = preg_replace('/[^\w\._-]/','',$id);
 
@@ -2193,17 +2193,16 @@ Class Table extends nb {
     return $this->status;
   }
 
-  private function template_id($id=null) {
+  private function idtemplate($id=null) {
     if (empty($id)
-      and !( $id=$this->p('table.template.id') )
       and !( $id=$this->p('idtemplate') )
-      and !( $id = $this->template_id )
+      and !( $id = $this->idtemplate )
     ) $this->bye('Wrong parameter!');
     return $id;
   }
 
   public function template($id=null) {
-    $id = $this->template_id($id);
+    $id = $this->idtemplate($id);
 
     $id = preg_replace('/[^\w\._-]/','',$id);
 
index 8755aad195de16379d0d7743a5daa2f09fefd6dd..0bb9320f604daa2a531a34601826221e1ada0b83 100644 (file)
@@ -79,8 +79,6 @@ class DbQ extends nb {
        public $table;
        public $db;
 
-       protected $idtemplate;
-
        public function __construct($opt=[]) {
                //
                // Pre defaults values
@@ -339,7 +337,7 @@ class DbQ extends nb {
                                }
                        }
 
-                       if ($this->params['format'] == $this->format_cli) $this->db->format = $this->params['format'] = 'txt';
+                       if ($this->params['format'] == $this->format_cli) $this->format('txt');
                        $this->db->out->header($this->p('header',false));
                        $this->db->out($row);
                        return;
@@ -403,8 +401,25 @@ class DbQ extends nb {
        }
 
 
+       public function format($set=null) {
+               if ($set === null) return $this->params['format'];
+               $this->db->format = $this->params['format'] = $set;
+       }
+
        public function table($param=[]) {
 
+# NB 08.12.17          if ($this->format() == 'tmpl') {
+                       #bye($param);
+                       if (preg_match("/^(.*)\.(tmpl)$/",$this->params['table'],$m)) {
+#bye($this->params['table']);
+                                       $this->params['table'] = $m[1];
+                                       $param['idtemplate'] = $this->format();
+                                       $this->format('template');
+# NB 08.12.17                  } else {
+# NB 08.12.17                                  $this->error("Template id is missing");
+# NB 08.12.17                  }
+               }
+
                if (!in_array($this->params['table'],array_keys($this->db->tables()))) {
 
                        # We Allow SELECT only in admin
@@ -423,6 +438,11 @@ class DbQ extends nb {
 
                $this->table->base = $this->db->base.'/'.$this->table->name;
 
+               if (isset($param['idtemplate'])) {
+                       $this->table->base .= '.tmpl.' . $param['idtemplate'];
+                       #bye([$this->table,$this->db->format]);
+               }
+
        }
 
        public function title_nav() {
@@ -687,11 +707,6 @@ EOF;
                // Format first !
                if ($this->params['format']) {
                        $format = $this->params['format'];
-# NB 08.12.17: TODO 
-# NB 08.12.17                  if (preg_match("/^(.*)\.tmpl/",$format,$m)) {
-# NB 08.12.17                          $this->idtemplate = $m[1];
-# NB 08.12.17                          $format = 'template';
-# NB 08.12.17                  }
 
                } else if ($content_type = self::client_content_type() and ( $format=Mime::toExt($content_type) )) {
                        #$format = $format;
@@ -719,8 +734,9 @@ EOF;
 
                // Affect values to objects
                if ($format == 'html') $format = $this->format_html;
-               $this->params['format'] = $format;
-               $this->db->format = $format;
+               $this->format($format);
+# NB 08.12.17          $this->params['format'] = $format;
+# NB 08.12.17          $this->db->format = $format;
                $this->is_html = strpos($content_type,'html') ? true : false;
                $this->db->is_html = $this->is_html;