]> git.nbdom.net Git - nb.git/commitdiff
Bed
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 6 Dec 2016 01:05:01 +0000 (01:05 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 6 Dec 2016 01:05:01 +0000 (01:05 +0000)
lib/php/db.php
lib/php/db/table.php
lib/php/out.php
lib/php/page.php
www/dbq/html/default.css

index 575ef3d9df5964659befd33fa202940c9354242c..528653ad03be90e177ba5e805d2c48457d2c8167 100644 (file)
@@ -549,7 +549,7 @@ class Db extends nb {
     return '"'.$value.'"';
   }
 
-  public function out($rows,$head=[]) {
+  public function out($rows,$head=[],$conf=[]) {
 
     if ($this->format) {
       $format = $this->format;
@@ -577,15 +577,11 @@ class Db extends nb {
 
     }
 
-    if (!empty($this->out_parser)) {
-      $fct = $this->out_parser;
-      $fct($rows);
-    }
-    $this->out->rows($format,$rows,$head);
+    $this->out->rows($format,$rows,$head,$conf);
     return true;
   }
 
-  public function tables_rows($o) {
+  public function tables_rows($o=[]) {
     # Options
     # Filters
     $type = empty($o['type']) ? '' : $o['type'];
index f1ff7979b38ef0775da9e813490af026270510cc..6c756d7cacedad8aecaa64ec3f4cc5fb7b1c22ae 100644 (file)
@@ -32,14 +32,16 @@ Class Table extends nb {
   public $created;
   public static $is_admin = true;
 
+  public $fields = [];
+  public $indexes;
+
+  public $itemplate_id;
+
   # hidden, sort, ... fields
   public static $params = [ 'db', 'table', 'limit', 'debug', 'action'
     , 'page', 'paged' # wordpress
   ];
 
-  public $fields = [];
-  public $indexes;
-
   function __construct($name,$opt=[]) {
 
     if (!is_scalar($name)) {
@@ -764,7 +766,7 @@ Class Table extends nb {
 
     if ($opt['is_html'] and !$opt['use_out']) {
       foreach ($row as $k=>$v) {
-        if (!isset($this->extras[$k])) $row[$k] = out::format($v);
+        if (!isset($this->extras[$k])) $row[$k] = $this->db()->out->format($v);
       }
 
     }
@@ -838,11 +840,11 @@ Class Table extends nb {
     {
 
       $opt['use_out'] = true;
-      if (!($out_conf = out::types($format))) $this->bye("Unknow format `$format`");
+      if (!($out_conf = $this->db()->out->types($format))) $this->bye("Unknow format `$format`");
       $out_conf = array_merge($opt,$out_conf);
 
       # Function name should be format
-      out::type($format); self::$params += array_values(out::types());
+      $this->db()->out->type($format); self::$params += array_values($this->db()->out->types());
 
       if (empty($out_conf['enclose'])) $out_conf['enclose'] = ['',''];
       debug('Using out module!',3);
@@ -867,7 +869,7 @@ Class Table extends nb {
        if (!$this->p('inc')) echo $this->form_hidden();
     }
 
-    if ($opt['is_html']) out::type('html');
+    if ($opt['is_html']) $this->db()->out->type('html');
 
     #
     # Rows
@@ -916,7 +918,7 @@ Class Table extends nb {
         }
 
         if ($out_conf) {
-          out::head($out_conf,array_keys($fields),[$row]);
+          $this->db()->out->head($out_conf,array_keys($fields),[$row]);
 
         } else {
           echo $this->{"rows_begin_$format"}($fields,$opt);
@@ -938,7 +940,7 @@ Class Table extends nb {
       }
 
       if ($out_conf) {
-        out::row($out_conf,$row);
+        $this->db()->out->row($out_conf,$row);
 
       } else {
         echo $this->{"rows_rec_$format"}($row,$opt);
@@ -993,7 +995,7 @@ Class Table extends nb {
     }
 
     if ($out_conf) {
-      out::end($out_conf);
+      $this->db()->out->end($out_conf);
 
     } else {
       echo $this->{"rows_end_$format"}();
@@ -1036,7 +1038,7 @@ Class Table extends nb {
     Template
   -----------------------------------------------------------------*/
   public function rows_begin_template($fields,&$o) {
-    $id = self::templateid();
+    $id = $this->template_id();
 
     $id = preg_replace('/[^\w\._-]/','',$id);
 
@@ -1494,7 +1496,7 @@ Class Table extends nb {
     return $info['rowCount'];
   }
 
-  public function out($v,$head=[]) { return $this->db()->out($v,$head); }
+  public function out($v,$head=[],$conf=[]) { return $this->db()->out($v,$head,$conf); }
 
   private function url_referer($default='') {
     if (self::p('referer')) {
@@ -1506,37 +1508,42 @@ Class Table extends nb {
     }
   }
 
-  public function action($action=null) {
-    #if (empty($action)) return;
-    #if ($action === null) $action = $this->p('action');
-    #debug($action);
+  public function fields_rows() {
+    $rows = array_values($this->object2array($this->fields()));
 
-    if ($action == 'table.fields') {
-      $rows = array_values($this->object2array($this->fields()));
+    list($sql,$where,$limit,$select_count) = $this->rows_sql();
+    foreach ([
+      'maxlen' => 'MAX(LENGTH(<NAME>))',
+      'max' => 'MAX(<NAME>)',
+    ] as $name => $select) {
+      if ($this->p($name)) {
+        $sql = '';
 
-      list($sql,$where,$limit,$select_count) = $this->rows_sql();
-      foreach ([
-        'maxlen' => 'MAX(LENGTH(<NAME>))',
-        'max' => 'MAX(<NAME>)',
-      ] as $name => $select) {
-        if ($this->p($name)) {
-          $sql = '';
-
-          foreach ($this->fields() as $f) {
-            $sql .= ($sql == '' ? 'SELECT ' : ', '); 
-            $sql .= str_replace('<NAME>',$f->sql_name(),$select);
-          }
+        foreach ($this->fields() as $f) {
+          $sql .= ($sql == '' ? 'SELECT ' : ', '); 
+          $sql .= str_replace('<NAME>',$f->sql_name(),$select);
+        }
 
-          $sql .= ' FROM ' . $this->sql_name() . $where . ($limit ? " LIMIT ".$limit : '');
-          $len = $this->db()->query($sql)->fetch(PDO::FETCH_NUM);
+        $sql .= ' FROM ' . $this->sql_name() . $where . ($limit ? " LIMIT ".$limit : '');
+        $len = $this->db()->query($sql)->fetch(PDO::FETCH_NUM);
 
-          $i = 0;
-          foreach ($rows as $k => $v) { $rows[$k][$name] = $len[$i]; $i++; }
+        $i = 0;
+        foreach ($rows as $k => $v) { $rows[$k][$name] = $len[$i]; $i++; }
 
-        }
       }
+    }
+
+    #return $this->out(array_values($this->object2array($this->fields())));
+    return $rows;
+  }
 
-      #return $this->out(array_values($this->object2array($this->fields())));
+  public function action($action=null) {
+    #if (empty($action)) return;
+    #if ($action === null) $action = $this->p('action');
+    #debug($action);
+
+    if ($action == 'table.fields') {
+      $rows = $this->fields_rows();
       return $this->out($rows);
 
     } elseif ($action == 'table.rows') {
@@ -1861,16 +1868,17 @@ Class Table extends nb {
     return $this->status;
   }
 
-  private static function templateid($id=null) {
+  private function template_id($id=null) {
     if (empty($id)
       and !( $id=self::p('table.template.id') )
       and !( $id=self::p('idtemplate') )
+      and !( $id = $this->template_id )
     ) self::bye('Wrong parameter!');
     return $id;
   }
 
   public function template($id=null) {
-    $id = self::templateid($id);
+    $id = $this->template_id($id);
 
     $id = preg_replace('/[^\w\._-]/','',$id);
 
index d619ebd4aafabfd68d0486670bdf2e231e08de8d..292a0abc1b33ab67fda29951cd78973ed43e8e08 100644 (file)
@@ -222,6 +222,9 @@ Class Out extends Nb {
       unset($opt[$k]);
     }
 
+# NB 05.12.16     if (isset($opt['format'])) self::type($opt['format']);
+# NB 05.12.16     unset($opt['format']);
+
     if (self::type() and !empty($data)) return self::rows(self::type(),$data,$head);
     return parent::__construct($opt);
   }
@@ -446,6 +449,9 @@ Class Out extends Nb {
     foreach ($row as $k => $v) {
       $v = out::format($v,null,$o);
     }
+    if (isset($o['row_parse_post'])) {
+      $o['row_parse_post']($row);
+    }
   }
 
   public static function format($v,$type=null,$o=[]) {
index 57b6d0dd2473cc1258a959d12990838a11e1c7b5..0480aa597fddcaddd39e14379bb9d7ea9ec299bf 100644 (file)
@@ -86,8 +86,9 @@ class Page extends nb {
     parent::__construct($opt);
 
     // Defaults
-    if ( empty($this->title) ) $this->title = !empty($title) ? join($this->sep,$title) : $this->filename2title();
-    if ( empty($this->h1) ) $this->h1 = !empty($nav) ? join($this->sep,$nav) : $this->title;
+# NB 06.12.16     if ( empty($this->title) ) $this->title = !empty($title) ? join($this->sep,$title) : $this->filename2title();
+# NB 06.12.16     if ( empty($this->h1) ) $this->h1 = !empty($nav) ? join($this->sep,$nav) : $this->title;
+    if ( empty($this->title) ) $this->title = !empty($nav) ? join($this->sep,$nav) : $this->filename2title();
 
     // Call / Print
     if (!empty($this->call)) $this->call($this->call);
@@ -179,9 +180,9 @@ class Page extends nb {
    * Function: tag
    * Return html code for a tag
    */
-  public static function h1($content='',$attrs='') { return self::tag('h1',$content,$attrs); }
-  public static function div($content='',$attrs='') { return self::tag('div',$content,$attrs); }
-  public static function pp($content='',$attrs='') { return self::tag('p',$content,$attrs); }
+# NB 06.12.16   public static function h1($content='',$attrs='') { return self::tag('h1',$content,$attrs); }
+# NB 06.12.16   public static function div($content='',$attrs='') { return self::tag('div',$content,$attrs); }
+# NB 06.12.16   public static function pp($content='',$attrs='') { return self::tag('p',$content,$attrs); }
   public static function tag($tag,$content='',$attrs='') {
     static $is_html = null;
     if ($is_html === null) $is_html = preg_match('/ml$/',self::content_type()) ? true : false;
index fc12023ee1b6979a63b0747e0abec007a7019c2f..4d4b68050267f942aa62941e85c76a2785793546 100644 (file)
@@ -8,7 +8,6 @@ body {
   margin-right: auto;
   padding-left: 1em;
   padding-right: 1em;
-  background-color: #E6E6E6;
   background-color: #009B9C;
 }
 
@@ -68,8 +67,8 @@ object, iframe, pre
 {
   border-collapse: separate;
   border-spacing: 0;
-  border-radius: 4px;
-  border: solid 1px #fff;
+  border-radius: 2px;
+  border: solid 1px #ddd;
 
   padding: 0.5em 0.2em;
   margin-bottom: 0.5em;
@@ -77,7 +76,7 @@ object, iframe, pre
 }
 
 table.rows { padding: 0; }
-table.rows th, table.rows td { border-bottom: solid 1px #fff; }
+table.rows th, table.rows td { border-bottom: solid 1px #ddd; }
 table.rows tr:last-child td { border-bottom: none; }
 
 .menu, .nav, .rows,
@@ -98,10 +97,7 @@ table.rows tr:last-child td { border-bottom: none; }
   background-color: #ddd;
        border: solid 1px #ddd;
   border-radius: 4px;
-       -webkit-border-radius: 4px;
        white-space: nowrap;
-       -webkit-box-sizing: border-box;
-       -moz-box-sizing: border-box;
        box-sizing: border-box;
   color: #ddd;
        margin: 0;