fix: unable to fetch saved wishlists

This commit is contained in:
grandeljay 2023-08-31 15:03:48 +02:00
parent d8e8491a18
commit f449570627
5 changed files with 52 additions and 6 deletions

View file

@ -45,7 +45,7 @@ switch ($_SERVER['REQUEST_METHOD']) {
/**
* Get wishes by priority
*/
$wishlist = new Wishlist($_GET['wishlist_id']);
$wishlist = Wishlist::getFromId($_GET['wishlist_id']);
$options = array(
'style' => $_GET['wishlist_style'],
);

View file

@ -111,7 +111,7 @@ switch ($_SERVER['REQUEST_METHOD']) {
/**
* Get wishlist cards with priority
*/
$wishlist = new Wishlist($_GET['wishlist_id']);
$wishlist = Wishlist::getFromId($_GET['wishlist_id']);
$options = array(
'style' => $_GET['style'],
'placeholders' => array(),
@ -135,7 +135,7 @@ switch ($_SERVER['REQUEST_METHOD']) {
/**
* Get wishlist by id
*/
$wishlist = new Wishlist($_GET['wishlist_id']);
$wishlist = Wishlist::getFromId($_GET['wishlist_id']);
if ($wishlist->exists) {
/** Determine if user is allowed to access wishlist */
@ -151,7 +151,7 @@ switch ($_SERVER['REQUEST_METHOD']) {
/**
* Get wishlist by hash
*/
$wishlist = new Wishlist($_GET['wishlist_hash']);
$wishlist = Wishlist::getFromHash($_GET['wishlist_hash']);
if ($wishlist->exists) {
$response['results'] = $wishlist;

View file

@ -10,6 +10,52 @@ namespace wishthis;
class Wishlist
{
public static function getFromId(int $id): self|false
{
global $database;
$wishlistQuery = $database->query(
'SELECT *
FROM `wishlists`
WHERE `wishlists`.`id` = :wishlist_id',
array(
'wishlist_id' => $id,
)
);
if (false === $wishlistQuery) {
return false;
}
$wishlistData = $wishlistQuery->fetch();
$wishlist = new Wishlist($wishlistData);
return $wishlist;
}
public static function getFromHash(string $hash): self
{
global $database;
$wishlistQuery = $database->query(
'SELECT *
FROM `wishlists`
WHERE `wishlists`.`hash` = :wishlist_hash',
array(
'wishlist_hash' => $hash,
)
);
if (false === $wishlistQuery) {
return false;
}
$wishlistData = $wishlistQuery->fetch();
$wishlist = new Wishlist($wishlistData);
return $wishlist;
}
/**
* The unique wishlist id.
*

View file

@ -8,7 +8,7 @@
namespace wishthis;
$wishlist = new Wishlist($_GET['hash']);
$wishlist = Wishlist::getFromHash($_GET['hash']);
$wishlist_user = User::getFromID($wishlist->user);
$page = new Page(__FILE__, $wishlist->getTitle());
$page->stylesheets['wish'] = 'src/assets/css/wish.css';

View file

@ -37,7 +37,7 @@ foreach ($wishlists as $wishlist_saved) {
<div class="ui four column doubling stackable grid wishlists-saved">
<?php foreach ($wishlists_saved as $wishlist_saved) { ?>
<?php
$wishlist = new Wishlist($wishlist_saved['wishlist']);
$wishlist = Wishlist::getFromId($wishlist_saved['wishlist']);
$wishlist_href = Page::PAGE_WISHLIST . '&hash=' . $wishlist->hash;
?>