diff --git a/classes/Battles/GameLogs.php b/classes/Battles/GameLogs.php index d4c1b3b..53c76a9 100644 --- a/classes/Battles/GameLogs.php +++ b/classes/Battles/GameLogs.php @@ -2,8 +2,10 @@ namespace Battles; + use Config; use SQLite3; +use SQLite3Result; class GameLogs { @@ -52,4 +54,29 @@ class GameLogs $row->execute(); $row->close(); } + + public static function getUserLogs($userId = null, $type = null): SQLite3Result + { + $db = new SQLite3(Config::$db_sqlite); + + if ($userId && $type) { + $query = "SELECT * FROM users_logs WHERE user_id = ? AND type = ?"; + $row = $db->prepare($query); + $row->bindValue(1, $userId, SQLITE3_INTEGER); + $row->bindValue(2, $type, SQLITE3_TEXT); + } elseif ($userId && !$type) { + $query = "SELECT * FROM users_logs WHERE user_id = ?"; + $row = $db->prepare($query); + $row->bindValue(1, $userId, SQLITE3_INTEGER); + } elseif (!$userId && $type) { + $query = "SELECT * FROM users_logs WHERE type= ?"; + $row = $db->prepare($query); + $row->bindValue(1, $type, SQLITE3_TEXT); + } elseif (!$userId && !$type) { + $query = "SELECT * FROM users_logs"; + $row = $db->prepare($query); + } + + return $row->execute(); + } } \ No newline at end of file diff --git a/classes/Battles/Models/UserLogModel.php b/classes/Battles/Models/UserLogModel.php deleted file mode 100644 index 7c3c1a7..0000000 --- a/classes/Battles/Models/UserLogModel.php +++ /dev/null @@ -1,22 +0,0 @@ -DB = \db::c()->query('SELECT * FROM users_logs WHERE user_id = ?i ORDER BY `id` ASC', $user_id); - - } - - public function getUserLog() - { - return $this->DB; - } -} \ No newline at end of file diff --git a/classes/Battles/UserInfo.php b/classes/Battles/UserInfo.php index 2a2a1ca..ab978cd 100644 --- a/classes/Battles/UserInfo.php +++ b/classes/Battles/UserInfo.php @@ -1,5 +1,8 @@ ИД Игрока: %s
ИД Комнаты: %s
Деньги: %s
Деньги в банке: %s
Опыт: %s
Нераспределённые очки: %s
Текущая сессия: %s
'; echo sprintf($infoString, $this->id, $this->room, $this->money, $this->Bank->getMoney(), $this->experience, $this->free_stat_points, $this->session_id); } - $this->UserLogs = new \Battles\Models\UserLogModel($this->id); + $this->UserLogs = GameLogs::getUserLogs($this->id); echo '
Личное дело
'; - while ($userLogRow = $this->UserLogs->getUserLog()->fetch_object()) { - echo sprintf('%s
', date("d.m.Y H:i ", strtotime($userLogRow->date)) . $userLogRow->text); + while ($userLogRow = $this->UserLogs->fetchArray(SQLITE3_ASSOC)) { + echo sprintf('%s
', date("d.m.Y H:i ", strtotime($userLogRow['date'])) . $userLogRow['text']); } echo '
'; echo ''; @@ -149,17 +152,17 @@ class UserInfo extends User public function showUserInfo() { $this->WatcherStatus(); - $effects = new \Battles\Models\EffectsModel($this->id); + $effects = new EffectsModel($this->id); if ($this->block && (!$this->watcherIsAdmin || !$this->watcherIsModerator)) { - throw new \Exceptions\GameException('Персонаж ' . $this->login . ' заблокирован!'); + throw new GameException('Персонаж ' . $this->login . ' заблокирован!'); } elseif ($effects->getHideUserInfoStatus() && (!$this->watcherIsAdmin || !$this->watcherIsModerator)) { if ($effects->getHideUserInfoStatus() == -1) { $date = 'навсегда'; } else { $date = 'до' . date('d.m.Y', strtotime($effects->getHideUserInfoStatus())); } - throw new \Exceptions\GameException('Персонаж ' . $this->login . ' обезличен ' . $date . '.'); + throw new GameException('Персонаж ' . $this->login . ' обезличен ' . $date . '.'); } else { $this->Info(); }