2012-03-22 01:56:32 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2012-06-12 11:11:56 +00:00
|
|
|
* ORMIterator that takes a ResultWrapper object returned from
|
|
|
|
|
* a select operation returning IORMRow objects (ie IORMTable::select).
|
2012-03-22 01:56:32 +00:00
|
|
|
*
|
2012-07-21 19:20:30 +00:00
|
|
|
* Documentation inline and at https://www.mediawiki.org/wiki/Manual:ORMTable
|
|
|
|
|
*
|
2012-04-26 08:47:10 +00:00
|
|
|
* 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
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
2012-03-22 01:56:32 +00:00
|
|
|
* @since 1.20
|
|
|
|
|
*
|
|
|
|
|
* @file ORMResult.php
|
2012-06-05 22:58:54 +00:00
|
|
|
* @ingroup ORM
|
2012-03-22 01:56:32 +00:00
|
|
|
*
|
2012-10-22 10:29:52 +00:00
|
|
|
* @license GNU GPL v2 or later
|
2012-03-22 01:56:32 +00:00
|
|
|
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
|
|
|
|
|
*/
|
2012-04-26 08:47:10 +00:00
|
|
|
|
2012-06-12 11:11:56 +00:00
|
|
|
class ORMResult implements ORMIterator {
|
2012-03-22 01:56:32 +00:00
|
|
|
/**
|
|
|
|
|
* @var ResultWrapper
|
|
|
|
|
*/
|
|
|
|
|
protected $res;
|
|
|
|
|
|
|
|
|
|
/**
|
2014-04-19 11:55:27 +00:00
|
|
|
* @var int
|
2012-03-22 01:56:32 +00:00
|
|
|
*/
|
2012-06-12 11:11:56 +00:00
|
|
|
protected $key;
|
2012-03-22 01:56:32 +00:00
|
|
|
|
|
|
|
|
/**
|
2012-06-05 22:58:54 +00:00
|
|
|
* @var IORMRow
|
2012-03-22 01:56:32 +00:00
|
|
|
*/
|
|
|
|
|
protected $current;
|
|
|
|
|
|
|
|
|
|
/**
|
2012-06-05 22:58:54 +00:00
|
|
|
* @var IORMTable
|
2012-03-22 01:56:32 +00:00
|
|
|
*/
|
|
|
|
|
protected $table;
|
|
|
|
|
|
|
|
|
|
/**
|
2012-06-05 22:58:54 +00:00
|
|
|
* @param IORMTable $table
|
2012-03-22 01:56:32 +00:00
|
|
|
* @param ResultWrapper $res
|
|
|
|
|
*/
|
2012-06-05 22:58:54 +00:00
|
|
|
public function __construct( IORMTable $table, ResultWrapper $res ) {
|
2012-03-22 01:56:32 +00:00
|
|
|
$this->table = $table;
|
|
|
|
|
$this->res = $res;
|
|
|
|
|
$this->key = 0;
|
|
|
|
|
$this->setCurrent( $this->res->current() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-04-19 11:55:27 +00:00
|
|
|
* @param bool|object $row
|
2012-03-22 01:56:32 +00:00
|
|
|
*/
|
|
|
|
|
protected function setCurrent( $row ) {
|
|
|
|
|
if ( $row === false ) {
|
|
|
|
|
$this->current = false;
|
|
|
|
|
} else {
|
2012-06-29 18:56:44 +00:00
|
|
|
$this->current = $this->table->newRowFromDBResult( $row );
|
2012-03-22 01:56:32 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-04-19 11:55:27 +00:00
|
|
|
* @return int
|
2012-03-22 01:56:32 +00:00
|
|
|
*/
|
|
|
|
|
public function count() {
|
|
|
|
|
return $this->res->numRows();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-04-19 11:55:27 +00:00
|
|
|
* @return bool
|
2012-03-22 01:56:32 +00:00
|
|
|
*/
|
|
|
|
|
public function isEmpty() {
|
|
|
|
|
return $this->res->numRows() === 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2012-06-05 22:58:54 +00:00
|
|
|
* @return IORMRow
|
2012-03-22 01:56:32 +00:00
|
|
|
*/
|
|
|
|
|
public function current() {
|
|
|
|
|
return $this->current;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-04-19 11:55:27 +00:00
|
|
|
* @return int
|
2012-03-22 01:56:32 +00:00
|
|
|
*/
|
|
|
|
|
public function key() {
|
|
|
|
|
return $this->key;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function next() {
|
|
|
|
|
$row = $this->res->next();
|
|
|
|
|
$this->setCurrent( $row );
|
|
|
|
|
$this->key++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function rewind() {
|
|
|
|
|
$this->res->rewind();
|
|
|
|
|
$this->key = 0;
|
|
|
|
|
$this->setCurrent( $this->res->current() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-04-19 11:55:27 +00:00
|
|
|
* @return bool
|
2012-03-22 01:56:32 +00:00
|
|
|
*/
|
|
|
|
|
public function valid() {
|
|
|
|
|
return $this->current !== false;
|
|
|
|
|
}
|
|
|
|
|
}
|