Made all dashes to underscores for criteria keys
authorRoland Häder <roland@mxchange.org>
Thu, 17 May 2012 18:55:06 +0000 (18:55 +0000)
committerRoland Häder <roland@mxchange.org>
Thu, 17 May 2012 18:55:06 +0000 (18:55 +0000)
inc/classes/main/criteria/class_BaseCriteria.php

index 55636c6166ebecf0295e308145c87b6180020600..4b77b8f1e7ba8fbb6c8bd455287d549a5fa66dd3 100644 (file)
@@ -71,14 +71,15 @@ 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;
+               $this->criteria[str_replace('-', '_', $criteriaKey)] = (string)$criteriaValue;
        }
 
        /**
@@ -97,17 +98,20 @@ 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 = str_replace('-', '_', $criteriaKey);
+
                // 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];
                }
 
                // Return the value
@@ -127,8 +131,14 @@ class BaseCriteria extends BaseFrameworkSystem {
 
                // Walk through all entries
                foreach ($entryArray as $key => $entry) {
+                       // Convert dashes to underscore
+                       $key = str_replace('-', '_', $key);
+
                        // Then walk through all search criteria
                        foreach ($this->criteria as $criteriaKey => $criteriaValue) {
+                               // Convert dashes to underscore
+                               $criteriaKey = str_replace('-', '_', $criteriaKey);
+
                                // Is the element found and does it match?
                                if (($key == $criteriaKey) && ($criteriaValue == $entry)) {
                                        // Then count this one up
@@ -156,6 +166,9 @@ class BaseCriteria extends BaseFrameworkSystem {
 
                // Now walk through all criterias
                foreach ($this->criteria as $criteriaKey => $criteriaValue) {
+                       // Convert dashes to underscore
+                       $criteriaKey = str_replace('-', '_', $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