63 lines
1.5 KiB
PHP
63 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Model;
|
|
|
|
use Core\Db;
|
|
use User\UserIp;
|
|
|
|
class ActionModel
|
|
{
|
|
private int $uid;
|
|
|
|
public function __construct(int $uid)
|
|
{
|
|
$this->uid = $uid;
|
|
}
|
|
|
|
public function getByVals(string $vals)
|
|
{
|
|
return Db::getRow('select * from actions where uid = ? and vals = ?', [$this->uid, $vals]);
|
|
}
|
|
|
|
public function getLastByVals(string $vals)
|
|
{
|
|
return Db::getRow(
|
|
'select * from actions where uid = ? and vals = ? order by time desc limit 1',
|
|
[$this->uid, $vals]
|
|
);
|
|
}
|
|
|
|
public function getLastByValsAndTime(string $vals, int $time)
|
|
{
|
|
return Db::getRow(
|
|
'select * from actions where uid = ? and vals = ? and time > unix_timestamp() - ? order by time desc limit 1',
|
|
[$this->uid, $vals, $time]
|
|
);
|
|
}
|
|
|
|
public function deleteByVals(string $vals)
|
|
{
|
|
Db::sql('delete from actions where uid = ? and vals = ?', [$this->uid, $vals]);
|
|
}
|
|
|
|
public static function new(array $user, string $vals, string $vars)
|
|
{
|
|
Db::sql(
|
|
'insert into actions (uid, time, city, room, vars, ip, vals, val) values (?,unix_timestamp(),?,?,?,?,?,?)',
|
|
[
|
|
$user['id'],
|
|
$user['city'],
|
|
$user['room'],
|
|
$vars,
|
|
UserIp::get(),
|
|
$vals,
|
|
'',
|
|
]
|
|
);
|
|
}
|
|
|
|
public static function getAll(): array
|
|
{
|
|
return Db::getRows('select * from actions');
|
|
}
|
|
} |