]> git.nbdom.net Git - nb.git/commitdiff
lib/php/nb.php
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 6 Feb 2018 22:15:48 +0000 (22:15 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 6 Feb 2018 22:15:48 +0000 (22:15 +0000)
lib/php/db/table.php
lib/php/nb.php

index 7c20b523d5fe1601a7aa995edef75206dd741220..302f74e1009290e10272c9af51b75c96b138a8af 100644 (file)
@@ -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);
index fb0aa914a34eda1cac70af31f7ad48198f54b4f3..dfc0368f74eed4b9f997587ab9eebf61d5f6efaf 100644 (file)
@@ -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);