MediaWiki
REL1_19
|
00001 <?php 00002 00003 abstract class UserArray implements Iterator { 00008 static function newFromResult( $res ) { 00009 $userArray = null; 00010 if ( !wfRunHooks( 'UserArrayFromResult', array( &$userArray, $res ) ) ) { 00011 return null; 00012 } 00013 if ( $userArray === null ) { 00014 $userArray = self::newFromResult_internal( $res ); 00015 } 00016 return $userArray; 00017 } 00018 00023 static function newFromIDs( $ids ) { 00024 $ids = array_map( 'intval', (array)$ids ); // paranoia 00025 if ( !$ids ) { 00026 // Database::select() doesn't like empty arrays 00027 return new ArrayIterator(array()); 00028 } 00029 $dbr = wfGetDB( DB_SLAVE ); 00030 $res = $dbr->select( 'user', '*', array( 'user_id' => $ids ), 00031 __METHOD__ ); 00032 return self::newFromResult( $res ); 00033 } 00034 00039 protected static function newFromResult_internal( $res ) { 00040 return new UserArrayFromResult( $res ); 00041 } 00042 } 00043 00044 class UserArrayFromResult extends UserArray { 00045 00049 var $res; 00050 var $key, $current; 00051 00055 function __construct( $res ) { 00056 $this->res = $res; 00057 $this->key = 0; 00058 $this->setCurrent( $this->res->current() ); 00059 } 00060 00065 protected function setCurrent( $row ) { 00066 if ( $row === false ) { 00067 $this->current = false; 00068 } else { 00069 $this->current = User::newFromRow( $row ); 00070 } 00071 } 00072 00076 public function count() { 00077 return $this->res->numRows(); 00078 } 00079 00083 function current() { 00084 return $this->current; 00085 } 00086 00087 function key() { 00088 return $this->key; 00089 } 00090 00091 function next() { 00092 $row = $this->res->next(); 00093 $this->setCurrent( $row ); 00094 $this->key++; 00095 } 00096 00097 function rewind() { 00098 $this->res->rewind(); 00099 $this->key = 0; 00100 $this->setCurrent( $this->res->current() ); 00101 } 00102 00106 function valid() { 00107 return $this->current !== false; 00108 } 00109 }