summaryrefslogtreecommitdiff
path: root/includes/model
diff options
context:
space:
mode:
authorcflip <36554078+cflip@users.noreply.github.com>2021-04-24 09:40:20 -0600
committercflip <36554078+cflip@users.noreply.github.com>2021-04-24 09:40:20 -0600
commit7c3f2e348c015ea93563d866f89ec8cea9159ea0 (patch)
treeb7b6b18cf9087f42300f621d15101628a8d214e4 /includes/model
parent6c9369ad85f2fb3dc61234b54db7e7079cdc0c4e (diff)
Refactoring part 2
Starting to move some functionality such as the session and database connection into singleton classes to manage them. Functions for modifying posts and threads are being put in one place as well.
Diffstat (limited to 'includes/model')
-rw-r--r--includes/model/User.php36
1 files changed, 14 insertions, 22 deletions
diff --git a/includes/model/User.php b/includes/model/User.php
index 1c48afb..c780ff0 100644
--- a/includes/model/User.php
+++ b/includes/model/User.php
@@ -1,14 +1,17 @@
<?php
+include_once './includes/Database.php';
const USER_LEVEL_MODERATOR = 1;
-class User {
+class User
+{
public $id;
public $name = 'Unknown';
public $date = 0;
public $level = 0;
- function get_by_name($name, $dbc) {
+ function get_by_name($name, $dbc)
+ {
$sql = "SELECT user_id, user_date, user_level FROM users WHERE user_name = ?";
$stmt = mysqli_stmt_init($dbc);
@@ -35,25 +38,14 @@ class User {
mysqli_stmt_close($stmt);
}
- function get_by_id($id, $dbc) {
- $sql = "SELECT user_name, user_date, user_level FROM users WHERE user_id = " . mysqli_real_escape_string($dbc, $id);
- $result = mysqli_query($dbc, $sql);
-
- if (!$result) {
- echo 'Failed to get user: ' . mysqli_error($dbc);
- }
-
- if (mysqli_num_rows($result) == 0) {
- } else {
- while ($row = mysqli_fetch_assoc($result)) {
- $this->id = $id;
- $this->name = $row['user_name'];
- $this->date = $row['user_date'];
- $this->level = $row['user_level'];
- }
- }
-
- mysqli_free_result($result);
- }
+ function get_by_id($id)
+ {
+ $sql = "SELECT user_name, user_date, user_level FROM users WHERE user_id = ?;";
+ $result = Database::get()->query($sql, "i", $id);
+ $this->id = $id;
+ $this->name = $result[0]['user_name'];
+ $this->date = $result[0]['user_date'];
+ $this->level = $result[0]['user_level'];
+ }
} \ No newline at end of file