-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUser.php
57 lines (43 loc) · 1.18 KB
/
User.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
namespace Models;
class User extends \DB\SQL\Mapper
{
public $userHref;
private static $_prefix;
function __construct(\DB\SQL $db)
{
self::$_prefix = \Base::instance()->get('_db.prefix');
parent::__construct($db, self::$_prefix . 'user');
$this->isOnline = "last_active >= UNIX_TIMESTAMP() - 300";
$this->onload(function($self){
$f3 = \Base::instance();
$self->userHref = 'user/'. $f3->get('Tools')->slug($self->userName) .'-'. $self->userID;
$self->isBot = \Audit::instance()->isbot();
});
}
public function getOnline($params = [], $ttl = 300)
{
return $this->find(['userID >= UNIX_TIMESTAMP() - ?', $params['time']], ['limit' => $params['limit']]);
}
function loadUsers($users = [])
{
$loaded = $data = [];
$data = $this->find(['userID IN(?)', implode(',', $users)]);
if (!empty($data))
foreach ($data as $d)
$loaded[$d->userID] = $d;
return $loaded;
}
function createUser($data = [])
{
$f3 = \Base::instance();
$this->reset();
if (empty($data))
return false;
// Get what we need
$data = array_intersect_key($data, array_flip($this->fields()));
$this->copyfrom($data);
// Thats pretty much it.
$this->save();
}
}