dev #38

Merged
lopar merged 22 commits from dev into master 2021-02-03 08:56:49 +00:00
3 changed files with 36 additions and 28 deletions
Showing only changes of commit 8d0bce6299 - Show all commits

View File

@ -2,8 +2,10 @@
namespace Battles; namespace Battles;
use Config; use Config;
use SQLite3; use SQLite3;
use SQLite3Result;
class GameLogs class GameLogs
{ {
@ -52,4 +54,29 @@ class GameLogs
$row->execute(); $row->execute();
$row->close(); $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 <?php
namespace Battles; namespace Battles;
use Battles\Models\EffectsModel;
use Exceptions\GameException;
class UserInfo extends User class UserInfo extends User
{ {
use Rooms; 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>'; $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); 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>'; echo '<div class="secret-info-user-log"><b>Личное дело</b><br>';
while ($userLogRow = $this->UserLogs->getUserLog()->fetch_object()) { 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 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-user-log -->';
echo '</div><!-- secret-info -->'; echo '</div><!-- secret-info -->';
@ -149,17 +152,17 @@ class UserInfo extends User
public function showUserInfo() public function showUserInfo()
{ {
$this->WatcherStatus(); $this->WatcherStatus();
$effects = new \Battles\Models\EffectsModel($this->id); $effects = new EffectsModel($this->id);
if ($this->block && (!$this->watcherIsAdmin || !$this->watcherIsModerator)) { 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)) { } elseif ($effects->getHideUserInfoStatus() && (!$this->watcherIsAdmin || !$this->watcherIsModerator)) {
if ($effects->getHideUserInfoStatus() == -1) { if ($effects->getHideUserInfoStatus() == -1) {
$date = 'навсегда'; $date = 'навсегда';
} else { } else {
$date = 'до' . date('d.m.Y', strtotime($effects->getHideUserInfoStatus())); $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 { } else {
$this->Info(); $this->Info();
} }