From: Roland Häder Date: Wed, 30 May 2012 22:30:08 +0000 (+0000) Subject: Search criteria with no entries (= no limitation on query) is now also accepted X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=6966c5ab4eaf26294d9dffb48037ed51d6ac8f46;p=core.git Search criteria with no entries (= no limitation on query) is now also accepted --- diff --git a/inc/classes/main/criteria/class_BaseCriteria.php b/inc/classes/main/criteria/class_BaseCriteria.php index a3daa36e..e1c048c5 100644 --- a/inc/classes/main/criteria/class_BaseCriteria.php +++ b/inc/classes/main/criteria/class_BaseCriteria.php @@ -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] diff --git a/inc/classes/main/database/databases/class_LocalFileDatabase.php b/inc/classes/main/database/databases/class_LocalFileDatabase.php index 9c9c00bd..38e67f10 100644 --- a/inc/classes/main/database/databases/class_LocalFileDatabase.php +++ b/inc/classes/main/database/databases/class_LocalFileDatabase.php @@ -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