MediaWiki  REL1_21
UserArray.php
Go to the documentation of this file.
00001 <?php
00023 abstract class UserArray implements Iterator {
00028         static function newFromResult( $res ) {
00029                 $userArray = null;
00030                 if ( !wfRunHooks( 'UserArrayFromResult', array( &$userArray, $res ) ) ) {
00031                         return null;
00032                 }
00033                 if ( $userArray === null ) {
00034                         $userArray = self::newFromResult_internal( $res );
00035                 }
00036                 return $userArray;
00037         }
00038 
00043         static function newFromIDs( $ids ) {
00044                 $ids = array_map( 'intval', (array)$ids ); // paranoia
00045                 if ( !$ids ) {
00046                         // Database::select() doesn't like empty arrays
00047                         return new ArrayIterator(array());
00048                 }
00049                 $dbr = wfGetDB( DB_SLAVE );
00050                 $res = $dbr->select( 'user', '*', array( 'user_id' => $ids ),
00051                         __METHOD__ );
00052                 return self::newFromResult( $res );
00053         }
00054 
00059         protected static function newFromResult_internal( $res ) {
00060                 return new UserArrayFromResult( $res );
00061         }
00062 }
00063 
00064 class UserArrayFromResult extends UserArray {
00065 
00069         var $res;
00070         var $key, $current;
00071 
00075         function __construct( $res ) {
00076                 $this->res = $res;
00077                 $this->key = 0;
00078                 $this->setCurrent( $this->res->current() );
00079         }
00080 
00085         protected function setCurrent( $row ) {
00086                 if ( $row === false ) {
00087                         $this->current = false;
00088                 } else {
00089                         $this->current = User::newFromRow( $row );
00090                 }
00091         }
00092 
00096         public function count() {
00097                 return $this->res->numRows();
00098         }
00099 
00103         function current() {
00104                 return $this->current;
00105         }
00106 
00107         function key() {
00108                 return $this->key;
00109         }
00110 
00111         function next() {
00112                 $row = $this->res->next();
00113                 $this->setCurrent( $row );
00114                 $this->key++;
00115         }
00116 
00117         function rewind() {
00118                 $this->res->rewind();
00119                 $this->key = 0;
00120                 $this->setCurrent( $this->res->current() );
00121         }
00122 
00126         function valid() {
00127                 return $this->current !== false;
00128         }
00129 }