Minor fixes
[core.git] / inc / classes / main / result / class_DatabaseResult.php
index 94fe3b5deff55a2f96fac4aaba5bde59197b32a0..aa09d11b3fc019555388e8f64679380357d448f4 100644 (file)
@@ -4,7 +4,7 @@
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, this is free software
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.ship-simu.org
  *
@@ -34,7 +34,7 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up
        /**
         * Current row
         */
-       private $currentRow = null;
+       private $currentRow = NULL;
 
        /**
         * Result array
@@ -54,7 +54,7 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up
        /**
         * Found value
         */
-       private $foundValue = "";
+       private $foundValue = '';
 
        /**
         * Protected constructor
@@ -64,10 +64,6 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up
        protected function __construct () {
                // Call parent constructor
                parent::__construct(__CLASS__);
-
-               // Clean up a little
-               $this->removeNumberFormaters();
-               $this->removeSystemArray();
        }
 
        /**
@@ -76,13 +72,16 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up
         * @param       $resultArray            The array holding the result from query
         * @return      $resultInstance         An instance of this class
         */
-       public final static function createDatabaseResult (array $resultArray) {
+       public static final function createDatabaseResult (array $resultArray) {
                // Get a new instance
                $resultInstance = new DatabaseResult();
 
                // Set the result array
                $resultInstance->setResultArray($resultArray);
 
+               // Set affected rows
+               $resultInstance->setAffectedRows(count($resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS]));
+
                // Return the instance
                return $resultInstance;
        }
@@ -110,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['rows'][$entryKey][$criteriaKey] = $criteriaValue;
+                       $this->resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS][$entryKey][$criteriaKey] = $criteriaValue;
 
                        // Mark it as out-dated
                        $this->outDated[$criteriaKey] = 1;
@@ -121,7 +120,7 @@ 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
@@ -131,7 +130,7 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up
                if ($this->valid()) {
                        // Next entry found, so count one up and cache it
                        $this->currentPos++;
-                       $this->currentRow = $this->resultArray['rows'][$this->currentPos];
+                       $this->currentRow = $this->resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS][$this->currentPos];
                        $nextValid = true;
                } // END - if
 
@@ -150,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
@@ -163,12 +162,12 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up
         */
        public function current () {
                // Default is not found
-               $current = null;
+               $current = NULL;
 
                // Does the current enty exist?
-               if (isset($this->resultArray['rows'][$this->currentPos])) {
+               if (isset($this->resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS][$this->currentPos])) {
                        // Then get it
-                       $current = $this->resultArray['rows'][$this->currentPos];
+                       $current = $this->resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS][$this->currentPos];
                } // END - if
 
                // Return the result
@@ -178,14 +177,14 @@ 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;
 
                // Check if 
-               if (($this->ifStatusIsOkay()) && (isset($this->resultArray['rows'][($this->currentPos + 1)])) && (isset($this->resultArray['rows'][0]))) {
+               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;
                } // END - if
@@ -195,12 +194,12 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up
        }
 
        /**
-        * Determines wether the status of the query was fine ("ok")
+        * Determines whether the status of the query was fine (LocalfileDatabase::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['status'])) && ($this->resultArray['status'] === "ok"));
+               return ((isset($this->resultArray[BaseDatabaseBackend::RESULT_INDEX_STATUS])) && ($this->resultArray[BaseDatabaseBackend::RESULT_INDEX_STATUS] === LocalfileDatabase::RESULT_OKAY));
        }
 
        /**
@@ -230,7 +229,7 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up
         * @todo        0% done
         */
        public function searchEntry (LocalSearchCriteria $criteriaInstance) {
-               die(__METHOD__.": Unfinished!");
+               $this->debugBackTrace('[' . '[' . __METHOD__ . ':' . __LINE__ . ']:  Unfinished!');
        }
 
        /**
@@ -265,17 +264,17 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up
                        } // END - if
                } // END - while
 
-               // Set affected rows
-               $this->setAffectedRows($foundEntries);
-
                // If no entry is found/updated throw an exception
                if ($foundEntries == 0) {
                        // Throw an exception here
                        throw new ResultUpdateException($this, self::EXCEPTION_RESULT_UPDATE_FAILED);
                } // END - if
 
-               // Set search instance
-               $this->setSearchInstance($searchInstance);
+               // Set affected rows
+               $this->setAffectedRows($foundEntries);
+
+               // Set update instance
+               $this->setUpdateInstance($criteriaInstance);
        }
 
        /**
@@ -307,9 +306,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);
@@ -338,7 +337,7 @@ 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
@@ -380,7 +379,7 @@ 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) {
                // By default nothing is found