views:

2247

answers:

2

i have a decent understanding of configuring drupal and using modules for basic stuff, but just getting into module development and overriding functions and stuff due to my very basic understanding of php and mysql.

i have a custom content type ('books') and a 3 cck field for genres (primary, secondary, tertiary). i'd like a user to be able to filter a view of all books with one exposed multi-selectable 'genre' filter. that's where i'm stuck-- i understand how to have three exposed filters for the 3 genre 'weights' (primary, secondary, tertiary)--i want one filter that would allow users to select any or all of those weights.

is a custom search form my only option? was there a better way to set things up? would i have been better off using one cck field for 'genres' with multiple entries? i ruled this out because i thought it would be harder to determine the genre 'weight' (primary, secondary, tertiary).

thanks a million.

A: 

Jergason has a good point saying that taxonomy would probably be a good fit for your fields. However this wouldn't solve your problem of weighted genres.

A possible (though hacky) solution would be to have a fourth field which combined the values of the other three which is only set when a node is saved. This field could then be used for searching.

The non hacky solution is to write your own views filter but this is very advanced.

There may be a way to do this with views out of the box it is flexible, hopefully someone else knows of an easier non hacky solution.

Jeremy French
writing your own views filter is not a little advanced it's very advanced to say the least. Having only little experience with Drupal and programming, this would not be a real solution.
googletorp
Updated, you are right.
Jeremy French
thanks again, googletorp and jeremy. one more bit of info: i don't expect the properties (as defined by my cck fields, like 'genre') to change, so i'm open to a hacky/hard coded solution. is a custom search form more within a beginner's grasp than a custom views filter?anyone else have an idea to do this (use one exposed views filter to search/filter several similar cck fields?)?
wagner
I would have a go at implementing them via a taxonomy, and then re examine the problem. Personally I havn't tried a custom search form so can't comment on that.
Jeremy French
thanks again. we (foolishly) already have a lot of content in the system, so reworking with taxonomy would be a real blow. your idea about the fourth 'combiner' field could definitely work, but i'm not sure how to implement the combining -- any pointers?
wagner
+1  A: 

Think about what the meaning of genres to a book is. Taxonomy is just what you use for this kind of thing. There are several pros using the taxonomy rather than using CCK fields.

  • Taxonomy is meta data, CCK fields are not. This mean that the way the html is generated for taxonomy terms, it will help SE to understand that these genres are important and it will give you a free SEO
  • You can setup how genres should be selected in far more detail than a CCK field. Again since taxonomy is made for exactly this kind of thing. You can setup how users are presentated with the genre selection in various ways. You can predefine genres or let users enter their own as they like. You can make child-parent relation ships and more
  • It's easier and more lightweight to use taxonomy than CCK fields.
  • If there only is 1 or 2 genre inputted you wont have to have empty CCK fields.
  • probably more that I can't think of right now

Using taxonomy you can pretty easily make a search with views, where you make it possible for users to select genres using a multiple select list. You can decide if you require all terms or only one of them. Simply put you should really use taxonomy, it should solve all of your problems, if not, you should still use it and try to solve the problems you could get using taxonomy instead of CCK fields.

googletorp
Good answer, the only thing I can't see how to do with a taxonomy is to keep the "weight" of the genre.
Jeremy French