Zine Data Structure

E-Zines are comprised of articles organized into hierarchical trees. Each article has a class, which determines where in the tree it is expected to appear. Each article also has a type, which is more specific than the class for zines. (For articles, comments, and attachments, the type and class are equivalent.) The zine type determines general formatting and indexing rules for associated articles. The various types are:

TypeClassNotes
e-zinezine Holds articles by various authors, which eventually expire into the archives as they are replaced by newer articles.
bookzine Holds an ordered set of articles that collectively comprise a single work. Articles do not expire.
forumzine Holds ongoing commentary from the readership.
newszine Holds articles which eventually expire into the archives as they are replaced by newer articles. Authors are usually not noted.
blogzine Holds articles by a single author, which eventually expire into the archives. Analogous to a magazine column, or an online diary.
wikizine Holds articles by various authors, which can be cross-linked, and which the readers can contribute to.
photoblogzine Similar to a blog, but emphasizes the image content over the text content.
regular articlearticle These are the individual stories/posts that readers are consuming.
commentcomment Readers can append their own thoughts to particular articles or forums.
attachmentattachment These are images or other files that are connected to zines, articles, or comments.

Article Trees

The rules for how articles in the overall tree are allowed to nest under each other are:

It may be possible to configure article relationships to break these rules, but in that case there is no assurance of the misconfigured articles being found and displayed by the system.

Each article has a parent article, which is the next article higher in the tree. To build a tree object from an array of articles, use this:

my $tree = new ExSite::Tree(
                            "article_id",    # primary key
			    "parent_id",     # parent key
			    @articles        # tree nodes
			    );

In principle the entire tree can be defined and constructed using only the parent reference. However, this makes for inefficient and recursive queries to retrieve the data needed to build the tree. To allow for simpler and more efficient queries, we also track each article's thread and reference.

The thread is the highest-level article of the same class. If the current article is the highest-level article of the same class, then the thread is not set (ie. it is set to 0).

The reference is used to group related articles. For comments and articles, the reference is the lowest-level article of a different class above it in the tree. A record with no reference is at the top level of the tree.

Attachments have the same thread and reference as the article they are attached to. This makes it easier to select article and their attachments together in a single query.

For example, consider a single branch of the article tree that nests as follows:

The following relationships hold true:

ArticleParentThreadReference
Z1n/an/an/a
Z2Z1Z1Z1
A1Z2n/aZ2
A2A1A1Z2
C1A1n/aA2
C2C1C1A2
C3C2C1A2
Att1C3n/aA2

Examples

To build a complete index of articles and their comments under a particular zine, while ignoring all other zines, select all records whose reference points to the zine of interest:

# construct a tree of everything in Z2
my @articles = $db->fetch_match("article",{reference=>$z2});
my $tree = new ExSite::Tree("article_id","parent_id",@articles);

To fetch a list of threads (ie. top-level comments) in a forum, select all comments whose reference is the forum, and whose thread is not set:

my @articles = $db->fetch_match("article",{type=>"comment",reference=>$forum_id,thread=>0});

To fetch a complete thread from a discussion, select all articles of a given thread:

# fetches all articles under the top-level article
my @articles = $db->fetch_match("article",{type=>"comment",thread=>$thread_id});
# fetches all articles including the top-level article
my @articles = $db->fetch_match("article","type=\"comment\" and (article_id=$thread_id or thread=$thread_id");
my $tree = new ExSite::Tree("article_id","parent_id",@articles);