3 * ORMIterator that takes a ResultWrapper object returned from
4 * a select operation returning IORMRow objects (ie IORMTable::select).
6 * Documentation inline and at https://www.mediawiki.org/wiki/Manual:ORMTable
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * http://www.gnu.org/copyleft/gpl.html
28 * @license GNU GPL v2 or later
29 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
32 class ORMResult
implements ORMIterator
{
54 * @param IORMTable $table
55 * @param ResultWrapper $res
57 public function __construct( IORMTable
$table, ResultWrapper
$res ) {
58 $this->table
= $table;
61 $this->setCurrent( $this->res
->current() );
65 * @param bool|object $row
67 protected function setCurrent( $row ) {
68 if ( $row === false ) {
69 $this->current
= false;
71 $this->current
= $this->table
->newRowFromDBResult( $row );
78 public function count() {
79 return $this->res
->numRows();
85 public function isEmpty() {
86 return $this->res
->numRows() === 0;
92 public function current() {
93 return $this->current
;
99 public function key() {
103 public function next() {
104 $row = $this->res
->next();
105 $this->setCurrent( $row );
109 public function rewind() {
110 $this->res
->rewind();
112 $this->setCurrent( $this->res
->current() );
118 public function valid() {
119 return $this->current
!== false;