From 1c379903c466fba5770c5f38b348915cee0f5854 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 22 Feb 2013 08:08:13 +0000 Subject: [PATCH] Introduced unsetCriteria() --- .../interfaces/criteria/class_Criteria.php | 8 ++++++++ .../main/criteria/class_BaseCriteria.php | 20 +++++++++++++++++++ .../databases/class_LocalFileDatabase.php | 6 +++--- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/inc/classes/interfaces/criteria/class_Criteria.php b/inc/classes/interfaces/criteria/class_Criteria.php index d2cb532f..6f515ec9 100644 --- a/inc/classes/interfaces/criteria/class_Criteria.php +++ b/inc/classes/interfaces/criteria/class_Criteria.php @@ -84,6 +84,14 @@ interface Criteria extends FrameworkInterface { */ function getCriteriaExcludeArray (); + /** + * Unsets a criteria key from all criteria types + * + * @param $criteriaKey Criteria key to unset + * @return void + */ + function unsetCriteria ($criteriaKey); + /** * Add criteria, this method converts dashes to underscores because dashes * are not valid for criteria keys. diff --git a/inc/classes/main/criteria/class_BaseCriteria.php b/inc/classes/main/criteria/class_BaseCriteria.php index d02c32fc..f42dc828 100644 --- a/inc/classes/main/criteria/class_BaseCriteria.php +++ b/inc/classes/main/criteria/class_BaseCriteria.php @@ -137,6 +137,26 @@ class BaseCriteria extends BaseFrameworkSystem implements Criteria { return $this->getCriteriaArray('exclude'); } + /** + * Unsets a criteria key from all criteria types + * + * @param $criteriaKey Criteria key to unset + * @return void + */ + public final function unsetCriteria ($criteriaKey) { + // Make sure no 'my-' or 'my_' passes this point + assert((strpos($criteriaKey, 'my-') === FALSE) && (strpos($criteriaKey, 'my_') === FALSE) && (!is_bool($criteriaValue))); + + // Convert dashes to underscore + $criteriaKey = $this->convertDashesToUnderscores($criteriaKey); + + // "Walk" through all criterias + foreach ($this->criteria as $criteriaType => $dummy) { + // Remove it + unset($this->criteria[$criteriaType][$criteriaKey]); + } // END - foreach + } + /** * Add criteria, this method converts dashes to underscores because dashes * are not valid for criteria keys. diff --git a/inc/classes/main/database/databases/class_LocalFileDatabase.php b/inc/classes/main/database/databases/class_LocalFileDatabase.php index f49a9f16..b3f01831 100644 --- a/inc/classes/main/database/databases/class_LocalFileDatabase.php +++ b/inc/classes/main/database/databases/class_LocalFileDatabase.php @@ -164,7 +164,7 @@ class LocalFileDatabase extends BaseDatabaseBackend implements DatabaseBackendIn */ private function getDataArrayFromFile ($fqfn) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: Reading elements from database file ' . $fqfn . ' ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: Reading elements from database file ' . $fqfn . ' ...'); // Init compressed data $compressedData = $this->getFileIoInstance()->loadFileContents($fqfn); @@ -180,8 +180,8 @@ class LocalFileDatabase extends BaseDatabaseBackend implements DatabaseBackendIn $dataArray = unserialize($serializedData); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: Read ' . count($dataArray) . ' elements from database file ' . $fqfn . '.'); - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: dataArray=' . print_r($dataArray, TRUE)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: Read ' . count($dataArray) . ' elements from database file ' . $fqfn . '.'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: dataArray=' . print_r($dataArray, TRUE)); // Finally return it return $dataArray; -- 2.39.5