Results are now searchable and iterateable, insertDataSet renamed to queryInsertDataS...
[shipsimu.git] / inc / classes / main / result / class_DatabaseResult.php
index 3d48861ba6fd259debbccf177bef32f3a4441e03..c6a0b1149a9d3e1907e019f51711ab0c68e5c74e 100644 (file)
@@ -3,10 +3,10 @@
  * A database result class
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
- * @version            0.3.0
+ * @version            0.0.0
  * @copyright  Copyright(c) 2007, 2008 Roland Haeder, this is free software
  * @license            GNU GPL 3.0 or any newer version
- * @link               http://www.mxchange.org
+ * @link               http://www.ship-simu.org
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -21,7 +21,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-class DatabaseResult extends BaseFrameworkSystem {
+class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, SeekableIterator {
        /**
         * Current position in array
         */
@@ -97,7 +97,7 @@ class DatabaseResult extends BaseFrameworkSystem {
                // Is the result valid?
                if ($this->resultArray['status'] === "ok") {
                        // The status is fine so let's have a look for the next entry
-                       if (isset($this->resultArray['rows'][($this->currentPos + 1)])) {
+                       if ($this->valid()) {
                                // Next entry found, so count one up and cache it
                                $this->currentPos++;
                                $this->currentRow = $this->resultArray['rows'][$this->currentPos];
@@ -108,6 +108,89 @@ class DatabaseResult extends BaseFrameworkSystem {
                // Return the result
                return $nextValid;
        }
+
+       /**
+        * Seeks for to a specified position
+        *
+        * @param       $index  Index to seek for
+        * @return      void
+        */
+       public function seek ($index) {
+               // Rewind to beginning
+               $this->rewind();
+
+               // Search for the entry
+               while ($this->currentPos < $index && ($this->valid())) {
+                       // Continue on
+                       $this->next();
+               } // END - while
+       }
+
+       /**
+        * Gives back the current position or null if not found
+        *
+        * @return      $current        Current element to give back
+        */
+       public function current () {
+               // Default is not found
+               $current = null;
+
+               // Does the current enty exist?
+               if (isset($this->resultArray['rows'][$this->currentPos])) {
+                       // Then get it
+                       $current = $this->resultArray['rows'][$this->currentPos];
+               } // END - if
+
+               // Return the result
+               return $current;
+       }
+
+       /**
+        * Checks if next() and rewind will give a valid result
+        *
+        * @return      $isValid Wether the next/rewind entry is valid
+        */
+       public function valid () {
+               // By default nothing is valid
+               $isValid = false;
+
+               // Check if 
+               if ((isset($this->resultArray['rows'][($this->currentPos + 1)])) && (isset($this->resultArray['rows'][0]))) {
+                       // All fine!
+                       $isValid = true;
+               } // END - if
+
+               // Return the result
+               return $isValid;
+       }
+
+       /**
+        * Gets the current key of iteration
+        *
+        * @return      $currentPos     Key from iterator
+        */
+       public function key () {
+               return $this->currentPos;
+       }
+
+       /**
+        * Rewind to the beginning
+        *
+        * @return      void
+        */
+       public function rewind () {
+               $this->currentPos = 0;
+       }
+
+       /**
+        * Searches for an entry in the data result and returns it
+        *
+        * @param       $criteriaInstance       The criteria to look inside the data set
+        * @return      $result                         Found result entry
+        */
+       public function searchEntry (LocalSearchCriteria $criteriaInstance) {
+               die("OK");
+       }
 }
 
 // [EOF]