38 lines
699 B
PHP
38 lines
699 B
PHP
|
<?php /* Copyright (c) 2024 Freya Murphy */
|
||
|
class Cache_model extends Model {
|
||
|
|
||
|
// the user cache
|
||
|
private $users;
|
||
|
|
||
|
function __construct($load) {
|
||
|
parent::__construct($load);
|
||
|
$this->users = array();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Gets a array of users
|
||
|
*/
|
||
|
public function get_users($objs) {
|
||
|
$ids = array();
|
||
|
foreach ($objs as $obj) {
|
||
|
$id = $obj['user_id'];
|
||
|
if (!array_key_exists($id, $this->users)) {
|
||
|
array_push($ids, intval($id));
|
||
|
}
|
||
|
}
|
||
|
if (!empty($ids)) {
|
||
|
$result = $this->main->db
|
||
|
->select('*')
|
||
|
->from('api.user')
|
||
|
->where_in('id', $ids)
|
||
|
->rows();
|
||
|
foreach ($result as $user) {
|
||
|
$id = $user['id'];
|
||
|
$this->users[$id] = $user;
|
||
|
}
|
||
|
}
|
||
|
return $this->users;
|
||
|
}
|
||
|
|
||
|
}
|