]> git.nbdom.net Git - nb.git/commitdiff
wp table
authorNicolas Boisselier <nicolas.boisselier@semantico.com>
Wed, 20 Apr 2016 16:32:21 +0000 (17:32 +0100)
committerNicolas Boisselier <nicolas.boisselier@semantico.com>
Wed, 20 Apr 2016 16:32:21 +0000 (17:32 +0100)
lib/php/db/field.php
lib/php/db/table.php
lib/php/nb.php

index b422f938f1785f0c04ffa95ebe0c51d7b7e5b805..97d3364cb45467079b5c04b32ff029ce78c53f32 100644 (file)
@@ -8,7 +8,7 @@ $DB_FIELD_TYPES = array(
  'blob' => PDO::PARAM_LOB,
 );
 */
-class field {
+class field extends nb {
   private $table;
   public $name;
   public $type;
index 0d55567f4b584534cc33942a3e7a97fbb262cc14..721e9449dd9812ab2bd6961d92dddfe11b780314 100644 (file)
@@ -2,6 +2,7 @@
 require_once(realpath(dirname(__FILE__).'/../db.php'));
 require_once(realpath(dirname(__FILE__).'/../db/field.php'));
 require_once(realpath(dirname(__FILE__).'/../out.php'));
+if (class_exists('WP_List_Table')) require_once(realpath(dirname(__FILE__).'/wp.php'));
 #$a = array('a','b','c'); $b = array('c','a'); debug(array_diff($a,$b));
 
 define('TABLE_INDENT',NB_EOL ? "\t" : "");
@@ -583,6 +584,8 @@ Class Table extends nb {
   ******************************************************************/
   public function rows_sql(&$opt=array()) {
     if (isset($this->orderby)) self::pdef('orderby',$this->orderby);
+    if (self::p('order')) self::pset('orderby',self::p('orderby').' '.self::p('order')); # from Wordpress
+
     //
     // Select
     //
@@ -663,7 +666,7 @@ Class Table extends nb {
     # Use the module out when format unknow
     $out_conf = null;
     if ($this->p('out') or !preg_match('/^('.join('|',
-      array( 'table','sql','div','_csv','_xml','_json','_yaml' ) # local
+      array( 'table','sql','div','wp','_csv','_xml','_json','_yaml' ) # local
     ).')$/',$format))
     {
 
@@ -827,6 +830,24 @@ Class Table extends nb {
     return $count;
   }
 
+  /*-----------------------------------------------------------------
+    Wordpress
+  -----------------------------------------------------------------*/
+  public function rows_begin_wp() {
+    $this->_html_table = new html_table($this);
+
+    return '';
+  }
+  public function rows_rec_wp(&$row) {
+    $this->_html_table->items[] = $row;
+    return '';
+  }
+  public function rows_end_wp() {
+    $this->_html_table->display();
+    unset($this->_html_table);
+    return '';
+  }
+
   /*-----------------------------------------------------------------
     Sql
   -----------------------------------------------------------------*/
index d2820ad8245846bed7d579400aceda6c905f9e13..bc0171e056ac7e81d6e34d0b542b64947bb6e8ca 100644 (file)
@@ -48,7 +48,7 @@ class NB {
     #foreach (get_object_vars($this) as $k=>$v) { echo ("$k: $v\n"); }
     #if (is_object($this))
     #foreach (get_object_vars($this) as $k=>$v) { unset($this->$k); };
-    foreach (array_keys((array)$this) as $k) { unset($this->$k); };
+    foreach (array_keys((array)$this) as $k) { if (isset($this->$k)) unset($this->$k); };
   }
 
   /*