From ea51ad27c38be88d86514cb979bb394fcfbef1f0 Mon Sep 17 00:00:00 2001 From: slawkens Date: Sat, 1 Feb 2025 00:35:22 +0100 Subject: [PATCH] Fix online status + vocation for TFS 0.x --- system/functions.php | 4 ---- system/pages/highscores.php | 4 ---- system/src/Models/Player.php | 18 ++++++++++++------ 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/system/functions.php b/system/functions.php index 7a26b7ec..d25dc5ae 100644 --- a/system/functions.php +++ b/system/functions.php @@ -1107,10 +1107,6 @@ function getTopPlayers($limit = 5, $skill = 'level') { $columns[] = 'lookaddons'; } - if ($db->hasColumn('players', 'online')) { - $columns[] = 'online'; - } - return Player::query() ->select($columns) ->withOnlineStatus() diff --git a/system/pages/highscores.php b/system/pages/highscores.php index d8057595..269c8ce4 100644 --- a/system/pages/highscores.php +++ b/system/pages/highscores.php @@ -234,10 +234,6 @@ foreach($highscores as $id => &$player) $player['experience'] = number_format($player['experience']); } - if(!$settingHighscoresVocation) { - unset($player['vocation']); - } - $player['link'] = getPlayerLink($player['name'], false); $player['flag'] = getFlagImage($player['country']); if($settingHighscoresOutfit) { diff --git a/system/src/Models/Player.php b/system/src/Models/Player.php index 6faf5df3..77fe4504 100644 --- a/system/src/Models/Player.php +++ b/system/src/Models/Player.php @@ -49,8 +49,8 @@ class Player extends Model { public function getVocationNameAttribute() { $vocation = $this->vocation; - if (isset($this->promotion)) { - $vocation *= $this->promotion; + if (isset($this->promotion) && $this->promotion > 0) { + $vocation += ($this->promotion * setting('core.vocations_amount')); } return config('vocations')[$vocation] ?? 'Unknown'; @@ -80,11 +80,17 @@ class Player extends Model { $query->where($column, 0); } - public function scopeWithOnlineStatus($query) { + public function scopeWithOnlineStatus($query) + { global $db; - $query->when($db->hasTable('players_online'), function ($query) { - $query->with('onlineTable'); - }); + if ($db->hasColumn('players', 'online')) { + $query->addSelect('online'); + } + else { + $query->when($db->hasTable('players_online'), function ($query) { + $query->with('onlineTable'); + }); + } } public function getOutfitUrlAttribute() {