From fa30f4b0f79eb02165f549ad476c8916a50cca92 Mon Sep 17 00:00:00 2001 From: Viktor Pedersen <viktor@dsv.su.se> Date: Wed, 8 Sep 2021 16:05:43 +0200 Subject: [PATCH] testing search function --- include/Product.php | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/include/Product.php b/include/Product.php index 3362e72..5ff909f 100644 --- a/include/Product.php +++ b/include/Product.php @@ -122,38 +122,43 @@ class Product extends Entity { if(property_exists($this, $field)) { if(match($values, $this->$field)) { $matches[$field] = $this->$field; + } else { + if($matchAll) { + return array(); + } } } else if(array_key_exists($field, $this->get_info())) { if(match($values, $this->get_info()[$field])) { $matches[$field] = $this->get_info()[$field]; + } else { + if($matchAll) { + return array(); + } } } else if($field == 'tag') { foreach($this->get_tags() as $tag) { if(match($values, $tag)) { - $matches['tags'] = $this->get_tags(); + if(!array_key_exists('tags', $matches)) { + $matches['tags'] = array(); + } + $matches['tags'][] = $tag; break; + } else { + if($matchAll) { + return array(); + } } } } else if($field == 'status') { if(match($values, $this->get_status())) { $matches['status'] = $this->get_status(); + } else { + if($matchAll) { + return array(); + } } } } - - if($matchAll && array_diff_assoc($terms, $matches)) { - print('=== DEBUG $terms ===<br>'); - var_dump($terms); - print('<br><br>'); - print('=== DEBUG diff $terms and $matches ===<br>'); - var_dump(array_diff_assoc($terms, $matches)); - print('<br><br>'); - print('=== DEBUG $matches ===<br>'); - var_dump($matches); - print('<br><br>'); - - return array(); - } return $matches; }