2014-01-26 17:49:18 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Class to walk into a list of User objects.
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
*/
|
|
|
|
|
|
2018-04-05 22:06:35 +00:00
|
|
|
use Wikimedia\Rdbms\IResultWrapper;
|
2017-02-19 05:03:13 +00:00
|
|
|
|
2014-01-26 17:49:18 +00:00
|
|
|
class UserArrayFromResult extends UserArray implements Countable {
|
2018-04-05 22:06:35 +00:00
|
|
|
/** @var IResultWrapper */
|
2014-05-11 15:34:14 +00:00
|
|
|
public $res;
|
2014-01-26 17:49:18 +00:00
|
|
|
|
2014-05-11 15:34:14 +00:00
|
|
|
/** @var int */
|
|
|
|
|
public $key;
|
|
|
|
|
|
2021-08-30 20:08:17 +00:00
|
|
|
/** @var User|false */
|
2014-05-11 15:34:14 +00:00
|
|
|
public $current;
|
2014-01-26 17:49:18 +00:00
|
|
|
|
|
|
|
|
/**
|
2018-04-05 22:06:35 +00:00
|
|
|
* @param IResultWrapper $res
|
2014-01-26 17:49:18 +00:00
|
|
|
*/
|
2019-11-30 23:03:59 +00:00
|
|
|
public function __construct( $res ) {
|
2014-01-26 17:49:18 +00:00
|
|
|
$this->res = $res;
|
|
|
|
|
$this->key = 0;
|
|
|
|
|
$this->setCurrent( $this->res->current() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-04-10 18:50:10 +00:00
|
|
|
* @param bool|stdClass $row
|
2014-01-26 17:49:18 +00:00
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
protected function setCurrent( $row ) {
|
|
|
|
|
if ( $row === false ) {
|
|
|
|
|
$this->current = false;
|
|
|
|
|
} else {
|
|
|
|
|
$this->current = User::newFromRow( $row );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function count() {
|
|
|
|
|
return $this->res->numRows();
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-30 20:08:17 +00:00
|
|
|
public function current(): User {
|
2014-01-26 17:49:18 +00:00
|
|
|
return $this->current;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-30 20:08:17 +00:00
|
|
|
public function key(): int {
|
2014-01-26 17:49:18 +00:00
|
|
|
return $this->key;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-17 22:39:57 +00:00
|
|
|
public function next() {
|
2014-01-26 17:49:18 +00:00
|
|
|
$row = $this->res->next();
|
|
|
|
|
$this->setCurrent( $row );
|
|
|
|
|
$this->key++;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-17 22:39:57 +00:00
|
|
|
public function rewind() {
|
2014-01-26 17:49:18 +00:00
|
|
|
$this->res->rewind();
|
|
|
|
|
$this->key = 0;
|
|
|
|
|
$this->setCurrent( $this->res->current() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2020-05-17 22:39:57 +00:00
|
|
|
public function valid() {
|
2014-01-26 17:49:18 +00:00
|
|
|
return $this->current !== false;
|
|
|
|
|
}
|
|
|
|
|
}
|