From c9a75125e8bda5c7d2a8c382b06734c06a42def4 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Tue, 6 Feb 2018 22:15:48 +0000 Subject: [PATCH] lib/php/nb.php --- lib/php/db/table.php | 23 ++++++++--- lib/php/nb.php | 95 +++++++++++++++++++++++--------------------- 2 files changed, 66 insertions(+), 52 deletions(-) diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 7c20b523..302f74e1 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -747,6 +747,17 @@ Class Table extends nb { } + private function row_match($row,$patterns,$fields=null) { + if ($fields === null) $fields = $this->fields(); + foreach ($fields as $k => $field) { + if (!isset($patterns[$k])) continue; + if (!isset($row[$k])) $row[$k] = null; + if ($this->str_match($row[$k],$patterns[$k])) continue; + return false; + } + return true; + } + private function where_criterias($values,$logic='') { $having = $where = []; if (empty($logic)) $logic = 'AND'; @@ -1188,13 +1199,15 @@ Class Table extends nb { $this->db()->type = $db_type; } - $count = 0; + $tot = $count = 0; #while ((empty($fct) or $fct()) and $row = $st->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT)) { while ($row = $fct($this)) { $count++; - $call = null; + if ($nosql and !$this->row_match($row,$this->p(),$fields)) continue; + $tot++; + $call = null; $call = $this->rows_parsers($row,$opt); # @@ -1205,7 +1218,7 @@ Class Table extends nb { # # Head # - if ($count === 1) { + if ($tot === 1) { if ($opt['is_html']) echo $this->html_rows_top(); if ($call) { @@ -1280,10 +1293,8 @@ Class Table extends nb { $tot = $query->fetch(PDO::FETCH_COLUMN); $this->tot = $opt['tot'] = $tot; - } else { - $this->tot = $opt['tot'] = $count; - } # < is_html + $this->tot = $opt['tot'] = $count; if ($count === 0 and !$format) { echo $this->{"rows_begin_$format"}($fields,$opt); diff --git a/lib/php/nb.php b/lib/php/nb.php index fb0aa914..dfc0368f 100644 --- a/lib/php/nb.php +++ b/lib/php/nb.php @@ -734,60 +734,63 @@ class NB { } } - public static function str_match($string,$patterns) { + public static function str_match($strings,$patterns) { $match = false; - foreach ((array)$patterns as $pattern) { - - // No empty values - if (strcmp($pattern,'')==0 or $pattern=='!' or $pattern=='~') return false; - - // Equal / Not Equal - $equal = '='; - $not = strpos($pattern,'!')===0 ? true : false; - if ($not) $pattern = substr($pattern,1); - - // Regex - if (strpos($pattern,'~')===0) { - $pattern = substr($pattern,1); - $match = preg_match('@'.str_replace('@','\@',$pattern).'@i',$string); - - // Superior - } elseif (strpos($pattern,'>')===0) { - $pattern = substr($pattern,1); - $match = ($string > $pattern); - } elseif (strpos($pattern,'>=')===0) { - $pattern = substr($pattern,2); - $match = ($string >= $pattern); - - // Inferior - } elseif (strpos($pattern,'<')===0) { - $pattern = substr($pattern,1); - $match = ($string < $pattern); - } elseif (strpos($pattern,'<=')===0) { - $pattern = substr($pattern,2); - $match = ($string <= $pattern); - - // Match - } elseif(preg_match('/['.preg_quote('*?[]!').']/',$pattern)) { - $match = fnmatch($pattern,$string,FNM_CASEFOLD); - - // Default - } else { + foreach ((array)$strings as $string) { - if (strtolower($pattern)=='null') { - $pattern = ''; - if (!$string) $string = 0; - } + foreach ((array)$patterns as $pattern) { + + // No empty values + if (strcmp($pattern,'')==0 or $pattern=='!' or $pattern=='~') return false; + + // Equal / Not Equal + $equal = '='; + $not = strpos($pattern,'!')===0 ? true : false; + if ($not) $pattern = substr($pattern,1); - $match = (strtolower($pattern) == strtolower($string)); + // Regex + if (strpos($pattern,'~')===0) { + $pattern = substr($pattern,1); + $match = preg_match('@'.str_replace('@','\@',$pattern).'@i',$string); + // Superior + } elseif (strpos($pattern,'>')===0) { + $pattern = substr($pattern,1); + $match = ($string > $pattern); + } elseif (strpos($pattern,'>=')===0) { + $pattern = substr($pattern,2); + $match = ($string >= $pattern); + + // Inferior + } elseif (strpos($pattern,'<')===0) { + $pattern = substr($pattern,1); + $match = ($string < $pattern); + } elseif (strpos($pattern,'<=')===0) { + $pattern = substr($pattern,2); + $match = ($string <= $pattern); + + // Match + } elseif(preg_match('/['.preg_quote('*?[]!').']/',$pattern)) { + $match = fnmatch($pattern,$string,FNM_CASEFOLD); + + // Default + } else { + + if (strtolower($pattern)=='null') { + $pattern = ''; + if (!$string) $string = 0; + } + + $match = (strtolower($pattern) == strtolower($string)); + + } + + $match = (bool)($not ? !$match : $match); + if ($match) break; } - $match = (bool)($not ? !$match : $match); - if ($match) break; } - return $match; # NB 10.01.18 return (bool)($not ? !$match : $match); -- 2.47.3