I am currently trying to re-create my flash games site to using Drupal. I have imported database tables for the categories and games I have and I now want to be able to browse the categories and play each game. When trying to write the module I am having problems getting to a page that I can display each category on. I have defined a block that displays each category but cannot link to a page to display them. This is my first attempt at a module so I obviously haven't got the concept right yet.

What I am trying to do is list the categories and display them in a block, currently hard coded them in, and then link to a node that displays the contents of the chosen category. Each member of a category will be a link to a page that displays the game, which I am pretty sure I will be able to use flashnode or swfobject for. Can I dynamically create a node for a category page i.e. no node record for it exists in db or do I have to create a generic page and pass the category name in the url and query the db from there. I am pretty sure I will have the same problem when I want to select each game but then I will need to manipulate a different type of node as well. What I would really like to do is create the node on the fly querying the db for the information I need and then display it. Or do I really have to create the node types and then go through adding each one to the system?

Any advice.

Comments

vm’s picture

When you crteate a txonomy you automagically have the ability to create listings of pages using terms see: http://drupal.org/handbook/modules/taxonomy

specifically:

Using categories in menus

The menus on your site can call for items that match specific taxonomy terms--that is, terms you’ve named your categories. Here's how.

When you create a new term, Drupal assigns it a number. And you can call up all the items categorized under that term by calling for its number.
To see your term's number, go to the categories page, choose list terms for the category to which your term belongs, and now hover over your term's name in the list. You'll see the number.
Now, on the menus page (administer >> site building >> menus) you can create a menu item for your term. Select add item, and when you fill in the path field you add your category like this:
taxonomy/term/1

If your category "sonatas" is term 1, this would call for all the nodes of that category.

If your category "Bach" is term 2, you could call for only those sonatas written by Bach:

taxonomy/term/1,2

Or if Brahms is term 3 and you want to call for everything that has to do with either Bach or Brahms, you’d do it this way:

taxonomy/term/2+3

_____________________________________________________________________
My posts & comments are usually dripping with sarcasm.
If you ask nicely I'll give you a towel : )

leonglass’s picture

I would have to have created the nodes for each item for that approach. I was thinking that I could have one generic game category node defined and then use the _load function to alter it based on the category called. My real problem is not creating the taxonomy for my games but having over three thousand games sat in the database that I can't use as I cant load a node because I have no node to get me to the _load stage.

criznach’s picture

I think that approach will short-circuit a bunch of really useful stuff that Drupal could do for you.

From what you wrote, I think you have a bunch of flash game records in a non-drupal table. Maybe another table with catgeory information.

I'd suggest something like this...

Create a custom node type using either a module or CCK that contains the fields you need, but in a Drupal-friendly way. Create a Drupal taxonomy that mirrors your categories. Write a one-time import function that iterates each of your game rows and uses node_save to put them into real Drupal nodes. Use the taxonomy functions to associate these with the Drupal taxonomy terms.

The benefits are that you can then use views, taxonomy, and a ton of other modules to jazz up your content. The method you proposed would work, but you don't get many of Drupal's cool features.

leonglass’s picture

Ok thanks that seems to make sense. Thanks

leonglass’s picture

I am trying to implement your suggestion at the moment but seem to be stumbling with the node. I do have a seperate, non-drupal, table with the games records in as you thought. To create a node for each of these do I create a new record in the node table and add the nid, vid fields to my games table? I am assuming that I don't alter the structure of the node table so I will need to alter the game table - is this the correct approach. How about the type field does that get my module name? Do I also need something to link the taxonomy to each node or do I do that later?

Thanks for your time.

leonglass’s picture

function game_install()
{
	switch($GLOBALS['db_type'])
	{
		case 'mysql':
		case 'mysqli':
			db_query(
				"CREATE TABLE {game}(
				nid int unsigned NOT NULL default '0',
				vid int unsigned NOT NULL default '0',
				description text NOT NULL,
				url text NOT NULL,
				width int unsigned NOT NULL default '0',
				height int unsigned NOT NULL default '0',
				PRIMARY KEY (nid, vid),
				UNIQUE KEY vid (vid),
				KEY nid (nid))");
			break;
	}
}

I currently have the above code in a file named game.install but drupal doesn't seem to know it's there. I have followed instructions and have the .info .module and .install file for the game module. I can definitely prove that the other two files are being found and used but this function never seems to be called. I have the devel module enabled and there is no record for a create after I have enabled the module. I have typed the query into mysql, only removing the brackets around game, and the table is created so I think the sql is ok.

Could someone tell me what I have done wrong.

Drupal 5.3
Mysql 5.0.44
Apache 5.25

Thanks.

leonglass’s picture

The last line
KEY nid (nid))");
needed a space before that second closing brace.
KEY nid (nid) )");

polesk’s picture

first day using drupal. will someone explain how i can incorporate games with a little more detail?

thanks