* Project name: Battles-Game */ class nick { private $user_data; /** * nick constructor. * @param int $playerId */ private function __construct($playerId) { 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(); $this->user_data = $user; } } /** * @param $playerId * @return nick */ public static function id($playerId) { return new self($playerId); } /** * @param int $showInvisibility * @return string */ public function full($showInvisibility = 0) { $n =''; if ($showInvisibility && $this->user_data['invis']) { return 'невидимка'; } else { if ($this->user_data['align']) { $n .= sprintf('', $this->user_data['align']); } if ($this->user_data['klan']) { $n .= sprintf('', $this->user_data['klan']); } } $n .= sprintf('%s [%s] ', $this->user_data['login'], $this->user_data['level'], $this->user_data['login']); return htmlspecialchars($n); } /** * @return string */ public function short() { if ($this->user_data['invis']) { return 'невидимка'; } else return htmlspecialchars($this->user_data['login']); } }