Skip to content

Commit

Permalink
top discoverer with timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
g5bot committed Dec 7, 2023
1 parent 0afe625 commit d720196
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ public function handle(GameControllerInterface $game): void
$game->setTemplateVar(
'DISCOVERER_LIST',
array_map(
fn (array $data): DatabaseTopListWithPoints => $this->databaseUiFactory->createDatabaseTopListWithPoints($data['user_id'], (string) $data['points']),
fn (array $data): DatabaseTopListWithPoints => $this->databaseUiFactory->createDatabaseTopListWithPoints(
$data['user_id'],
(string) $data['points'],
$data['timestamp'],
),
$this->databaseUserRepository->getTopList()
)
);
Expand Down
15 changes: 11 additions & 4 deletions src/Orm/Repository/DatabaseUserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,22 @@ public function getTopList(): array
$rsm = new ResultSetMapping();
$rsm->addScalarResult('user_id', 'user_id', 'integer');
$rsm->addScalarResult('points', 'points', 'integer');
$rsm->addScalarResult('timestamp', 'timestamp', 'integer');

return $this->getEntityManager()
->createNativeQuery(
'SELECT dbu.user_id, SUM(dbc.points) as points FROM stu_database_user dbu LEFT JOIN
stu_database_entrys dbe ON dbe.id = dbu.database_id LEFT JOIN stu_database_categories dbc ON
dbc.id = dbe.category_id
'SELECT dbu.user_id, SUM(dbc.points) AS points,
(SELECT MAX(du.date)
FROM stu_database_user du
WHERE du.user_id = dbu.user_id) AS timestamp
FROM stu_database_user dbu
LEFT JOIN stu_database_entrys dbe
ON dbe.id = dbu.database_id
LEFT JOIN stu_database_categories dbc
ON dbc.id = dbe.category_id
WHERE dbu.user_id > :firstUserId
GROUP BY dbu.user_id
ORDER BY points DESC
ORDER BY points DESC, timestamp ASC
LIMIT 10',
$rsm
)
Expand Down
2 changes: 1 addition & 1 deletion src/Orm/Repository/DatabaseUserRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function prototype(): DatabaseUserInterface;
public function save(DatabaseUserInterface $entry): void;

/**
* @return array<array{user_id: int, points: int}>
* @return array<array{user_id: int, points: int, timestamp: int}>
*/
public function getTopList(): array;

Expand Down
2 changes: 1 addition & 1 deletion src/html/database.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
tal:define="USER entry/getUser" />
</div>
<div class="userName" tal:content="structure bbcode:entry/getUser/getName">USER</div>
<div>
<div tal:attributes="title datetime:entry/getTime">
Punkte: <span tal:content="entry/getPoints">AMOUNT</span>
</div>
<div>
Expand Down

0 comments on commit d720196

Please sign in to comment.