Skip to content

Commit

Permalink
GH-230 Move stats list to a component
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed Jul 7, 2022
1 parent a11d186 commit 6b5e663
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 155 deletions.
1 change: 1 addition & 0 deletions modules/overview/_includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,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/PlanetNameChange/PlanetNameChange.screen.php');
include($includePath . './screens/PlanetNameChange/PlanetNameChange.utils.php');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?php

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

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

$stats = $props['stats'];

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

$categories = [
'general' => [
'categoryName' => $_Lang['Box_statGeneral'],
'categoryType' => '',
'pointsKey' => 'total_points',
'recordsCurrentKey' => 'total_old_rank',
'recordsOldKey' => 'total_rank',
],
'buildings' => [
'categoryName' => $_Lang['Box_statBuildings'],
'categoryType' => '4',
'pointsKey' => 'build_points',
'recordsCurrentKey' => 'build_rank',
'recordsOldKey' => 'build_old_rank',
],
'fleet' => [
'categoryName' => $_Lang['Box_statFleet'],
'categoryType' => '2',
'pointsKey' => 'fleet_points',
'recordsCurrentKey' => 'fleet_rank',
'recordsOldKey' => 'fleet_old_rank',
],
'defenses' => [
'categoryName' => $_Lang['Box_statDefense'],
'categoryType' => '5',
'pointsKey' => 'defs_points',
'recordsCurrentKey' => 'defs_rank',
'recordsOldKey' => 'defs_old_rank',
],
'research' => [
'categoryName' => $_Lang['Box_statResearch'],
'categoryType' => '3',
'pointsKey' => 'tech_points',
'recordsCurrentKey' => 'tech_rank',
'recordsOldKey' => 'tech_old_rank',
],
];

$categoriesHTML = [];

foreach ($categories as $category) {
$categoryTplBodyParams = [
'categoryName' => $category['categoryName'],
'statCategoryType' => $category['categoryType'],
'userCategoryRankLabel' => '0',
'userCategoryRankPosition' => '0',
'userCategoryPoints' => prettyNumber($stats[$category['pointsKey']]),
'statsUnit' => $_Lang['_statUnit'],
];

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

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

continue;
}

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

$positionDifference = $oldPosition - $currentPosition;
$positionDifferenceLabel = null;

if ($positionDifference > 0) {
$positionDifferenceLabel = "<span class=\"lime\">(+{$positionDifference})</span>";
} elseif ($positionDifference == 0) {
$positionDifferenceLabel = "<span class=\"lightblue\">(*)</span>";
} else {
$positionDifferenceLabel = "<span class=\"red\">({$positionDifference})</span>";
}

$categoryTplBodyParams['userCategoryRankPosition'] = $currentPosition;
$categoryTplBodyParams['userCategoryRankLabel'] = implode(
' ',
[
$currentPosition,
$positionDifferenceLabel,
]
);

$categoriesHTML[] = parsetemplate($tplBodyCache['statCategoryRow'], $categoryTplBodyParams);
}

$tplBodyParams = [
'statsCategories' => implode('', $categoriesHTML),
];
$tplBodyParams = array_merge($_Lang, $tplBodyParams);

$componentHTML = parsetemplate(
$tplBodyCache['body'],
$tplBodyParams
);

return [
'componentHTML' => $componentHTML,
];
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<table width="100%" align="center">
<tr>
<td colspan="2" class="c pad3">{Statistics}</td>
</tr>
{statsCategories}
</table>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

header("Location: ../index.php");

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<tr>
<th><a href="stats.php?range={userCategoryRankPosition}&amp;type={statCategoryType}">{categoryName}</a></th>
<th>{userCategoryRankLabel}<br/><span class="grey">{userCategoryPoints} {statsUnit}</span></th>
</tr>
134 changes: 4 additions & 130 deletions overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,138 +336,12 @@
$Referred = doquery("SELECT COUNT(`id`) as `count` FROM {{table}} WHERE `referrer_id` = {$_User['id']};", 'referring_table', true);
$parse['RefferedCounter'] = prettyNumber((($Referred['count'] > 0) ? $Referred['count'] : '0'));

// --- Get UserStats ---
// --- Render UserStats ---
$StatRecord = doquery("SELECT * FROM {{table}} WHERE `stat_type` = '1' AND `id_owner` = {$_User['id']} LIMIT 1;", 'statpoints', true);
$parse['user_points'] = prettyNumber($StatRecord['build_points']);
$parse['user_fleet'] = prettyNumber($StatRecord['fleet_points']);
$parse['user_defs'] = prettyNumber($StatRecord['defs_points']);
$parse['player_points_tech'] = prettyNumber($StatRecord['tech_points']);
$parse['total_points'] = prettyNumber($StatRecord['total_points']);

// Total Rank changes
if($StatRecord['total_rank'] > 0)
{
$ile = $StatRecord['total_old_rank'] - $StatRecord['total_rank'];
if($ile > 0)
{
$ile = "<span class=\"lime\">(+{$ile})</span>";
}
elseif($ile < 0)
{
$ile = "<span class=\"red\">({$ile})</span>";
}
else
{
$ile = '<span class="lightblue">(*)</span>';
}
$parse['user_total_rank'] = '<a href="stats.php?range='.$StatRecord['total_rank'].'">'.$StatRecord['total_rank'].'</a> '.$ile;
}
else
{
$parse['user_total_rank'] = 0;
$StatRecord['total_rank'] = '0';
}
$parse['set_user_total_rank'] = $StatRecord['total_rank'];

// Build Rank changes
if(isset($StatRecord['build_rank']) && $StatRecord['build_rank'] > 0)
{
$ile = $StatRecord['build_old_rank'] - $StatRecord['build_rank'];
if($ile > 0)
{
$ile = "<span class=\"lime\">(+{$ile})</span>";
}
elseif($ile < 0)
{
$ile = "<span class=\"red\">({$ile})</span>";
}
else
{
$ile = '<span class="lightblue">(*)</span>';
}
$parse['user_br'] = '<a href="stats.php?range='.$StatRecord['build_rank'].'&amp;type=4">'.$StatRecord['build_rank'].'</a> '.$ile;
}
else
{
$parse['user_br'] = 0;
$StatRecord['build_rank'] = '0';
}
$parse['set_user_br'] = $StatRecord['build_rank'];

// Fleet rank changes
if(isset($StatRecord['fleet_rank']) && $StatRecord['fleet_rank'] > 0)
{
$ile = $StatRecord['fleet_old_rank'] - $StatRecord['fleet_rank'];
if($ile > 0)
{
$ile = "<span class=\"lime\">(+{$ile})</span>";
}
else if($ile < 0)
{
$ile = "<span class=\"red\">({$ile})</span>";
}
else
{
$ile = '<span class="lightblue">(*)</span>';
}
$parse['user_fr'] = '<a href="stats.php?range='.$StatRecord['fleet_rank'].'&amp;type=2">'.$StatRecord['fleet_rank'].'</a> '.$ile;
}
else
{
$parse['user_fr'] = 0;
$StatRecord['fleet_rank'] = '0';
}
$parse['set_user_fr'] = $StatRecord['fleet_rank'];

// Defense rank changes
if(isset($StatRecord['defs_rank']) && $StatRecord['defs_rank'] > 0)
{
$ile = $StatRecord['defs_old_rank'] - $StatRecord['defs_rank'];
if($ile > 0)
{
$ile = "<span class=\"lime\">(+{$ile})</span>";
}
else if($ile < 0)
{
$ile = "<span class=\"red\">({$ile})</span>";
}
else
{
$ile = '<span class="lightblue">(*)</span>';
}
$parse['user_dr'] = '<a href="stats.php?range='.$StatRecord['defs_rank'].'&amp;type=5">'.$StatRecord['defs_rank'].'</a> '.$ile;
}
else
{
$parse['user_dr'] = 0;
$StatRecord['defs_rank'] = '0';
}
$parse['set_user_dr'] = $StatRecord['defs_rank'];

// Research rank changes
if(isset($StatRecord['tech_rank']) && $StatRecord['tech_rank'] > 0)
{
$ile = $StatRecord['tech_old_rank'] - $StatRecord['tech_rank'];
if($ile > 0)
{
$ile = "<span class=\"lime\">(+{$ile})</span>";
}
else if($ile < 0)
{
$ile = "<span class=\"red\">({$ile})</span>";
}
else
{
$ile = '<span class="lightblue">(*)</span>';
}
$parse['user_tr'] = '<a href="stats.php?range='.$StatRecord['tech_rank'].'&amp;type=3">'.$StatRecord['tech_rank'].'</a> '.$ile;
}
else
{
$parse['user_tr'] = 0;
$StatRecord['tech_rank'] = '0';
}
$parse['set_user_tr'] = $StatRecord['tech_rank'];
$parse['Component_StatsList'] = Overview\Screens\Overview\Components\StatsList\render([
'stats' => $StatRecord,
])['componentHTML'];

// Get User Achievements
$GetStats_Fields = '`ustat_raids_won`, `ustat_raids_draw`, `ustat_raids_lost`, `ustat_raids_acs_won`, `ustat_raids_inAlly`, `ustat_raids_missileAttack`';
Expand Down
26 changes: 1 addition & 25 deletions templates/default_template/overview_body.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -166,31 +166,7 @@ $(document).ready(function()
</table>
</th>
<th width="215">
<table width="100%" align="center">
<tr>
<td colspan="2" class="c pad3">{Statistics}</td>
</tr>
<tr>
<th><a href="stats.php?range={set_user_total_rank}">{Box_statGeneral}</a></th>
<th>{user_total_rank}<br/><span class="grey">{total_points} {_statUnit}</span></th>
</tr>
<tr>
<th><a href="stats.php?range={set_user_br}&amp;type=4">{Box_statBuildings}</a></th>
<th>{user_br}<br/><span class="grey">{user_points} {_statUnit}</span></th>
</tr>
<tr>
<th><a href="stats.php?range={set_user_fr}&amp;type=2">{Box_statFleet}</a></th>
<th>{user_fr}<br/><span class="grey">{user_fleet} {_statUnit}</span></th>
</tr>
<tr>
<th><a href="stats.php?range={set_user_dr}&amp;type=5">{Box_statDefense}</a></th>
<th>{user_dr}<br/><span class="grey">{user_defs} {_statUnit}</span></th>
</tr>
<tr>
<th><a href="stats.php?range={set_user_tr}&amp;type=3">{Box_statResearch}</a></th>
<th>{user_tr}<br/><span class="grey">{player_points_tech} {_statUnit}</span></th>
</tr>
</table>
{Component_StatsList}
<br/>
<table width="100%" align="center">
<tr>
Expand Down

0 comments on commit 6b5e663

Please sign in to comment.