From: Nicolas Boisselier Date: Thu, 21 Apr 2016 16:05:30 +0000 (+0100) Subject: wp table X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=70093d6c044f24a13dbf842982261f6a8829f7eb;p=nb.git wp table --- diff --git a/etc/dbs/ui.php b/etc/dbs/ui.php index 764816d0..60f8376b 100644 --- a/etc/dbs/ui.php +++ b/etc/dbs/ui.php @@ -11,7 +11,7 @@ $CONF['ui'] = array( 'aws_region_cidr' => "(SELECT cidr FROM aws_region WHERE aws_region.id=idaws_region)", 'aws_region_idvpc' => "(SELECT idvpc FROM aws_region WHERE aws_region.id=idaws_region)", 'aws_region_sg' => "(SELECT sg FROM aws_region WHERE aws_region.id=idaws_region)", - 'aws_instances' => "(SELECT count(*) FROM aws_instance WHERE aws_az.id=idaws_az)", + 'aws_ec2s' => "(SELECT count(*) FROM aws_ec2 WHERE aws_az.id=idaws_az)", 'idnetwork' => "(SELECT id FROM network WHERE network.id='subnet-' || aws_az.id)", 'network_subnet' => "(SELECT network FROM network WHERE network.id='subnet-' || aws_az.id)", 'ec2' => "'--region '||(SELECT id FROM aws_region WHERE aws_region.id=idaws_region)||' --subnet-id '||(SELECT id FROM aws_subnet WHERE aws_subnet.aws_azid=aws_az.id)||' --security-group-ids '||(SELECT sg FROM aws_region WHERE aws_region.id=idaws_region)||' --associate-public-ip-address --key-name semadm'" @@ -22,7 +22,7 @@ $CONF['ui'] = array( 'aws_region' => array( 'extras'=> array( 'aws_az' => "(SELECT count(*) FROM aws_az WHERE idaws_region=aws_region.id)", - 'aws_instance' => "(SELECT count(*) FROM aws_instance JOIN aws_az ON idaws_region=aws_region.id)", + 'aws_ec2' => "(SELECT count(*) FROM aws_ec2 JOIN aws_az ON idaws_region=aws_region.id)", 'aws_rds' => "(SELECT count(*) FROM aws_rds WHERE idaws_region=aws_region.id)", 'aws_elb' => "(SELECT count(*) FROM aws_elb WHERE idaws_region=aws_region.id)", ), @@ -94,7 +94,7 @@ $CONF['ui'] = array( UNION SELECT 'idvmware' as 'n',idvmware as 'v' FROM vms WHERE vms.idnode=node.id UNION SELECT 'rack' as'n',idrack as 'v' FROM rack_node WHERE id=idnode OR idnode IN (SELECT idvmware FROM vms WHERE vms.idnode=node.id) UNION SELECT 'env' as 'n',value as 'v' FROM fact WHERE fact.idnode=node.id AND name='environment' - UNION SELECT 'aws_instance' as 'n',id as 'v' FROM aws_instance WHERE aws_instance.idnode=node.id + UNION SELECT 'aws_ec2' as 'n',id as 'v' FROM aws_ec2 WHERE aws_ec2.idnode=node.id UNION SELECT 'file' as 'n',file as 'v' UNION SELECT 'last_backup' as 'n',''||max(date)||'' as 'v' FROM backup WHERE idnode=node.id UNION SELECT name as 'n', strftime('%Y-%m-%d',value) as 'v' FROM fact WHERE idnode=id AND name='last_run' AND value < date(CURRENT_DATE,'-7 days') || ' 00:00:00' diff --git a/lib/php/db.php b/lib/php/db.php index 7d081420..ba41429c 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -556,11 +556,11 @@ EOF; } # Connection - #bye($Db->p('db')); $db = array_merge($dbs[$Db->p('db')],array( 'dbs'=>array_keys($dbs), 'conf'=>$dbs, )); + #bye($Db->p('db')); $Db->__construct($db); diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 73e51f10..26a6c07e 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -32,7 +32,9 @@ Class Table extends nb { public $created; # hidden, sort, ... fields - public static $params = array( 'db', 'table', 'limit', 'debug', 'action', 'page'); + public static $params = array( 'db', 'table', 'limit', 'debug', 'action' + , 'page', 'paged' # wordpress + ); public $fields; @@ -585,6 +587,9 @@ 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 + if (self::p('paged')) { + self::pset( 'limit', (self::p('limit') * self::p('paged')).','.self::p('limit') ); + } // // Select @@ -765,11 +770,10 @@ Class Table extends nb { return; } - $this->tot = $opt['tot'] = $count; - $this->count = $opt['count'] = $count; - $this->limit = $opt['limit'] = $limit; + $opt['count'] = $count; + $opt['limit'] = $limit; - if ($opt['is_html']) { + if ($opt['is_html'] or $format=='wp') { // // Tot @@ -802,6 +806,10 @@ Class Table extends nb { } # < is_html + $this->tot = $opt['tot']; + $this->count = $opt['count']; + $this->limit = $opt['limit']; + if ($count === 0 and $this->p('header') === 'force') { echo $this->{"rows_begin_$format"}($this->fields()); } @@ -844,11 +852,15 @@ Class Table extends nb { } public function rows_end_wp() { + + $limit = preg_replace('/^.*,\s*/','',$this->limit); + $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 + 'total_items' => $this->tot, // total items defined above + 'per_page' => $limit, // per page constant defined at top of method + 'total_pages' => ceil($this->tot / $limit) // calculate pages count )); + #$this->_html_table->display_tablenav('top'); $this->_html_table->display(); #$this->_html_table->display_tablenav('bottom'); diff --git a/lib/php/db/wp.php b/lib/php/db/wp.php index 4c9dd2db..8bfcd927 100644 --- a/lib/php/db/wp.php +++ b/lib/php/db/wp.php @@ -69,11 +69,11 @@ return; debug($this->items); $total_items = $this->items; $per_page = $this->_table->p('limit'); - $this->set_pagination_args(array( + $this->set_pagination_args([ '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(); }