-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-> Finishes #128
- Loading branch information
Showing
5 changed files
with
93 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
namespace MythicalClient\Chat; | ||
|
||
use MythicalClient\Chat\interface\UserActivitiesTypes; | ||
|
||
class UserActivities { | ||
|
||
/** | ||
* Add user activity | ||
* | ||
* @param string $uuid User UUID | ||
* @param string|\MythicalClient\Chat\interface\UserActivitiesTypes $type Activity type | ||
* @param string $ipv4 IP address | ||
* | ||
* @return bool | ||
*/ | ||
public static function add(string $uuid, string|UserActivitiesTypes $type, string $ipv4) : bool { | ||
$dbConn = Database::getPdoConnection(); | ||
|
||
$stmt = $dbConn->prepare("INSERT INTO " . self::getTable() . " (user, action, ip_address) VALUES (:user, :action, :ip_address)"); | ||
return $stmt->execute([ | ||
':user' => $uuid, | ||
':action' => $type, | ||
':ip_address' => $ipv4 | ||
]); | ||
} | ||
/** | ||
* Get user activities | ||
* | ||
* @param string $uuid User UUID | ||
* | ||
* @return array | ||
*/ | ||
public static function get(string $uuid) : array { | ||
$dbConn = Database::getPdoConnection(); | ||
|
||
$stmt = $dbConn->prepare("SELECT * FROM " . self::getTable() . " WHERE user = :user LIMIT 125"); | ||
$stmt->execute([ | ||
':user' => $uuid | ||
]); | ||
return $stmt->fetchAll(\PDO::FETCH_ASSOC); | ||
} | ||
|
||
/** | ||
* Get table name | ||
* | ||
* @return string Table name | ||
*/ | ||
public static function getTable() : string { | ||
return "mythicalclient_users_activities"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace MythicalClient\Chat\interface; | ||
|
||
class UserActivitiesTypes { | ||
public static string $login = "auth:login"; | ||
public static string $register = "auth:register"; | ||
|
||
/** | ||
* Get all types | ||
* | ||
* @return array All types | ||
*/ | ||
public static function getTypes(): array { | ||
return [ | ||
self::$login, | ||
self::$register | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters