]> git.nbdom.net Git - nb.git/commitdiff
wp table
authorNicolas Boisselier <nicolas.boisselier@semantico.com>
Wed, 20 Apr 2016 20:57:25 +0000 (21:57 +0100)
committerNicolas Boisselier <nicolas.boisselier@semantico.com>
Wed, 20 Apr 2016 20:57:25 +0000 (21:57 +0100)
lib/php/db/wp.php [new file with mode: 0644]

diff --git a/lib/php/db/wp.php b/lib/php/db/wp.php
new file mode 100644 (file)
index 0000000..608b00d
--- /dev/null
@@ -0,0 +1,47 @@
+<?php
+class html_table extends WP_List_Table {
+
+  public $_table;
+  #var $items = array();
+
+       public function __construct($table) {
+    parent::__construct();
+    $this->_table = $table;
+#debug($table);
+    #$fields = $this->get_columns();
+    #debug($sort);
+    $this->_column_headers = array($this->get_columns(), array(), $this->get_sortable_columns());
+    return;
+  }
+
+       protected function column_default( $item, $column_name ) { echo $item[$column_name]; }
+
+       public function get_columns() {
+    static $cols = array();
+    if (empty($cols)) {
+        foreach ($this->_table->fields() as $f) {
+          $cols[$f->name] = $f->prettyText($f->name);
+        }
+        #$cols = array_map(function($k,$v){return array($v=>$this->_table->prettyText($v));},$fields,$fields);
+    }
+    return $cols;
+       }
+
+       protected function get_sortable_columns() {
+    $sort = array();
+    foreach ($this->get_columns() as $k =>$v) {
+      #$sort[$k] = array($v => array($k,false));
+      $sort[$k] = array($k,false);
+    }
+    return $sort;
+               return $this->get_columns();
+       }
+
+       public function prepare_items() {
+    $sql = $this->_table->rows_sql($opt);
+    $st = $GLOBALS['wpdb']->prepare($sql);
+    return $st->execute();
+       }
+
+}
+?>