Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
feat(Torrents): Allow search in user's favour (or you can say bookmark)
Browse files Browse the repository at this point in the history
1. Allow search in user's favour (or you can say bookmark)
2. Add function removeCacheValue for class \Rid\Utils\ClassValueCacheUtils
  • Loading branch information
Rhilip committed Feb 25, 2020
1 parent 6da82a7 commit c0aa627
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
- **Cron:** Fix components lost in CronTabProcess (1ced4bf)
- **Redis:** Fix wrong type of Redis call function hMset() to hMSet() (a163150)
- **Response:** Fix Response header and status not clean (82977ea)
- **Response:** Fix Header `Set-Cookie` header don't clean (144eef7)
- **Route:** Fix user can access maintenance page even not on maintenance status (b29c2f6)
- **Tracker:** Fix typo in TrackerController (323c8ec)
- **Tracker:** Disable `retry in` feature by default (4b1f767)
Expand Down
5 changes: 5 additions & 0 deletions application/Entity/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,11 @@ public function getInvitees()
});
}

public function updateBookmarkList() {
$this->removeCacheValue('bookmark_list');
$this->getBookmarkList();
}

public function getBookmarkList()
{
return $this->getCacheValue('bookmark_list', function () {
Expand Down
4 changes: 2 additions & 2 deletions application/Models/Api/v1/Form/TorrentsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ public function updateRecord()
app()->pdo->prepare('DELETE FROM `bookmarks` WHERE `id` = :bid')->bindParams([
'bid' => $bookmark_exist
])->execute();
app()->redis->del('User:' . app()->auth->getCurUser()->getId() . ':bookmark_array');
app()->auth->getCurUser()->updateBookmarkList();

return ['msg' => 'Delete Old Bookmark Success', 'result' => 'deleted'];
} else { // Add new record
app()->pdo->prepare('INSERT INTO `bookmarks` (`uid`, `tid`) VALUES (:uid, :tid)')->bindParams([
'uid' => app()->auth->getCurUser()->getId(),
'tid' => $this->getInput('id')
])->execute();
app()->redis->del('User:' . app()->auth->getCurUser()->getId() . ':bookmark_array');
app()->auth->getCurUser()->updateBookmarkList();

return ['msg' => 'Add New Bookmark Success', 'result' => 'added'];
}
Expand Down
8 changes: 8 additions & 0 deletions application/Models/Form/Torrents/SearchForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ private function getSearchField(): array
}
}

// Favour
$favour = $this->getInput('favour');
if ($favour == 1) { // bookmarked in favour
$fields[] = ['AND `id` IN (SELECT `tid` FROM `bookmarks` WHERE `uid` = :uid)', 'params' => ['uid' => app()->auth->getCurUser()->getId()]];
} elseif ($favour == 2) { // not bookmarked in favour
$fields[] = ['AND `id` NOT IN (SELECT `tid` FROM `bookmarks` WHERE `uid` = :uid)', 'params' => ['uid' => app()->auth->getCurUser()->getId()]];
}

// TODO we may not use `&search_area=` to search in non-title/subtitle/descr field, Use sep `&ownerid=` , `&doubanid=` instead.

$searchstr = $this->getInput('search');
Expand Down
5 changes: 5 additions & 0 deletions framework/Utils/ClassValueCacheUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@ final protected function getCacheValue($key, $closure)
}
return $this->$key;
}

final protected function removeCacheValue($key) {
unset($this->$key);
app()->redis->hDel($this->getCacheNameSpace(), $key);
}
}
2 changes: 1 addition & 1 deletion templates/helper/torrent_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</tr>
</thead>
<tbody>
<?php foreach ($search->getPagerData() as $torrent): /** @var \App\Entity\Torrent $torrent */ ?>
<?php foreach ($search->getPagerData() as $torrent): /** @var \App\Entity\Torrent\Torrent $torrent */ ?>
<tr data-tid="<?= $torrent->getId() ?>">
<td class="text-center" data-item="category" style="margin: 0;padding: 0">
<?php $cat = $torrent->getCategory(); ?>
Expand Down
2 changes: 1 addition & 1 deletion templates/layout/nav_user.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<?php if ($user->getClass() > UserRole::FORUM_MODERATOR): ?>
<span><!--suppress HtmlUnknownTarget -->[<a href="/admin">Admin Panel</a>]</span>
<?php endif; ?>
<span data-item="favour"><!--suppress HtmlUnknownTarget -->[<a href="/torrents/favour">Favour</a>]</span>
<span data-item="favour"><!--suppress HtmlUnknownTarget -->[<a href="/torrents?favour=1">Favour</a>]</span>
<span data-item="invite" data-invite="<?= $user->getInvites() ?>" data-temp-invite="<?= $user->getTempInvitesSum() ?>">
<span class="color-invite">Invite [<a href="/user/invite">Send</a>]: </span> <?= $user->getInvites() ?>
<?php if ($user->getTempInvitesSum() > 0): ?>
Expand Down

0 comments on commit c0aa627

Please sign in to comment.