From: Nicolas Boisselier Date: Thu, 21 Apr 2016 11:12:51 +0000 (+0100) Subject: wp table X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=d2e16bf182102039228388b1b7d718b47112c415;p=nb.git wp table --- diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 09660aa8..73e51f10 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -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 ''; } diff --git a/lib/php/db/wp.php b/lib/php/db/wp.php index 24b362d2..4c9dd2db 100644 --- a/lib/php/db/wp.php +++ b/lib/php/db/wp.php @@ -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 { */ } - 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(); } diff --git a/lib/php/functions.php b/lib/php/functions.php index a133f77b..08856f41 100644 --- a/lib/php/functions.php +++ b/lib/php/functions.php @@ -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];