Add request more wishes button
This commit is contained in:
parent
6ab27e3cd0
commit
5c6b5a0b72
6 changed files with 203 additions and 7 deletions
|
@ -17,10 +17,10 @@ require '../../index.php';
|
|||
|
||||
switch ($_SERVER['REQUEST_METHOD']) {
|
||||
case 'POST':
|
||||
if (isset($_POST['wishlist-name'], $_SESSION['user']['id'])) {
|
||||
/**
|
||||
* Create
|
||||
*/
|
||||
if (isset($_POST['wishlist-name'], $_SESSION['user']['id'])) {
|
||||
$database->query('INSERT INTO `wishlists`
|
||||
(
|
||||
`user`,
|
||||
|
@ -36,6 +36,68 @@ switch ($_SERVER['REQUEST_METHOD']) {
|
|||
$response['data'] = array(
|
||||
'lastInsertId' => $database->lastInsertId(),
|
||||
);
|
||||
} elseif (isset($_POST['wishlist-id'])) {
|
||||
/**
|
||||
* Request more wishes
|
||||
*/
|
||||
$wishlistID = $_POST['wishlist-id'];
|
||||
|
||||
/** Get last notification time */
|
||||
$wishlistQuery = $database
|
||||
->query(
|
||||
'SELECT *
|
||||
FROM `wishlists`
|
||||
WHERE `id` = ' . $wishlistID . '
|
||||
AND (`notification_sent` < UNIX_TIMESTAMP(CURRENT_TIMESTAMP - INTERVAL 1 DAY) OR `notification_sent` IS NULL);'
|
||||
);
|
||||
|
||||
$wishlist = $wishlistQuery->fetch();
|
||||
|
||||
/** Set notification time */
|
||||
if (false !== $wishlist) {
|
||||
/** Send email */
|
||||
$mjml = file_get_contents(ROOT . '/src/mjml/wishlist-request-wishes.mjml');
|
||||
$mjml = str_replace(
|
||||
'TEXT_HELLO',
|
||||
__('Hello,'),
|
||||
$mjml
|
||||
);
|
||||
$mjml = str_replace(
|
||||
'TEXT_WISHLIST_REQUEST_WISHES',
|
||||
sprintf(
|
||||
/** TRANSLATORS: %s: Wishlist name */
|
||||
__('somebody has requested that you add more wishes to your wishlist %s.'),
|
||||
'<a href="https://wishthis.online/?page=wishlists&id=' . $wishlist['id'] . '">' . $wishlist['name'] . '</a>'
|
||||
),
|
||||
$mjml
|
||||
);
|
||||
$mjml = str_replace(
|
||||
'TEXT_WISH_ADD',
|
||||
__('Add wish'),
|
||||
$mjml
|
||||
);
|
||||
$mjml = str_replace(
|
||||
'LINK_WISH_ADD',
|
||||
$_SERVER['REQUEST_SCHEME'] . '://' .
|
||||
$_SERVER['HTTP_HOST'] .
|
||||
Page::PAGE_WISHLISTS . '&id=' . $wishlist['id'] . '&wish_add=true',
|
||||
$mjml
|
||||
);
|
||||
|
||||
$emailRequest = new Email($user->email, __('Wish request'), $mjml);
|
||||
$emailRequest->send();
|
||||
|
||||
/** Save date to database */
|
||||
$database
|
||||
->query(
|
||||
'UPDATE `wishlists`
|
||||
SET `notification_sent` = CURRENT_TIMESTAMP
|
||||
WHERE `id` = ' . $wishlist['id'] . ';'
|
||||
);
|
||||
}
|
||||
|
||||
$response['success'] = true;
|
||||
$response['email_was_sent'] = false !== $wishlist;
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
@ -140,4 +140,36 @@ $(function() {
|
|||
buttonSave.find('span').text(text.button_wishlist_saved);
|
||||
}
|
||||
|
||||
/**
|
||||
* Request more wishes
|
||||
*/
|
||||
$(document).on('click', '.ui.button.wishlist-request-wishes', function() {
|
||||
var buttonRequest = $(this);
|
||||
var wishlist_id = $('.wishlist-cards[data-wishlist]').attr('data-wishlist');
|
||||
|
||||
var formData = new URLSearchParams({
|
||||
'wishlist-id' : wishlist_id,
|
||||
});
|
||||
|
||||
buttonRequest.addClass('disabled loading');
|
||||
|
||||
fetch('/src/api/wishlists.php', {
|
||||
method : 'POST',
|
||||
body : formData
|
||||
})
|
||||
.then(handleFetchError)
|
||||
.then(handleFetchResponse)
|
||||
.then(function(response) {
|
||||
if (response.email_was_sent) {
|
||||
$('.modal.wishlist-request-wishes-notification-sent').modal('show');
|
||||
} else {
|
||||
$('.modal.wishlist-request-wishes-notification-notsent').modal('show');
|
||||
}
|
||||
})
|
||||
.catch(handleFetchCatch)
|
||||
.finally(function() {
|
||||
buttonRequest.removeClass('loading');
|
||||
});;
|
||||
});
|
||||
|
||||
});
|
||||
|
|
58
src/mjml/wishlist-request-wishes.mjml
Normal file
58
src/mjml/wishlist-request-wishes.mjml
Normal file
|
@ -0,0 +1,58 @@
|
|||
<mjml>
|
||||
<mj-head>
|
||||
<mj-attributes>
|
||||
<mj-all font-family="Raleway, sans-serif"
|
||||
font-size="12pt"
|
||||
/>
|
||||
<mj-body background-color="#f4f4f4" />
|
||||
<mj-text line-height="1.6" />
|
||||
<mj-button align="left"
|
||||
background-color="#6435c9"
|
||||
font-weight="700"
|
||||
/>
|
||||
|
||||
<mj-class name="segment"
|
||||
background-color="#fff"
|
||||
border="1px solid rgba(34,36,38,.15)"
|
||||
/>
|
||||
</mj-attributes>
|
||||
|
||||
<mj-font name="Raleway" href="https://fonts.googleapis.com/css?family=Raleway" />
|
||||
|
||||
<mj-style>
|
||||
a {
|
||||
color: #6435c9;
|
||||
}
|
||||
.segment {
|
||||
box-shadow: 0 1px 2px 0 rgba(34,36,38,.15);
|
||||
}
|
||||
</mj-style>
|
||||
</mj-head>
|
||||
<mj-body>
|
||||
<mj-section><mj-column></mj-column></mj-section>
|
||||
|
||||
<mj-section>
|
||||
<mj-column>
|
||||
<mj-image src="https://wishthis.online/src/assets/img/logo.svg"
|
||||
alt="wishthis"
|
||||
height="28px"
|
||||
align="left"
|
||||
/>
|
||||
</mj-column>
|
||||
</mj-section>
|
||||
|
||||
<mj-section mj-class="segment" css-class="segment">
|
||||
<mj-column>
|
||||
|
||||
<mj-text>TEXT_HELLO</mj-text>
|
||||
|
||||
<mj-text>TEXT_WISHLIST_REQUEST_WISHES</mj-text>
|
||||
|
||||
<mj-button href="LINK_WISH_ADD">TEXT_WISH_ADD</mj-button>
|
||||
|
||||
</mj-column>
|
||||
</mj-section>
|
||||
|
||||
<mj-section><mj-column></mj-column></mj-section>
|
||||
</mj-body>
|
||||
</mjml>
|
|
@ -154,6 +154,7 @@ switch ($step) {
|
|||
`user` INT NOT NULL,
|
||||
`name` VARCHAR(128) NOT NULL,
|
||||
`hash` VARCHAR(128) NOT NULL,
|
||||
`notification_sent` TIMESTAMP NULL DEFAULT NULL,
|
||||
|
||||
INDEX `idx_hash` (`hash`),
|
||||
CONSTRAINT `FK_wishlists_user` FOREIGN KEY (`user`) REFERENCES `users` (`id`) ON DELETE CASCADE
|
||||
|
|
|
@ -86,9 +86,47 @@ $page->navigation();
|
|||
?>
|
||||
</div>
|
||||
|
||||
<div class="ui basic center aligned segment">
|
||||
<button class="ui primary button wishlist-request-wishes">
|
||||
<?= __('Request more wishes') ?>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<?php
|
||||
$page->bodyEnd();
|
||||
?>
|
||||
|
||||
<!-- Wishlist: Request wishes -->
|
||||
<div class="ui tiny modal wishlist-request-wishes-notification-sent">
|
||||
<div class="header">
|
||||
<?= __('Request more wishes') ?>
|
||||
</div>
|
||||
<div class="content">
|
||||
<div class="description">
|
||||
<p><?= __('A notification has just been sent to the owner of this wishlist.') ?></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<div class="ui approve primary button" title="<?= __('Ok') ?>">
|
||||
<?= __('Ok') ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui tiny modal wishlist-request-wishes-notification-notsent">
|
||||
<div class="header">
|
||||
<?= __('Request more wishes') ?>
|
||||
</div>
|
||||
<div class="content">
|
||||
<div class="description">
|
||||
<p><?= __('The wishlist owner has already received a notification recently and has not been notified again.') ?></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<div class="ui approve primary button" title="<?= __('Ok') ?>">
|
||||
<?= __('Ok') ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
/**
|
||||
* Wishlists
|
||||
*/
|
||||
ALTER TABLE `wishlists` ADD COLUMN `notification_sent` TIMESTAMP NULL DEFAULT NULL;
|
||||
|
||||
/**
|
||||
* Wishes
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue