This commit is contained in:
Igor Barkov (iwork) 2021-02-01 16:40:21 +02:00
parent 538047f36f
commit 8d0bce6299
3 changed files with 36 additions and 28 deletions

View File

@ -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();
}
}

View File

@ -1,22 +0,0 @@
<?php
/**
* Author: lopiu
* Date: 05.07.2020
* Time: 22:38
*/
namespace Battles\Models;
class UserLogModel
{
protected $DB;
public function __construct(int $user_id)
{
$this->DB = \db::c()->query('SELECT * FROM users_logs WHERE user_id = ?i ORDER BY `id` ASC', $user_id);
}
public function getUserLog()
{
return $this->DB;
}
}

View File

@ -1,5 +1,8 @@
<?php
namespace Battles;
use Battles\Models\EffectsModel;
use Exceptions\GameException;
class UserInfo extends User
{
use Rooms;
@ -136,10 +139,10 @@ class UserInfo extends User
$infoString = '<br><span>ИД Игрока: %s<br> ИД Комнаты: %s<br> Деньги: %s<br> Деньги в банке: %s<br> Опыт: %s<br> Нераспределённые очки: %s<br> Текущая сессия: %s</span>';
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 '<div class="secret-info-user-log"><b>Личное дело</b><br>';
while ($userLogRow = $this->UserLogs->getUserLog()->fetch_object()) {
echo sprintf('<code>%s</code><br>', date("d.m.Y H:i ", strtotime($userLogRow->date)) . $userLogRow->text);
while ($userLogRow = $this->UserLogs->fetchArray(SQLITE3_ASSOC)) {
echo sprintf('<code>%s</code><br>', date("d.m.Y H:i ", strtotime($userLogRow['date'])) . $userLogRow['text']);
}
echo '</div><!-- secret-info-user-log -->';
echo '</div><!-- secret-info -->';
@ -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('<span class="error">Персонаж ' . $this->login . ' заблокирован!</span>');
throw new GameException('<span class="error">Персонаж ' . $this->login . ' заблокирован!</span>');
} 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('<span class="error">Персонаж ' . $this->login . ' обезличен ' . $date . '.</span>');
throw new GameException('<span class="error">Персонаж ' . $this->login . ' обезличен ' . $date . '.</span>');
} else {
$this->Info();
}