battles/classes/nick.php

74 lines
2.0 KiB
PHP
Raw Normal View History

2018-03-01 14:51:01 +00:00
<?php
/**
* Copyright (c) 2018.
* Author: Igor Barkov <lopar.4ever@gmail.com>
* Project name: Battles-Game
*/
2018-03-03 18:24:19 +00:00
2018-03-01 14:51:01 +00:00
class nick
{
2018-03-02 23:49:16 +00:00
private $user_data;
2018-03-03 17:16:13 +00:00
2018-03-03 00:07:27 +00:00
/**
* nick constructor.
2018-03-03 00:34:12 +00:00
* @param int $playerId
2018-03-03 00:07:27 +00:00
*/
2018-03-03 18:11:48 +00:00
private function __construct($playerId)
2018-03-03 17:16:13 +00:00
{
2018-03-02 23:49:16 +00:00
if (!$this->user_data) {
$user = db::c()->query('
SELECT
`login`,
`level`,
`align`,
(SELECT `short` FROM `clans` WHERE `clans`.`id` = `klan`) AS `klan`,
(SELECT 1 FROM `effects` WHERE `owner` = `users`.`id` AND `type` = 1022) AS `invis`,
`hp`,
`maxhp`
FROM `users` WHERE `id` = ?i', $playerId)->fetch_assoc();
2018-03-02 23:49:16 +00:00
$this->user_data = $user;
}
2018-03-01 16:56:17 +00:00
2018-03-01 14:51:01 +00:00
}
/**
* @param $playerId
* @return nick
*/
public static function id($playerId)
2018-03-03 18:11:48 +00:00
{
return new self($playerId);
}
2018-03-03 17:16:13 +00:00
2018-03-03 00:34:12 +00:00
/**
* @param int $showInvisibility
* @return string
2018-03-03 00:34:12 +00:00
*/
public function full($showInvisibility = 0)
2018-03-03 17:16:13 +00:00
{
$n ='';
if ($showInvisibility && $this->user_data['invis']) {
return '<i>невидимка</i>';
2018-03-03 17:16:13 +00:00
} else {
if ($this->user_data['align']) {
2018-03-04 00:24:24 +00:00
$n .= sprintf('<img src="i/align_%s.gif">', htmlspecialchars($this->user_data['align']));
2018-03-03 17:16:13 +00:00
}
if ($this->user_data['klan']) {
2018-03-04 00:24:24 +00:00
$n .= sprintf('<img src="i/klan/%s.gif">', htmlspecialchars($this->user_data['klan']));
2018-03-03 17:16:13 +00:00
}
2018-03-03 00:34:12 +00:00
}
2018-03-04 00:24:24 +00:00
$n .= sprintf('<b>%s</b> [%s] <a href="inf.php?%s" target="_blank"><img src="i/inf.gif" style="width:12px;height:11px"></a>', htmlspecialchars($this->user_data['login']), htmlspecialchars($this->user_data['level']), htmlspecialchars($this->user_data['login']));
2018-03-03 18:52:22 +00:00
2018-03-04 00:24:24 +00:00
return $n;
2018-03-01 14:51:01 +00:00
}
/**
* @return string
*/
public function short()
{
if ($this->user_data['invis']) {
return '<i>невидимка</i>';
} else return htmlspecialchars($this->user_data['login']);
}
2018-03-01 14:51:01 +00:00
}