Skip to content

Commit

Permalink
GH-230 Move game stats data fetcher to utils as well
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed Jul 17, 2022
1 parent 169d22d commit 8bd6ce3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 11 deletions.
1 change: 1 addition & 0 deletions modules/overview/_includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
include($includePath . './screens/Overview/components/PlanetsListElement/PlanetsListElement.component.php');
include($includePath . './screens/Overview/components/ResourcesTransport/ResourcesTransport.component.php');
include($includePath . './screens/Overview/components/StatsList/StatsList.component.php');
include($includePath . './screens/Overview/components/StatsList/StatsList.utils.php');
include($includePath . './screens/Overview/components/VacationInfoBox/VacationInfoBox.component.php');

include($includePath . './screens/PlanetNameChange/PlanetNameChange.screen.php');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@

namespace UniEngine\Engine\Modules\Overview\Screens\Overview\Components\StatsList;

use UniEngine\Engine\Modules\Overview\Screens\Overview\Components\StatsList;

/**
* @param array $props
* @param array $props['stats']
* @param number $props['userId']
*/
function render($props) {
global $_Lang;

$stats = $props['stats'];

$localTemplateLoader = createLocalTemplateLoader(__DIR__);
$tplBodyCache = [
'body' => $localTemplateLoader('body'),
'statCategoryRow' => $localTemplateLoader('statCategoryRow'),
];

$statsData = StatsList\Utils\getUserGameStats([
'userId' => $props['userId'],
]);

$categories = [
'general' => [
'categoryName' => $_Lang['Box_statGeneral'],
Expand Down Expand Up @@ -63,24 +67,24 @@ function render($props) {
'statCategoryType' => $category['categoryType'],
'userCategoryRankLabel' => '0',
'userCategoryRankPosition' => '0',
'userCategoryPoints' => prettyNumber($stats[$category['pointsKey']]),
'userCategoryPoints' => prettyNumber($statsData[$category['pointsKey']]),
'statsUnit' => $_Lang['_statUnit'],
];

$recordsCurrentKey = $category['recordsCurrentKey'];
$recordsOldKey = $category['recordsOldKey'];

if (
!isset($stats[$recordsCurrentKey]) ||
$stats[$recordsCurrentKey] <= 0
!isset($statsData[$recordsCurrentKey]) ||
$statsData[$recordsCurrentKey] <= 0
) {
$categoriesHTML[] = parsetemplate($tplBodyCache['statCategoryRow'], $categoryTplBodyParams);

continue;
}

$oldPosition = $stats[$recordsOldKey];
$currentPosition = $stats[$recordsCurrentKey];
$oldPosition = $statsData[$recordsOldKey];
$currentPosition = $statsData[$recordsCurrentKey];

$positionDifference = $oldPosition - $currentPosition;
$positionDifferenceLabel = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace UniEngine\Engine\Modules\Overview\Screens\Overview\Components\StatsList\Utils;

/**
* @param array $props
* @param array $props['userId']
*/
function getUserGameStats($props) {
$userId = $props['userId'];

$query = (
"SELECT * " .
"FROM {{table}} " .
"WHERE " .
"`stat_type` = '1' AND " .
"`id_owner` = {$userId} " .
"LIMIT 1 " .
";"
);

return doquery($query, 'statpoints', true);
}

?>
4 changes: 1 addition & 3 deletions overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,8 @@
$parse['RefferedCounter'] = prettyNumber((($Referred['count'] > 0) ? $Referred['count'] : '0'));

// --- Render UserStats ---
$StatRecord = doquery("SELECT * FROM {{table}} WHERE `stat_type` = '1' AND `id_owner` = {$_User['id']} LIMIT 1;", 'statpoints', true);

$parse['Component_StatsList'] = Overview\Screens\Overview\Components\StatsList\render([
'stats' => $StatRecord,
'userId' => $_User['id'],
])['componentHTML'];
$parse['Component_CombatStatsList'] = Overview\Screens\Overview\Components\CombatStatsList\render([
'userId' => $_User['id'],
Expand Down

0 comments on commit 8bd6ce3

Please sign in to comment.