Search criteria with no entries (= no limitation on query) is now also accepted
authorRoland Häder <roland@mxchange.org>
Wed, 30 May 2012 22:30:08 +0000 (22:30 +0000)
committerRoland Häder <roland@mxchange.org>
Wed, 30 May 2012 22:30:08 +0000 (22:30 +0000)
inc/classes/main/criteria/class_BaseCriteria.php
inc/classes/main/database/databases/class_LocalFileDatabase.php

index a3daa36e1cb4ac5001756d22ff8d1b91444c5fee..e1c048c538f807847927fd13d1088d2f45155e98 100644 (file)
@@ -105,6 +105,9 @@ class BaseCriteria extends BaseFrameworkSystem {
                // Convert dashes to underscore
                $criteriaKey = $this->convertDashesToUnderscores($criteriaKey);
 
+               // Debug message
+               //* NOISY-DEBUG: */ $this->debugOutput('CRITERIA: criteriaKey=' . $criteriaKey . ',criteria()=' . count($this->criteria));
+
                // Default is not found
                $value = NULL;
 
@@ -112,7 +115,7 @@ class BaseCriteria extends BaseFrameworkSystem {
                if (isset($this->criteria[$criteriaKey])) {
                        // Then use it
                        $value = $this->criteria[$criteriaKey];
-               }
+               } // END - if
 
                // Return the value
                return $value;
@@ -197,6 +200,16 @@ class BaseCriteria extends BaseFrameworkSystem {
                // Return the cache key
                return $cacheKey;
        }
+
+       /**
+        * Count the criteria, e.g. useful to find out if a database query has no limitation (search criteria)
+        *
+        * @return      $count  Count of all criteria entries
+        */
+       public final function count () {
+               // Return it
+               return count($this->criteria);
+       }
 }
 
 // [EOF]
index 9c9c00bde531870addff78e18f3611f25ea5919f..38e67f1061b405c4654fb51c5f26b22e80752e77 100644 (file)
@@ -161,6 +161,9 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
         * @return      $dataArray
         */
        private function getDataArrayFromFile ($fqfn) {
+               // Debug message
+               //* NOISY-DEBUG: */ $this->debugOutput('DATABASE: Reading elements from database file ' . $fqfn . ' ...');
+
                // Get a file pointer
                $fileInstance = FrameworkFileInputPointer::createFrameworkFileInputPointer($fqfn);
 
@@ -177,6 +180,9 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
                // Unserialize it
                $dataArray = unserialize($serializedData);
 
+               // Debug message
+               //* NOISY-DEBUG: */ $this->debugOutput('DATABASE: Read ' . count($dataArray) . ' elements from database file ' . $fqfn . '.');
+
                // Finally return it
                return $dataArray;
        }
@@ -190,7 +196,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
         */
        private function writeDataArrayToFqfn ($fqfn, array $dataArray) {
                // Debug message
-               /* NOISY-DEBUG: */ $this->debugOutput('DATABASE: Flushing ' . count($dataArray) . ' elements to database file ' . $fqfn . ' ...');
+               //* NOISY-DEBUG: */ $this->debugOutput('DATABASE: Flushing ' . count($dataArray) . ' elements to database file ' . $fqfn . ' ...');
 
                // Get a file pointer instance
                $fileInstance = FrameworkFileOutputPointer::createFrameworkFileOutputPointer($fqfn, 'w');
@@ -205,7 +211,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
                $fileInstance->closeFile();
 
                // Debug message
-               /* NOISY-DEBUG: */ $this->debugOutput('DATABASE: Flushing ' . count($dataArray) . ' elements to database file completed.');
+               //* NOISY-DEBUG: */ $this->debugOutput('DATABASE: Flushing ' . count($dataArray) . ' elements to database file completed.');
        }
 
        /**
@@ -352,9 +358,9 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
                                                // Get criteria element
                                                $criteria = $criteriaInstance->getCriteriaElemnent($key);
 
-                                               // Is the criteria met?
-                                               //* NOISY-DEBUG: */ $this->debugOutput('DATABASE: criteria[' . gettype($criteria) . ']=' . $criteria . ',()=' . strlen($criteria) . ',value=' . $value . ',()=' . strlen($value));
-                                               if ((!is_null($criteria)) && ($criteria == $value))  {
+                                               // Is the criteria met or none set?
+                                               //* NOISY-DEBUG: */ $this->debugOutput('DATABASE: criteria[' . gettype($criteria) . ']=' . $criteria . ';()=' . strlen($criteria) . ',criteriaInstance()=' . $criteriaInstance->count() . ',value(' . strlen($value) . ')=' . $value);
+                                               if (((!is_null($criteria)) && ($criteria == $value)) || ($criteriaInstance->count() == 0))  {
                                                        // Shall we skip this entry?
                                                        if ($criteriaInstance->getSkip() > 0) {
                                                                // We shall skip some entries
@@ -467,6 +473,8 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
                        while (($dataFile = $directoryInstance->readDirectoryExcept(array('.', '..', '.htaccess', '.svn', 'info.' . $this->getFileExtension()))) && ($limitFound < $searchInstance->getLimit())) {
                                // Does the extension match?
                                if (substr($dataFile, -(strlen($this->getFileExtension()))) !== $this->getFileExtension()) {
+                                       // Debug message
+                                       /* NOISY-DEBUG: */ $this->debugOutput('DATABASE: dataFile=' . $dataFile . ',getFileExtension()=' . $this->getFileExtension());
                                        // Skip this file!
                                        continue;
                                } // END - if