1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
/*
* Copyright (C) 2009 Emweb bvba, Kessel-Lo, Belgium.
*
* See the LICENSE file for terms of use.
*/
#include <boost/lexical_cast.hpp>
#include "Post.h"
#include "Comment.h"
#include "User.h"
#include "Tag.h"
#include <Wt/Dbo/Impl>
DBO_INSTANTIATE_TEMPLATES(Post);
std::string Post::permaLink() const
{
return date.toString("yyyy/MM/dd/'" + titleToUrl() + '\'').toUTF8();
}
std::string Post::commentCount() const
{
int count = comments.size() - 1;
if (count == 1)
return "1 comment";
else
return boost::lexical_cast<std::string>(count) + " comments";
}
dbo::ptr<Comment> Post::rootComment() const
{
if (session())
return session()->find<Comment>
("where post_id = ? and parent_id is null").bind(id());
else
return dbo::ptr<Comment>();
}
std::string Post::titleToUrl() const
{
std::string result = title.narrow();
for (unsigned i = 0; i < result.length(); ++i) {
if (!isalnum(result[i]))
result[i] = '_';
else
result[i] = tolower(result[i]);
}
return result;
}
|