Sort nodes based on calculated score from CCK contents

faunapolis - June 25, 2007 - 13:07

Hi,

I have nodes made with the CCK (content construction kit) module that will have numerical values. I want to:

- Filter these nodes using one of the values (date)
- Sort the remaining nodes using a calculated value (a score, an average of several of the other values in the node)
- Display using Contemplate [Content Templates (Contemplate)]

What should be my strategy here? Will maybe using Dript (lisp module for Drupal) a solution?

...

mooffie - June 26, 2007 - 06:21

Filter these nodes using one of the values (date)

Use the Views module. It can filter by fields.

You can postpone reading the rest of this message till you acquaint yourself with Views.

Sort the remaining nodes using a calculated value (a score, an average of several of the other values in the node)

I see two options here.

Views can only sort in the SQL level. (Well, It's possible to sort using PHP if you're not using a pager; i.e., if you have a very small number of nodes --but let's ignore this option).

One solution is to use the Computed Field module. You define, as PHP code, the value this field gets upon node submission. The drawback is that if, for some reason, you change the formula, you need to find a way to recalculate it in all existing nodes.

Another solution is to inform Views to sort by prividing the SQL formula. You do this by writing your own sort hook, or by implementing hook_views_pre_query().

Thanks

faunapolis - July 6, 2007 - 04:17

Mooffie,

Thank you very much. I am getting acquainted with the views module and the hook_views_pre_query() to test this option.

http://www.faunapolis.org/

 
 

Drupal is a registered trademark of Dries Buytaert.