My main taxonomy vocab is pretty darn big, it has a huge amount of sub categories and when we create content it is very easy to get lost in the huge scrolling list of vocab terms. So I thought that things would be easier if I could somehow display available taxonomy terms based upon role.

CAN THIS EVEN BE DONE ?!?! I've never seen it or even heard of it before.

If I'm not explaining myself well in words, here would be a quick and dirty example

-------------------------------
Main term 'CAT'
-sub term 1
-sub term 2
-sub term 3
-sub term 4

Main term 'FISH'
-sub term 1
-sub term 2
-sub term 3
-sub term 4

Main term 'DOG'
-sub term 1
-sub term 2
-sub term 3
-sub term 4
-------------------------------

How could I make just the cat terms show up for cat role users, fish terms for fish role users, etc?
That would be an elegant way of doing it as each role can only access certain terms.

Please help!

Comments

nirbhasa’s picture

Perhaps there is a module already for this

However ive been in situations in the past where i needed to display info in a way that was not readily available in a Drupal module and i found (despite not being expert in php by any means) it was quite easy to careate a small module that queried the database and displayed information in the way i wanted

My guess is you are using something like TAC to assign taxonomies to roles, so your code would probably include a database query on the tables the TAC module sets up. Im assuming the TAC db table has a column for terms (tid, say) and another one for roles (rid, say) so basically your code might run a bit like this:


function mymodule_print_terms_by_role  {

   $roles = user_roles()

  foreach( $roles as $role)
  {
     $query = db_query('SELECT tid FROM {tac} WHERE rid=%d', $role->rid); //searched db for terms assigned to role
  
     $output .= '<h3>'.$role->name.'</h3>';   //header - specifies the role name

     while($termid = db_fetch_object($query) )  //goes through each result in $query one at a time
     {
                $term_name = db_result(db_query('SELECT name FROM {term_data} WHERE tid=%d', $termid));
                $output .= '<p>'.$term_name.'</p>';     // prints out each term in that role
     }

  }
  
  echo $output;

}

like i said im not familiar with TAC tables db structre (or even what it is called - i am using tac here), so please when you do find the right answer, you can post it here :)

you can also join those 2 db queries, but i thought id err on the simple and explainable side