createUniqueID -> generateUniqueId renamed, dataset criteria added, registration...
[shipsimu.git] / inc / classes / main / result / class_DatabaseResult.php
1 <?php
2 /**
3  * A database result class
4  *
5  * @author              Roland Haeder <webmaster@ship-simu.org>
6  * @version             0.3.0
7  * @copyright   Copyright(c) 2007, 2008 Roland Haeder, this is free software
8  * @license             GNU GPL 3.0 or any newer version
9  * @link                http://www.mxchange.org
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23  */
24 class DatabaseResult extends BaseFrameworkSystem {
25         /**
26          * Current position in array
27          */
28         private $currentPos = -1;
29
30         /**
31          * Current row
32          */
33         private $currentRow = null;
34
35         /**
36          * Result array
37          */
38         private $resultArray = array();
39
40         /**
41          * Protected constructor
42          *
43          * @return      void
44          */
45         protected function __construct () {
46                 // Call parent constructor
47                 parent::__construct(__CLASS__);
48
49                 // Set part description
50                 $this->setObjectDescription("Database result");
51
52                 // Create unique ID number
53                 $this->generateUniqueId();
54
55                 // Clean up a little
56                 $this->removeNumberFormaters();
57                 $this->removeSystemArray();
58         }
59
60         /**
61          * Creates an instance of this result by a provided result array
62          *
63          * @param       $resultArray            The array holding the result from query
64          * @return      $resultInstance         An instance of this class
65          */
66         public final static function createDatabaseResult (array $resultArray) {
67                 // Get a new instance
68                 $resultInstance = new DatabaseResult();
69
70                 // Set the result array
71                 $resultInstance->setResultArray($resultArray);
72
73                 // Return the instance
74                 return $resultInstance;
75         }
76
77         /**
78          * Setter for result array
79          *
80          * @param       $resultArray    The array holding the result from query
81          * @return      void
82          */
83         protected final function setResultArray (array $resultArray) {
84                 $this->resultArray = $resultArray;
85         }
86
87         /**
88          * "Iterator" method next() to advance to the next valid entry. This method
89          * does also check if the result is invalid
90          *
91          * @return      $nextValid      Wether the next entry is valid
92          */
93         public function next () {
94                 // Default is not valid
95                 $nextValid = false;
96
97                 // Is the result valid?
98                 if ($this->resultArray['status'] === "ok") {
99                         // The status is fine so let's have a look for the next entry
100                         if (isset($this->resultArray['rows'][($this->currentPos + 1)])) {
101                                 // Next entry found, so count one up and cache it
102                                 $this->currentPos++;
103                                 $this->currentRow = $this->resultArray['rows'][$this->currentPos];
104                                 $nextValid = true;
105                         } // END - if
106                 } // END - if
107
108                 // Return the result
109                 return $nextValid;
110         }
111 }
112
113 // [EOF]
114 ?>