}
+ 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';
$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);
#
#
# Head
#
- if ($count === 1) {
+ if ($tot === 1) {
if ($opt['is_html']) echo $this->html_rows_top();
if ($call) {
$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);
}
}
- 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);