game/_incl_data/class/Model/ActionModel.php

86 lines
2.1 KiB
PHP
Raw Normal View History

<?php
namespace Model;
use Core\Db;
use User\UserIp;
class ActionModel
{
private int $uid;
public function __construct(int $uid)
{
$this->uid = $uid;
}
2023-11-02 13:57:39 +00:00
public static function new(array $user, string $vals, string $vars, int $time = 0)
{
if (!$time) {
$time = time();
}
Db::sql(
'insert into actions (uid, time, city, room, vars, ip, vals, val) values (?,?,?,?,?,?,?,?)',
[
$user['id'],
$time,
$user['city'],
$user['room'],
$vars,
UserIp::get(),
$vals,
'',
]
);
}
public static function getAll(string $filter = ''): array
{
return Db::getRows('select * from actions');
}
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]);
}
2023-11-05 02:46:07 +00:00
public static function deleteById(int $id): void
{
Db::sql('delete from actions where id = ?', [$id]);
}
2023-11-02 13:57:39 +00:00
/*protected function testAction($filter, $tp): array
{
2023-11-02 13:57:39 +00:00
if ($tp == 1) {
$query = 'select * from actions where ' . $filter;
} elseif ($tp == 2) {
$query = 'select count(*) from actions where ' . $filter;
} else {
return [];
}
$arr = mysql_fetch_array(mysql_query($query));
2023-11-02 13:57:39 +00:00
return !empty($arr) ? $arr : [];
}*/
}