]> git.nbdom.net Git - nb.git/commitdiff
wp table
authorNicolas Boisselier <nicolas.boisselier@semantico.com>
Thu, 21 Apr 2016 11:12:51 +0000 (12:12 +0100)
committerNicolas Boisselier <nicolas.boisselier@semantico.com>
Thu, 21 Apr 2016 11:12:51 +0000 (12:12 +0100)
lib/php/db/table.php
lib/php/db/wp.php
lib/php/functions.php

index 09660aa86212878a49de8b8de427f3a430e31a84..73e51f10487a09d221b6be8a7422829b43d98754 100644 (file)
@@ -765,9 +765,9 @@ Class Table extends nb {
       return;
     }
 
-    $opt['tot'] = $count;
-    $opt['count'] = $count;
-    $opt['limit'] = $limit;
+    $this->tot = $opt['tot'] = $count;
+    $this->count = $opt['count'] = $count;
+    $this->limit = $opt['limit'] = $limit;
 
     if ($opt['is_html']) {
 
@@ -835,15 +835,23 @@ Class Table extends nb {
   -----------------------------------------------------------------*/
   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->set_pagination_args(array(
+      'total_items' => $this->count, // total items defined above
+      'per_page' => $this->limit, // per page constant defined at top of method
+      'total_pages' => ceil($this->count / $this->limit) // calculate pages count
+    ));
+    #$this->_html_table->display_tablenav('top');
     $this->_html_table->display();
+    #$this->_html_table->display_tablenav('bottom');
     unset($this->_html_table);
     return '';
   }
index 24b362d23abebacdc48c0e10f6b2086a076c774f..4c9dd2dbe88d6204ac8fd94a4f0d305e03eff371 100644 (file)
@@ -11,8 +11,6 @@ class html_table extends WP_List_Table {
     #$fields = $this->get_columns();
     #debug($sort);
     $this->_column_headers = array($this->get_columns(), array(), $this->get_sortable_columns());
-    $_REQUEST['s'] = ' ';
-    $this->search_box();
     return;
   }
 
@@ -39,7 +37,7 @@ class html_table extends WP_List_Table {
        <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" />
   */
        }
-       protected function column_default( $item, $column_name ) { echo $item[$column_name]; }
+       protected function column_default( $item, $column_name ) { return $item[$column_name]; }
 
        public function get_columns() {
     static $cols = array();
@@ -56,15 +54,26 @@ class html_table extends WP_List_Table {
     $sort = array();
     foreach ($this->get_columns() as $k =>$v) {
       #$sort[$k] = array($v => array($k,false));
-      $sort[$k] = array($k,false);
+      $sort[$k] = array($k,$this->_table->p('orderby') == $k ? true : false);
     }
     return $sort;
                return $this->get_columns();
        }
 
-       public function prepare_items() {
-    $sql = $this->_table->rows_sql($opt);
+       public function _prepare_items() {
+debug('prepare_items');
+return;
+    list($sql,$where,$limit,$select_count) = $this->_table->rows_sql($opt);
     $st = $GLOBALS['wpdb']->prepare($sql);
+    $this->items = $wpdb->get_results($st, ARRAY_A);
+    debug($this->items);
+    $total_items = $this->items;
+    $per_page = $this->_table->p('limit');
+    $this->set_pagination_args(array(
+      'total_items' => $total_items, // total items defined above
+      'per_page' => $per_page, // per page constant defined at top of method
+      'total_pages' => ceil($total_items / $per_page) // calculate pages count
+    ));
     return $st->execute();
        }
 
index a133f77b0d42085d0b979bb44b0e5728e7d99d7d..08856f41037ff343be019048a73389c6d0c99889 100644 (file)
@@ -37,7 +37,7 @@ function ls_dir($path,$recurse=false,$exp='') {
   while($file = readdir($rep)) {
 
     if ($file == '.' or $file == '..') continue;
-    
+
     if (!$exp or preg_match('#\.('.$exp.')$#',$file)) {
       $ls[] = $file;
     }
@@ -269,7 +269,7 @@ if (!function_exists('array_replace_recursive')) {
         if (!isset($array[$key]) || (isset($array[$key]) && !is_array($array[$key]))) {
           $array[$key] = array();
         }
+
         // overwrite the value in the base array
         if (is_array($value)) {
           $value = recurse($array[$key], $value);
@@ -281,7 +281,7 @@ if (!function_exists('array_replace_recursive')) {
 
       return $array;
     }
+
     // handle the arguments, merge one by one
     $args = func_get_args();
     $array = $args[0];