]> git.mxchange.org Git - core.git/blobdiff - inc/classes/main/criteria/class_BaseCriteria.php
MINOR: Missing empty line
[core.git] / inc / classes / main / criteria / class_BaseCriteria.php
index 55636c6166ebecf0295e308145c87b6180020600..21b53aa13e078b6ff69c50ae1e0f2730cb439c94 100644 (file)
@@ -31,6 +31,7 @@ class BaseCriteria extends BaseFrameworkSystem {
         * Criteria to handle
         */
        private $criteria = array();
+
        /**
         * Protected constructor
         *
@@ -71,14 +72,20 @@ class BaseCriteria extends BaseFrameworkSystem {
        }
 
        /**
-        * Add criteria
+        * Add criteria, this method converts dashes to underscores because dashes
+        * are not valid for criteria keys.
         *
         * @param       $criteriaKey    Criteria key
         * @param       $criteriaValue  Criteria value
         * @return      void
         */
        public final function addCriteria ($criteriaKey, $criteriaValue) {
-               $this->criteria[(string)$criteriaKey] = (string)$criteriaValue;
+               // Debug message
+               if (strpos($criteriaKey, 'my-') !== false) $this->debugBackTrace('criteriaKey=' . $criteriaKey);
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRITERIA: criteriaKey=' . $criteriaKey . ',criteriaValue=' . $criteriaValue);
+
+               // Add it
+               $this->criteria[$this->convertDashesToUnderscores($criteriaKey)] = (string)$criteriaValue;
        }
 
        /**
@@ -97,18 +104,24 @@ class BaseCriteria extends BaseFrameworkSystem {
        /**
         * Get criteria element or null if not found
         *
-        * @param       $criteria       The criteria we want to have
-        * @return      $value          Whether the value of the critera or null
+        * @param       $criteriaKey    The requested criteria key
+        * @return      $value                  Whether the value of the critera or null
         */
-       public function getCriteriaElemnent ($criteria) {
+       public function getCriteriaElemnent ($criteriaKey) {
+               // Convert dashes to underscore
+               $criteriaKey = $this->convertDashesToUnderscores($criteriaKey);
+
+               // Debug message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRITERIA: criteriaKey=' . $criteriaKey . ',criteria()=' . count($this->criteria));
+
                // Default is not found
                $value = NULL;
 
                // Is the criteria there?
-               if (isset($this->criteria[$criteria])) {
+               if (isset($this->criteria[$criteriaKey])) {
                        // Then use it
-                       $value = $this->criteria[$criteria];
-               }
+                       $value = $this->criteria[$criteriaKey];
+               } // END - if
 
                // Return the value
                return $value;
@@ -127,8 +140,14 @@ class BaseCriteria extends BaseFrameworkSystem {
 
                // Walk through all entries
                foreach ($entryArray as $key => $entry) {
+                       // Convert dashes to underscore
+                       $key = $this->convertDashesToUnderscores($key);
+
                        // Then walk through all search criteria
                        foreach ($this->criteria as $criteriaKey => $criteriaValue) {
+                               // Convert dashes to underscore
+                               $criteriaKey = $this->convertDashesToUnderscores($criteriaKey);
+
                                // Is the element found and does it match?
                                if (($key == $criteriaKey) && ($criteriaValue == $entry)) {
                                        // Then count this one up
@@ -156,6 +175,9 @@ class BaseCriteria extends BaseFrameworkSystem {
 
                // Now walk through all criterias
                foreach ($this->criteria as $criteriaKey => $criteriaValue) {
+                       // Convert dashes to underscore
+                       $criteriaKey = $this->convertDashesToUnderscores($criteriaKey);
+
                        // Is the value in array or is $onlyKeys empty?
                        if ((isset($onlyKeys[$criteriaKey])) || (count($onlyKeys) == 0)) {
                                // Add the value URL encoded to avoid any trouble with special characters
@@ -184,6 +206,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]