fetch a block of users

This commit is contained in:
Shish Moom 2009-05-30 06:47:35 -07:00
parent 4765e51e7c
commit c5e9788358

View File

@ -1,4 +1,8 @@
<?php
function _new_user($row) {
return new User($row);
}
/*
* An object representing a row in the "users" table.
*/
@ -18,7 +22,7 @@ class User {
* User objects shouldn't be created directly, they should be *
* fetched from the database like so: *
* *
* $user = User::by_name($config, $database, "bob"); *
* $user = User::by_name("bob"); *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
public function User($row) {
@ -61,6 +65,14 @@ class User {
return is_null($row) ? null : new User($row);
}
public static function by_list($offset, $limit=50) {
assert(is_numeric($offset));
assert(is_numeric($limit));
global $database;
$rows = $database->get_all("SELECT * FROM users WHERE id >= ? AND id < ?", array($offset, $offset+$limit));
return array_map("_new_user", $rows);
}
/*
* useful user object functions start here