Skip to content

Commit 7efd7c0

Browse files
committed
Added last online
1 parent 98a613c commit 7efd7c0

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
}
1111
],
1212
"require": {
13-
"php": "^7.4|^8.0"
13+
"php": "^7.4|^8.0",
14+
"ext-pdo": "*"
1415
},
1516
"require-dev": {
1617
"roave/security-advisories": "dev-latest",

src/Simonsator/PartyAndFriends/PAFPlayer.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace Simonsator\PartyAndFriends;
44

5+
use DateTime;
6+
use Exception;
7+
58
class PAFPlayer
69
{
710
private string $uniqueID;
@@ -142,11 +145,25 @@ public function getSettingsWorth(int $pSettingsID): int
142145
return 0;
143146
}
144147

148+
public function getLastOnline(): DateTime
149+
{
150+
$stmt = PAFPlayerManager::getInstance()->getConnection()->prepare(
151+
"SELECT last_online
152+
FROM {$this->getTablePrefix()}players
153+
WHERE player_id = '{$this->id}' LIMIT 1");
154+
$stmt->execute();
155+
try {
156+
return new DateTime($stmt->fetch()['last_online']);
157+
} catch (Exception $e) {
158+
return new DateTime();
159+
}
160+
}
161+
145162
/**
146163
* @param PAFPlayer $player The player which should be the new friend of this player
147164
* @return void
148165
*/
149-
public function addFriend(PAFPlayer $player)
166+
public function addFriend(PAFPlayer $player): void
150167
{
151168
$stmt = PAFPlayerManager::getInstance()->getConnection()->prepare(
152169
"INSERT INTO {$this->getTablePrefix()}friend_assignment

0 commit comments

Comments
 (0)