Localisation updates from http://translatewiki.net.
[mediawiki.git] / includes / db / ORMResult.php
blob3f2d8036326fb8168bed046d0468db146f251373
1 <?php
2 /**
3 * ORMIterator that takes a ResultWrapper object returned from
4 * a select operation returning IORMRow objects (ie IORMTable::select).
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
21 * @since 1.20
23 * @file ORMResult.php
24 * @ingroup ORM
26 * @licence GNU GPL v2 or later
27 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
30 class ORMResult implements ORMIterator {
32 /**
33 * @var ResultWrapper
35 protected $res;
37 /**
38 * @var integer
40 protected $key;
42 /**
43 * @var IORMRow
45 protected $current;
47 /**
48 * @var IORMTable
50 protected $table;
52 /**
53 * @param IORMTable $table
54 * @param ResultWrapper $res
56 public function __construct( IORMTable $table, ResultWrapper $res ) {
57 $this->table = $table;
58 $this->res = $res;
59 $this->key = 0;
60 $this->setCurrent( $this->res->current() );
63 /**
64 * @param $row
66 protected function setCurrent( $row ) {
67 if ( $row === false ) {
68 $this->current = false;
69 } else {
70 $this->current = $this->table->newRowFromDBResult( $row );
74 /**
75 * @return integer
77 public function count() {
78 return $this->res->numRows();
81 /**
82 * @return boolean
84 public function isEmpty() {
85 return $this->res->numRows() === 0;
88 /**
89 * @return IORMRow
91 public function current() {
92 return $this->current;
95 /**
96 * @return integer
98 public function key() {
99 return $this->key;
102 public function next() {
103 $row = $this->res->next();
104 $this->setCurrent( $row );
105 $this->key++;
108 public function rewind() {
109 $this->res->rewind();
110 $this->key = 0;
111 $this->setCurrent( $this->res->current() );
115 * @return boolean
117 public function valid() {
118 return $this->current !== false;