Add a parameter to getBookmarks fct to get valid bookmarks only

The default value of this parameter is false, in this case all the bookmarks
are returned, otherwise only those who are related to books of the library.
This commit is contained in:
luddens 2019-09-28 21:50:19 +02:00
parent f1d55f8e86
commit c9a15c9961
2 changed files with 16 additions and 1 deletions

View File

@ -208,7 +208,7 @@ class Library
*
* @return A list of bookmarks
*/
const std::vector<kiwix::Bookmark>& getBookmarks() { return m_bookmarks; }
const std::vector<kiwix::Bookmark> getBookmarks(bool onlyValidBookmarks = true);
/**
* Get all book ids of the books in the library.

View File

@ -184,6 +184,21 @@ std::vector<std::string> Library::getBooksPublishers()
return booksPublishers;
}
const std::vector<kiwix::Bookmark> Library::getBookmarks(bool onlyValidBookmarks)
{
if (!onlyValidBookmarks) {
return m_bookmarks;
}
std::vector<kiwix::Bookmark> validBookmarks;
auto booksId = getBooksIds();
for(auto& bookmark:m_bookmarks) {
if (std::find(booksId.begin(), booksId.end(), bookmark.getBookId()) != booksId.end()) {
validBookmarks.push_back(bookmark);
}
}
return validBookmarks;
}
std::vector<std::string> Library::getBooksIds()
{
std::vector<std::string> bookIds;