Allow viewing saved wishlists
This commit is contained in:
parent
ff4c5bed2d
commit
cd909de857
4 changed files with 48 additions and 10 deletions
|
@ -18,14 +18,7 @@ switch ($_SERVER['REQUEST_METHOD']) {
|
|||
/**
|
||||
* Get
|
||||
*/
|
||||
$wishlists = $database
|
||||
->query('SELECT *
|
||||
FROM `wishlists_saved` `ws`
|
||||
JOIN `wishlists` `w` ON `w`.`id` = `ws`.`wishlist`
|
||||
WHERE `ws`.`user` = ' . $user->id . ';')
|
||||
->fetchAll();
|
||||
|
||||
$response['data'] = $wishlists;
|
||||
$response['data'] = $user->getSavedWishlists();
|
||||
break;
|
||||
|
||||
case 'POST':
|
||||
|
|
|
@ -108,7 +108,6 @@ $(function() {
|
|||
});
|
||||
});
|
||||
|
||||
|
||||
/** Determine if list is saved */
|
||||
fetch('/src/api/wishlists-saved.php', {
|
||||
method : 'GET',
|
||||
|
|
|
@ -44,7 +44,8 @@ class User
|
|||
global $database;
|
||||
|
||||
$user = $database
|
||||
->query('SELECT * FROM `users`
|
||||
->query('SELECT *
|
||||
FROM `users`
|
||||
WHERE `id` = ' . $this->id . ';')
|
||||
->fetch();
|
||||
|
||||
|
@ -81,4 +82,33 @@ class User
|
|||
|
||||
return $wishlists;
|
||||
}
|
||||
|
||||
public function getSavedWishlists(): array
|
||||
{
|
||||
global $database;
|
||||
|
||||
$wishlists = array();
|
||||
|
||||
$result = $database
|
||||
->query('SELECT `ws`.`wishlist`,
|
||||
`w`.`user`,
|
||||
`w`.`hash`
|
||||
FROM `wishlists_saved` `ws`
|
||||
JOIN `wishlists` `w` ON `w`.`id` = `ws`.`wishlist`
|
||||
WHERE `ws`.`user` = ' . $this->id . ';')
|
||||
->fetchAll();
|
||||
|
||||
if ($result) {
|
||||
$wishlists = $result;
|
||||
}
|
||||
|
||||
return $wishlists;
|
||||
}
|
||||
|
||||
public function getDisplayName(): string
|
||||
{
|
||||
return $this->name_nick
|
||||
?: $this->name_first
|
||||
?: $this->email;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,23 @@ $page->navigation();
|
|||
<h1 class="ui header"><?= $page->title ?></h1>
|
||||
|
||||
<div class="ui segment">
|
||||
<div class="ui relaxed divided list">
|
||||
|
||||
<?php foreach ($user->getSavedWishlists() as $wishlist_saved) { ?>
|
||||
<?php
|
||||
$wishlist = new Wishlist($wishlist_saved['wishlist']);
|
||||
$wishlist_user = new User($wishlist_saved['user']);
|
||||
?>
|
||||
<div class="item">
|
||||
<i class="large heart middle aligned icon"></i>
|
||||
<div class="content">
|
||||
<a class="header" href="/?wishlist=<?= $wishlist->hash ?>"><?= $wishlist->getTitle(); ?></a>
|
||||
<div class="description"><?= $wishlist_user->getDisplayName(); ?></div>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
|
Loading…
Reference in a new issue