Skip to content

Commit

Permalink
GH-224 Move login entries history rendering entirely to a component
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed Jun 29, 2022
1 parent dd96fea commit 884a611
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 28 deletions.
1 change: 1 addition & 0 deletions modules/settings/_includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

include($includePath . './components/IgnoredUsersList/IgnoredUsersList.component.php');
include($includePath . './components/LanguageSelectorList/LanguageSelectorList.component.php');
include($includePath . './components/LoginHistory/LoginHistory.component.php');
include($includePath . './components/LoginHistoryEntry/LoginHistoryEntry.component.php');
include($includePath . './components/QuickTransportPlanetsList/QuickTransportPlanetsList.component.php');
include($includePath . './components/SkinSelectorList/SkinSelectorList.component.php');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace UniEngine\Engine\Modules\Settings\Components\LoginHistory;

use UniEngine\Engine\Includes\Helpers\Common;
use UniEngine\Engine\Modules\Settings;

/**
* @param object $props
* @param array $props['loginHistoryEntries']
* @param number $props['displayItemsCount']
* @param string $props['currentUserLastIp']
* @param number $props['currentTimestamp']
*
* @return object $result
* @return string $result['componentHTML']
*/
function render($props) {
global $_Lang;

$loginHistoryEntries = $props['loginHistoryEntries'];
$displayItemsCount = $props['displayItemsCount'];
$currentUserLastIp = $props['currentUserLastIp'];
$currentTimestamp = $props['currentTimestamp'];

if (empty($loginHistoryEntries)) {
$localTemplateLoader = createLocalTemplateLoader(__DIR__);
$componentHTML = parsetemplate($localTemplateLoader('emptyList'), $_Lang);

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

$limitedLoginHistoryEntries = Common\Collections\firstN($loginHistoryEntries, $displayItemsCount);

$listElements = array_map_withkeys(
$limitedLoginHistoryEntries,
function ($loginEntry) use ($currentUserLastIp, $currentTimestamp) {
return Settings\Components\LoginHistoryEntry\render([
'entryData' => $loginEntry,
'userLastIp' => $currentUserLastIp,
'currentTimestamp' => $currentTimestamp,
])['componentHTML'];
}
);

$componentHTML = implode('', $listElements);

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

?>
1 change: 1 addition & 0 deletions modules/settings/components/LoginHistory/emptyList.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<tr><th colspan="4">{Logons_ListEmpty}</th></tr>
5 changes: 5 additions & 0 deletions modules/settings/components/LoginHistory/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

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

?>
38 changes: 10 additions & 28 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -1052,35 +1052,17 @@ function isInputKeyChecked($input, $key) {
'userId' => $_User['id'],
'historyEntriesLimit' => $LogonLIMIT,
]);
$loginHistoryEntries = Settings\Utils\Helpers\parseLoginHistoryEntries([
'historyEntries' => $accountLoginHistory,
'historyEntriesLimit' => $LogonLIMIT,
]);

if (count($accountLoginHistory) > 0) {
$LogonList = Settings\Utils\Helpers\parseLoginHistoryEntries([
'historyEntries' => $accountLoginHistory,
'historyEntriesLimit' => $LogonLIMIT,
]);

$LimitCounter = $LogonLIMIT;

$_Lang['ParseLogonsList'] = [];

foreach ($LogonList as $LogonData) {
if ($LimitCounter <= 0) {
break;
}

$_Lang['ParseLogonsList'][] = Settings\Components\LoginHistoryEntry\render([
'entryData' => $LogonData,
'userLastIp' => $_User['user_lastip'],
'currentTimestamp' => $Now,
])['componentHTML'];

$LimitCounter -= 1;
}

$_Lang['ParseLogonsList'] = implode('', $_Lang['ParseLogonsList']);
} else {
$_Lang['ParseLogonsList'] = '<tr><th colspan="4">'.$_Lang['Logons_ListEmpty'].'</th></tr>';
}
$_Lang['ParseLogonsList'] = Settings\Components\LoginHistory\render([
'loginHistoryEntries' => $loginHistoryEntries,
'displayItemsCount' => $LogonLIMIT,
'currentUserLastIp' => $_User['user_lastip'],
'currentTimestamp' => $Now,
])['componentHTML'];

// FleetColors - Pickers
$TPL_FleetColors_Row = gettemplate('settings_fleetcolors_row');
Expand Down

0 comments on commit 884a611

Please sign in to comment.