Fix spy favorites showing numeric IDs instead of player/alliance names#538
Fix spy favorites showing numeric IDs instead of player/alliance names#538
Conversation
Agent-Logs-Url: https://github.com/OGSteam/ogspy/sessions/601bd64b-e567-4ce7-9eab-d7da8d52db19 Co-authored-by: darknoon29 <13015521+darknoon29@users.noreply.github.com>
… query Agent-Logs-Url: https://github.com/OGSteam/ogspy/sessions/601bd64b-e567-4ce7-9eab-d7da8d52db19 Co-authored-by: darknoon29 <13015521+darknoon29@users.noreply.github.com>
|
There was a problem hiding this comment.
Pull request overview
Fixes the spy favorites list so it displays player/alliance names (instead of numeric FK IDs) by selecting the proper name columns and adding the missing alliance join.
Changes:
- Update
get_favoriteSpyList()SELECT to returnplayer.name/ally.namefor display. - Add
LEFT JOINto the alliance table to resolveplayer.ally_idinto an alliance name. - Alias
user.nameasuser_nameto avoid ambiguity among multiplenamecolumns.
| $request = "SELECT pspy.`id`, astro.`galaxy`, astro.`system`, astro.`row`, `dateRE`, `user`.`name` AS `user_name`, `astro`.`type`, `ally`.`name` AS `ally_name`, `player`.`name` AS `player_name`, `player`.`status`"; | ||
| $request .= " FROM " . TABLE_PARSEDSPY . " `pspy`"; | ||
| $request .= " INNER JOIN " . TABLE_USER_BUILDING . " `astro` ON `pspy`.`astro_object_id` = `astro`.`id`"; | ||
| $request .= " INNER JOIN " . TABLE_GAME_PLAYER . " `player` ON `astro`.`player_id` = `player`.`id`"; | ||
| $request .= " LEFT JOIN " . TABLE_GAME_ALLY . " `ally` ON `player`.`ally_id` = `ally`.`id`"; | ||
| $request .= " INNER JOIN " . TABLE_USER . " `user` ON `user`.`id` = `pspy`.`sender_id`"; | ||
| $request .= " WHERE `pspy`.`sender_id`=$user_id "; | ||
| $request .= " ORDER BY " . $ordered_by; |
There was a problem hiding this comment.
ORDER BY uses $ordered_by values like ally, player, and coordinates, but the query no longer has columns/aliases with those names (it selects ally_name / player_name, and coordinates are split across astro.galaxy/system/row). As a result, clicking the sort links in views/home_spy.php (sort=1..4) will produce an SQL error (Unknown column ... in order clause) or sort incorrectly. Update the $ordered_by mapping to real SQL expressions/aliases (e.g., astro.galaxy, astro.system, astro.row for coordinates; ally.name/ally_name; player.name/player_name; and astro.type for moon).



get_favoriteSpyList()was selectingplayer.ally_idandastro.player_id(integer FKs) into theallyandplayerdisplay fields, so the favorites view rendered raw numeric IDs instead of names.Changes
model/Spy_Model.php—get_favoriteSpyList()astro.player_id→player.name AS player_name(player table already JOINed)player.ally_id→ally.name AS ally_nameLEFT JOIN TABLE_GAME_ALLY ally ON player.ally_id = ally.id(LEFT to preserve players without an alliance)user.name AS user_nameto disambiguate duplicatenamecolumns