#1 April 5, 2012 3:44am

philp
Member
Registered: April 5, 2012
Posts: 25

Mixing different types of content

First of all, quickly wanted to say how impressive Bigtree looks — very elegant and intuitive feel to the design, and hoping that follows through to the code.


I'm starting to evaluate Bigtree to see whether it could be used on a couple of upcoming projects, and just trying to get an idea of how flexible it is to create different types of content, and then have them mixed up. One of the projects we're working on is kind of tumblr-like, with a number of different project pages which can include posts of different types: news, video, image galleries, quotes etc.


Just wondering if you were able to give an indication of how easy this would be to achieve with Bigtree?

Offline

#2 April 5, 2012 12:48pm

curt
Administrator
Registered: March 30, 2012
Posts: 7

Re: Mixing different types of content

I think BigTree will excel at managing the type of system you described. It sounds to me like you would want to run the core "tumblr-like" content off of a single module. You could design the module entries a couple of different ways.

The easier to code, but harder to maintain method would be to make simple blog-like module entries that have a single HTML content field and handle the media through html embeds.

The more elegant method would be to design a module that has a separate field for each media type. There are built in field types to handle news (html text), image galleries (photo gallery), quotes (text and text areas) and the ones that don't exist would be easy to make (read about custom field types at the bottom of this article). For video I would probably just store a youtube or vimeo ID in a textfield and then do the heavy lifting of constructing the embed in the template code. This method would normalize the input and allow you to sort and categorize based on the existence of content types rather than having to manually categorize the post based on the content it contains.

Regardless of which method you use for the module, you will probably want to power the front end with a single routed template. With a routed template you can construct routes based on post categories, post titles etc... to serve the results of various queries without being tied to a physical page tree structure.
I would definitely poke around the example site, it makes use of techniques you will find useful like routed templates, generating url slugs for module entries, etc.

I hope you find this response helpful, as always if you get stuck or we are missing something in the documentation ask away.

Offline

#3 April 12, 2012 5:11am

philp
Member
Registered: April 5, 2012
Posts: 25

Re: Mixing different types of content

Thanks for the pointers — really useful.


Ideally, I'd like to be able to create modules for each type of content (Video, Image Gallery, Post) with specific fields for each. Then, each of those modules will need to reference a Category module.


I think I should be able to do that quite nicely using modules which use M2M relationships (every content type references a common Category module). I think the only tricky thing could be referencing and ordering all of the different content types for a particular category.

Offline

#4 April 12, 2012 8:39am

benplum
Administrator
Registered: March 30, 2012
Posts: 54

Re: Mixing different types of content

This can be achieved one of two ways. Both will require a single relation table with a column for the category as well as one for each type of content. Set up each module to use the same relation table for it's many-to-many. Now we can get into the nitty gritty.

The first way to get the desired result is to query the relation table for all rows containing the category. Then loop through each relation row querying for the correct post:

function getMedia($category) {
	$cat_rels = array();
	$cat_q = $this->sqlquery("SELECT * FROM `media_categories_rel` WHERE category = " . $category . " ORDER BY id DESC");
	while ($f = sqlfetch($cat_rels)) {
		$cat_rels[] = $f;
	}
	
	$return_media = array();
	foreach ($cat_rels as $rel) {
		if (is_int($rel["video"])) {
			$return_media[] = $this->get(sqlfetch(sqlquery("SELECT * FROM `media_videos` WHERE id = " . $rel["video"] . " LIMIT 1")));
		} else if (is_int($rel["post"])) {
			$return_media[] = $this->get(sqlfetch(sqlquery("SELECT * FROM `media_posts` WHERE id = " . $rel["post"] . " LIMIT 1")));
		} else if (is_int($rel["gallery"])) {
			$return_media[] = $this->get(sqlfetch(sqlquery("SELECT * FROM `media_galleries` WHERE id = " . $rel["gallery"] . " LIMIT 1")));
		}
	}
	
	return $return_media;
}

This method might require a different sorting method depending on how the data is input.

The second and more efficient way is to write a nice big query to fetch everything at once:

function getMedia($category) {
	$query = sqlquery("SELECT posts.* FROM (
						(SELECT v.* FROM `media_videos` AS v, `media_categories_rel` AS rel WHERE v.id = rel.video AND rel.category = '" . $category . "' ORDER BY v.date DESC)
						UNION ALL
						(SELECT p.* FROM `media_posts` AS p, `media_categories_rel` AS rel WHERE p.id = rel.post AND rel.category = '" . $category . "' ORDER BY p.date DESC)
						UNION ALL
						(SELECT g.* FROM `media_galleries` AS g, `media_categories_rel` AS rel WHERE g.id = rel.gallery AND rel.category = '" . $category . "' ORDER BY g.date DESC)
					   ) AS posts
					   ORDER BY posts.date DESC LIMIT 10");
	
	$return_media = array();
	while ($fetch = sqlfetch($query)) {
		$return_media[] = $this->get($fetch);
	}
	
	return $return_media;
}

Both methods should be functions of a custom module class so they can make use of the function [url=http://www.bigtreecms.org/docs/code/core/BigTreeModule/#get]get(), ensuring all internal page links and json-encoded resources are properly translated. They are both also heavily reliant on direct SQL queries, so remember to clean any inputs.

Offline

#5 April 12, 2012 3:38pm

philp
Member
Registered: April 5, 2012
Posts: 25

Re: Mixing different types of content

Thanks so much for this in-depth reply — is going to prove really, really useful in getting things up and running.

Offline

Board footer

Powered by FluxBB

The Discussion Forum is not available on displays of this size.