fix: unable to fetch saved wishlists
This commit is contained in:
parent
d8e8491a18
commit
f449570627
5 changed files with 52 additions and 6 deletions
|
@ -45,7 +45,7 @@ switch ($_SERVER['REQUEST_METHOD']) {
|
||||||
/**
|
/**
|
||||||
* Get wishes by priority
|
* Get wishes by priority
|
||||||
*/
|
*/
|
||||||
$wishlist = new Wishlist($_GET['wishlist_id']);
|
$wishlist = Wishlist::getFromId($_GET['wishlist_id']);
|
||||||
$options = array(
|
$options = array(
|
||||||
'style' => $_GET['wishlist_style'],
|
'style' => $_GET['wishlist_style'],
|
||||||
);
|
);
|
||||||
|
|
|
@ -111,7 +111,7 @@ switch ($_SERVER['REQUEST_METHOD']) {
|
||||||
/**
|
/**
|
||||||
* Get wishlist cards with priority
|
* Get wishlist cards with priority
|
||||||
*/
|
*/
|
||||||
$wishlist = new Wishlist($_GET['wishlist_id']);
|
$wishlist = Wishlist::getFromId($_GET['wishlist_id']);
|
||||||
$options = array(
|
$options = array(
|
||||||
'style' => $_GET['style'],
|
'style' => $_GET['style'],
|
||||||
'placeholders' => array(),
|
'placeholders' => array(),
|
||||||
|
@ -135,7 +135,7 @@ switch ($_SERVER['REQUEST_METHOD']) {
|
||||||
/**
|
/**
|
||||||
* Get wishlist by id
|
* Get wishlist by id
|
||||||
*/
|
*/
|
||||||
$wishlist = new Wishlist($_GET['wishlist_id']);
|
$wishlist = Wishlist::getFromId($_GET['wishlist_id']);
|
||||||
|
|
||||||
if ($wishlist->exists) {
|
if ($wishlist->exists) {
|
||||||
/** Determine if user is allowed to access wishlist */
|
/** Determine if user is allowed to access wishlist */
|
||||||
|
@ -151,7 +151,7 @@ switch ($_SERVER['REQUEST_METHOD']) {
|
||||||
/**
|
/**
|
||||||
* Get wishlist by hash
|
* Get wishlist by hash
|
||||||
*/
|
*/
|
||||||
$wishlist = new Wishlist($_GET['wishlist_hash']);
|
$wishlist = Wishlist::getFromHash($_GET['wishlist_hash']);
|
||||||
|
|
||||||
if ($wishlist->exists) {
|
if ($wishlist->exists) {
|
||||||
$response['results'] = $wishlist;
|
$response['results'] = $wishlist;
|
||||||
|
|
|
@ -10,6 +10,52 @@ namespace wishthis;
|
||||||
|
|
||||||
class Wishlist
|
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.
|
* The unique wishlist id.
|
||||||
*
|
*
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
namespace wishthis;
|
namespace wishthis;
|
||||||
|
|
||||||
$wishlist = new Wishlist($_GET['hash']);
|
$wishlist = Wishlist::getFromHash($_GET['hash']);
|
||||||
$wishlist_user = User::getFromID($wishlist->user);
|
$wishlist_user = User::getFromID($wishlist->user);
|
||||||
$page = new Page(__FILE__, $wishlist->getTitle());
|
$page = new Page(__FILE__, $wishlist->getTitle());
|
||||||
$page->stylesheets['wish'] = 'src/assets/css/wish.css';
|
$page->stylesheets['wish'] = 'src/assets/css/wish.css';
|
||||||
|
|
|
@ -37,7 +37,7 @@ foreach ($wishlists as $wishlist_saved) {
|
||||||
<div class="ui four column doubling stackable grid wishlists-saved">
|
<div class="ui four column doubling stackable grid wishlists-saved">
|
||||||
<?php foreach ($wishlists_saved as $wishlist_saved) { ?>
|
<?php foreach ($wishlists_saved as $wishlist_saved) { ?>
|
||||||
<?php
|
<?php
|
||||||
$wishlist = new Wishlist($wishlist_saved['wishlist']);
|
$wishlist = Wishlist::getFromId($wishlist_saved['wishlist']);
|
||||||
$wishlist_href = Page::PAGE_WISHLIST . '&hash=' . $wishlist->hash;
|
$wishlist_href = Page::PAGE_WISHLIST . '&hash=' . $wishlist->hash;
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue