Hi All!

Working on a custom module for a corporate client, and they have a drupal site with 4 blogs. As you know all content is treated as nodes, and stored in the node, node_revisions tables. They have 4 views created that separate the 4 blogs and group their posts together in the front end templates.

The module I created is a "fancy" (read: js effects) Archive block grouped by year, then by month and displays a count of the number of posts for each month.

Right now, this module does not know, nor does it separate the posts in its counts. They were happy with it, but of course they want it to work intelligently depending on which 'blog' they are looking at.

I have looked at the table schemas and can not for the life of me figure out how to group nodes the way the views do, with SQL or with the API. In other words, I want to be able to do this programmatically, As it stands now, the only way I can group them is by the user that posted the content - which is obviously a solution that will not be able to stand up to much real-world use, as their team of bloggers (a group of 7 or 8 people) can and most likely will change over time - so hard coding these values into my module is not ideal.

There's got to be a better way! I'm new to drupal, but not to PHP - get as technical as you want.

OR is there a way to output all queries at the bottom of the page? (as this would give me a little bit of an idea of how things are running under the hood).

Thanks in advance for all your input. I await your replies with bated breath.

- Eric

Comments

papile’s picture

Really you should write your own module for this. In general I do not use views although it is very good for simple things.

To see all the queries, use the devel module. It is excellent. However it is not always clear how views is doing things, as it is a rather complex module. Views is good to use for things like archives, and post display blocks, but it sounds as if you need more.

Maybe if I see what you are doing I can help out.

I would write a module with the following:
-A plugin to the /admin panel where one can create a blog, and assign one or more posters the ability to post to such blog.
-A handler like /blogs that pulls up the blog based on blog name (see page example on api.drupal.org)
-A handler like /archive that paginates and groups based on years etc

These things are all easy with drupal, but you have to learn the system. Start off by looking at the examples on api.drupal.org and start with the node example. There you can make a form, an insert function, a delete function etc.

I do not really use views anymore because for things that are going to be used a lot, you can write your own module with no limitations, and it is often a lot faster too.

xentek’s picture

Hi Papile,

Yes, I have created a module that publishes a block that does almost everything I need. My only issue is that I'm not sure how to determine which blog posts are grouped together, so that I can give accurate counts based on which of the 4 blogs you are browsing. I will take a look at the devel module - because If I can get an idea of how to group these with SQL, I will be able to do the rest - hopefully this module will give me some more insight into what is going on under the hood.

Thanks again, and keep the comments coming (everyone).

- Eric

xentek’s picture

Installed the Devel module, and now it is logging my queries. It looks as if this query is the meat of what I was looking for, so I appreciate your input!

SELECT DISTINCT(node.nid), node.created AS node_created_created FROM {node} node LEFT JOIN {term_node} term_node ON node.nid = term_node.nid LEFT JOIN {term_data} term_data ON term_node.tid = term_data.tid AND term_data.vid IN ('1') WHERE (node.status = '1') AND (term_node.tid IS NOT NULL) AND (term_data.tid IS NOT NULL) GROUP BY node.nid, node_created_created ORDER BY node_created_created DESC