2022-01-13 15:43:07 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* user.php
|
|
|
|
*
|
|
|
|
* A wishthis user.
|
|
|
|
*
|
|
|
|
* @author Jay Trees <github.jay@grandel.anonaddy.me>
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace wishthis;
|
|
|
|
|
|
|
|
class User
|
|
|
|
{
|
|
|
|
public int $id;
|
2022-01-18 12:23:37 +00:00
|
|
|
public int $power = 0;
|
2022-01-13 15:43:07 +00:00
|
|
|
|
|
|
|
public function __construct(int $id = -1)
|
|
|
|
{
|
|
|
|
if (-1 === $id) {
|
2022-01-18 09:51:51 +00:00
|
|
|
if (isset($_SESSION['user']['id'])) {
|
|
|
|
$this->id = $_SESSION['user']['id'];
|
|
|
|
}
|
2022-01-13 15:43:07 +00:00
|
|
|
} else {
|
|
|
|
$this->id = $id;
|
|
|
|
}
|
2022-01-18 12:23:37 +00:00
|
|
|
|
|
|
|
if (!isset($this->id)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
global $database;
|
|
|
|
|
|
|
|
$user = $database->query('SELECT * FROM `users`
|
|
|
|
WHERE `id` = ' . $this->id . ';')
|
|
|
|
->fetch();
|
|
|
|
|
|
|
|
$this->power = $user['power'];
|
2022-01-13 15:43:07 +00:00
|
|
|
}
|
|
|
|
|
2022-01-14 07:34:55 +00:00
|
|
|
/**
|
|
|
|
* Return whether the current user is logged in.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isLoggedIn(): bool
|
|
|
|
{
|
|
|
|
return isset($_SESSION['user']);
|
|
|
|
}
|
|
|
|
|
2022-01-13 15:43:07 +00:00
|
|
|
/**
|
|
|
|
* Returns a list of the users wishlists.
|
|
|
|
* Defaults to the currently logged in user.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getWishlists(): array
|
|
|
|
{
|
|
|
|
global $database;
|
|
|
|
|
|
|
|
$wishlists = $database->query(
|
|
|
|
'SELECT *
|
|
|
|
FROM wishlists
|
2022-01-14 08:28:41 +00:00
|
|
|
WHERE user = ' . $this->id . ';'
|
2022-01-13 15:43:07 +00:00
|
|
|
)->fetchAll();
|
|
|
|
|
|
|
|
return $wishlists;
|
|
|
|
}
|
2022-01-14 08:28:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a list of products for a given wishlist.
|
|
|
|
*
|
|
|
|
* @param int $wishlist
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getProducts(int $wishlist): array
|
|
|
|
{
|
|
|
|
global $database;
|
|
|
|
|
|
|
|
$products = $database->query(
|
|
|
|
'SELECT *
|
|
|
|
FROM products
|
2022-01-17 11:40:42 +00:00
|
|
|
WHERE wishlist = ' . $wishlist . ';'
|
2022-01-14 08:28:41 +00:00
|
|
|
)->fetchAll();
|
|
|
|
|
|
|
|
return $products;
|
|
|
|
}
|
2022-01-13 15:43:07 +00:00
|
|
|
}
|