Begin dynamic content generators
This commit is contained in:
43
dynamic/dynamiccontentpostlist.cpp
Normal file
43
dynamic/dynamiccontentpostlist.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <chrono>
|
||||
#include "dynamiccontentpostlist.h"
|
||||
|
||||
void DynamicContentPostList::setCategory(std::string catname)
|
||||
{
|
||||
this->catname = catname;
|
||||
}
|
||||
|
||||
std::string DynamicContentPostList::render()
|
||||
{
|
||||
auto categoryDao = this->database->createCategoryDao();
|
||||
auto pageDao = this->database->createPageDao();
|
||||
auto revisionDao = this->database->createRevisionDao();
|
||||
QueryOption option;
|
||||
auto members = categoryDao->fetchMembers(this->catname, option);
|
||||
std::vector<std::pair<std::string, time_t>> pageList;
|
||||
for(std::string &member : members)
|
||||
{
|
||||
auto revision = revisionDao->getRevisionForPage(member, 1);
|
||||
pageList.push_back({member, revision->timestamp});
|
||||
}
|
||||
std::sort(pageList.begin(), pageList.end(),
|
||||
[](std::pair<std::string, time_t> &a, std::pair<std::string, time_t> &b) { return a.second > b.second; });
|
||||
|
||||
std::string postListBegin = this->templ->loadResolvedPart("dynamic/postlistbegin");
|
||||
std::string postListEnd = this->templ->loadResolvedPart("dynamic/postlistend");
|
||||
std::string postLink = this->templ->loadResolvedPart("dynamic/postlistlink");
|
||||
std::stringstream stream;
|
||||
stream << postListBegin;
|
||||
for(auto &pair : pageList)
|
||||
{
|
||||
std::string link = this->urlProvider->page(pair.first);
|
||||
std::string date = utils::toISODate(pair.second);
|
||||
Varreplacer replacer{"{"};
|
||||
replacer.addKeyValue("url", link);
|
||||
replacer.addKeyValue("date", date);
|
||||
replacer.addKeyValue("page", pair.first);
|
||||
|
||||
stream << replacer.parse(postLink);
|
||||
}
|
||||
stream << postListEnd;
|
||||
return stream.str();
|
||||
}
|
Reference in New Issue
Block a user