]> git.mxchange.org Git - core.git/blobdiff - inc/classes/main/result/class_DatabaseResult.php
Some fixes.
[core.git] / inc / classes / main / result / class_DatabaseResult.php
index 69c23ff6952173fa2a423ac902adc59c7e72a953..4b2c073b5a685398f731ede03de978cba0a50079 100644 (file)
@@ -2,11 +2,11 @@
 /**
  * A database result class
  *
- * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Core Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2013 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
- * @link               http://www.ship-simu.org
+ * @link               http://www.shipsimu.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
@@ -80,7 +80,7 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up
                $resultInstance->setResultArray($resultArray);
 
                // Set affected rows
-               $resultInstance->setAffectedRows(count($resultArray[BaseDatabaseFrontend::RESULT_INDEX_ROWS]));
+               $resultInstance->setAffectedRows(count($resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS]));
 
                // Return the instance
                return $resultInstance;
@@ -109,7 +109,7 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up
                // Now get the update criteria array and update all entries
                foreach ($updateInstance->getUpdateCriteria() as $criteriaKey => $criteriaValue) {
                        // Update data
-                       $this->resultArray[BaseDatabaseFrontend::RESULT_INDEX_ROWS][$entryKey][$criteriaKey] = $criteriaValue;
+                       $this->resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS][$entryKey][$criteriaKey] = $criteriaValue;
 
                        // Mark it as out-dated
                        $this->outDated[$criteriaKey] = 1;
@@ -120,18 +120,18 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up
         * "Iterator" method next() to advance to the next valid entry. This method
         * does also check if result is invalid
         *
-        * @return      $nextValid      Wether the next entry is valid
+        * @return      $nextValid      Whether the next entry is valid
         */
        public function next () {
                // Default is not valid
-               $nextValid = false;
+               $nextValid = FALSE;
 
                // Is the result valid?
                if ($this->valid()) {
                        // Next entry found, so count one up and cache it
                        $this->currentPos++;
-                       $this->currentRow = $this->resultArray[BaseDatabaseFrontend::RESULT_INDEX_ROWS][$this->currentPos];
-                       $nextValid = true;
+                       $this->currentRow = $this->resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS][$this->currentPos];
+                       $nextValid = TRUE;
                } // END - if
 
                // Return the result
@@ -149,7 +149,7 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up
                $this->rewind();
 
                // Search for the entry
-               while ($this->currentPos < $index && ($this->valid())) {
+               while (($this->currentPos < $index) && ($this->valid())) {
                        // Continue on
                        $this->next();
                } // END - while
@@ -165,9 +165,9 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up
                $current = NULL;
 
                // Does the current enty exist?
-               if (isset($this->resultArray[BaseDatabaseFrontend::RESULT_INDEX_ROWS][$this->currentPos])) {
+               if (isset($this->resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS][$this->currentPos])) {
                        // Then get it
-                       $current = $this->resultArray[BaseDatabaseFrontend::RESULT_INDEX_ROWS][$this->currentPos];
+                       $current = $this->resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS][$this->currentPos];
                } // END - if
 
                // Return the result
@@ -177,16 +177,19 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up
        /**
         * Checks if next() and rewind will give a valid result
         *
-        * @return      $isValid Wether the next/rewind entry is valid
+        * @return      $isValid Whether the next/rewind entry is valid
         */
        public function valid () {
                // By default nothing is valid
-               $isValid = false;
+               $isValid = FALSE;
 
-               // Check if 
-               if (($this->ifStatusIsOkay()) && (isset($this->resultArray[BaseDatabaseFrontend::RESULT_INDEX_ROWS][($this->currentPos + 1)])) && (isset($this->resultArray[BaseDatabaseFrontend::RESULT_INDEX_ROWS][0]))) {
+               // Debug message
+               //*NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] this->currentPos=' . $this->currentPos);
+
+               // Check if all is fine ...
+               if (($this->ifStatusIsOkay()) && (isset($this->resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS][($this->currentPos + 1)])) && (isset($this->resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS][0]))) {
                        // All fine!
-                       $isValid = true;
+                       $isValid = TRUE;
                } // END - if
 
                // Return the result
@@ -194,12 +197,24 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up
        }
 
        /**
-        * Determines wether the status of the query was fine (LocalfileDatabase::RESULT_OKAY)
+        * Returns count of entries
+        *
+        * @return      $isValid Whether the next/rewind entry is valid
+        */
+       public function count () {
+               // Return it
+               return count($this->resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS]);
+       }
+
+       /**
+        * Determines whether the status of the query was fine (BaseDatabaseBackend::RESULT_OKAY)
         *
-        * @return      $ifStatusOkay   Wether the status of the query was okay
+        * @return      $ifStatusOkay   Whether the status of the query was okay
         */
        public function ifStatusIsOkay () {
-               return ((isset($this->resultArray[BaseDatabaseFrontend::RESULT_INDEX_STATUS])) && ($this->resultArray[BaseDatabaseFrontend::RESULT_INDEX_STATUS] === LocalfileDatabase::RESULT_OKAY));
+               $ifStatusOkay = ((isset($this->resultArray[BaseDatabaseBackend::RESULT_INDEX_STATUS])) && ($this->resultArray[BaseDatabaseBackend::RESULT_INDEX_STATUS] === BaseDatabaseBackend::RESULT_OKAY));
+               //*NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] ifStatusOkay=' . intval($ifStatusOkay));
+               return $ifStatusOkay;
        }
 
        /**
@@ -229,7 +244,7 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up
         * @todo        0% done
         */
        public function searchEntry (LocalSearchCriteria $criteriaInstance) {
-               $this->debugBackTrace(__METHOD__ . ': Unfinished!');
+               $this->debugBackTrace('[' . '[' . __METHOD__ . ':' . __LINE__ . ']:  Unfinished!');
        }
 
        /**
@@ -306,9 +321,9 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up
        }
 
        /**
-        * Checks wether we have out-dated entries or not
+        * Checks whether we have out-dated entries or not
         *
-        * @return      $needsUpdate    Wether we have out-dated entries
+        * @return      $needsUpdate    Whether we have out-dated entries
         */
        public function ifDataNeedsFlush () {
                $needsUpdate = (count($this->outDated) > 0);
@@ -318,10 +333,11 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up
        /**
         * Adds registration elements to a given dataset instance
         *
-        * @param       $criteriaInstance       An instance of a storeable criteria
+        * @param       $criteriaInstance       An instance of a StoreableCriteria class
+        * @param       $requestInstance        An instance of a Requestable class
         * @return      void
         */
-       public function addElementsToDataSet (StoreableCriteria $criteriaInstance) {
+       public function addElementsToDataSet (StoreableCriteria $criteriaInstance, Requestable $requestInstance = NULL) {
                // Walk only through out-dated columns
                foreach ($this->outDated as $key => $dummy) {
                        // Does this key exist?
@@ -337,11 +353,11 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up
         * Find a key inside the result array
         *
         * @param       $key    The key we shall find
-        * @return      $found  Wether the key was found or not
+        * @return      $found  Whether the key was found or not
         */
        public function find ($key) {
                // By default nothing is found
-               $found = false;
+               $found = FALSE;
 
                // Rewind the pointer
                $this->rewind();
@@ -357,7 +373,7 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up
                        // Is the element there?
                        if (isset($currentEntry[$key])) {
                                // Okay, found!
-                               $found = true;
+                               $found = TRUE;
 
                                // So "cache" it
                                $this->foundValue = $currentEntry[$key];
@@ -379,9 +395,9 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up
         * @para        $callBack                       Call-back object for setting the index;
         *                                                              0=object instance,1=method name
         * @return      void
-4       * @todo        Find a caching way without modifying the result array
+        * @todo        Find a caching way without modifying the result array
         */
-       public function solveResultIndex ($databaseColumn, BaseDatabaseWrapper $wrapperInstance, array $callBack) {
+       public function solveResultIndex ($databaseColumn, DatabaseWrapper $wrapperInstance, array $callBack) {
                // By default nothing is found
                $indexValue = 0;