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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
// This may look like C code, but it's really -*- C++ -*-
/*
* Copyright (C) 2009 Emweb bvba, Kessel-Lo, Belgium.
*
* See the LICENSE file for terms of use.
*/
#ifndef POST_H_
#define POST_H_
#include <Wt/WDate>
#include <Wt/WString>
#include <Wt/Dbo/Types>
#include <Wt/Dbo/WtSqlTraits>
class Comment;
class Tag;
class User;
namespace dbo = Wt::Dbo;
typedef dbo::collection< dbo::ptr<Comment> > Comments;
typedef dbo::collection< dbo::ptr<Tag> > Tags;
class Post : public dbo::Dbo {
public:
enum State {
Unpublished = 0,
Published = 1
};
dbo::ptr<User> author;
State state;
Wt::WDateTime date;
Wt::WString title;
Wt::WString briefSrc;
Wt::WString briefHtml;
Wt::WString bodySrc;
Wt::WString bodyHtml;
Comments comments;
Tags tags;
std::string permaLink() const;
std::string commentCount() const;
dbo::ptr<Comment> rootComment() const;
std::string titleToUrl() const;
template<class Action>
void persist(Action& a)
{
dbo::field(a, state, "state");
dbo::field(a, date, "date");
dbo::field(a, title, "title");
dbo::field(a, briefSrc, "brief_src");
dbo::field(a, briefHtml, "brief_html");
dbo::field(a, bodySrc, "body_src");
dbo::field(a, bodyHtml, "body_html");
dbo::belongsTo(a, author, "author");
dbo::hasMany(a, comments, dbo::ManyToOne, "post");
dbo::hasMany(a, tags, dbo::ManyToMany, "post_tag");
}
};
DBO_EXTERN_TEMPLATES(Post);
#endif // POST_H_
|