00001 <?php 00002 00003 abstract class UserArray implements Iterator { 00004 static function newFromResult( $res ) { 00005 $userArray = null; 00006 if ( !wfRunHooks( 'UserArrayFromResult', array( &$userArray, $res ) ) ) { 00007 return null; 00008 } 00009 if ( $userArray === null ) { 00010 $userArray = self::newFromResult_internal( $res ); 00011 } 00012 return $userArray; 00013 } 00014 00015 static function newFromIDs( $ids ) { 00016 $ids = array_map( 'intval', (array)$ids ); // paranoia 00017 if ( !$ids ) 00018 // Database::select() doesn't like empty arrays 00019 return new ArrayIterator(array()); 00020 $dbr = wfGetDB( DB_SLAVE ); 00021 $res = $dbr->select( 'user', '*', array( 'user_id' => $ids ), 00022 __METHOD__ ); 00023 return self::newFromResult( $res ); 00024 } 00025 00026 protected static function newFromResult_internal( $res ) { 00027 $userArray = new UserArrayFromResult( $res ); 00028 return $userArray; 00029 } 00030 } 00031 00032 class UserArrayFromResult extends UserArray { 00033 var $res; 00034 var $key, $current; 00035 00036 function __construct( $res ) { 00037 $this->res = $res; 00038 $this->key = 0; 00039 $this->setCurrent( $this->res->current() ); 00040 } 00041 00042 protected function setCurrent( $row ) { 00043 if ( $row === false ) { 00044 $this->current = false; 00045 } else { 00046 $this->current = User::newFromRow( $row ); 00047 } 00048 } 00049 00050 public function count() { 00051 return $this->res->numRows(); 00052 } 00053 00054 function current() { 00055 return $this->current; 00056 } 00057 00058 function key() { 00059 return $this->key; 00060 } 00061 00062 function next() { 00063 $row = $this->res->next(); 00064 $this->setCurrent( $row ); 00065 $this->key++; 00066 } 00067 00068 function rewind() { 00069 $this->res->rewind(); 00070 $this->key = 0; 00071 $this->setCurrent( $this->res->current() ); 00072 } 00073 00074 function valid() { 00075 return $this->current !== false; 00076 } 00077 }