Views integration

leafish_paul - May 3, 2006 - 18:31
Project:Role Weights
Version:HEAD
Component:External module integration
Category:task
Priority:normal
Assigned:leafish_paul
Status:closed
Description

One obvious use for this module would be with Views. A view could then sort its nodes by role weights.

#1

leafish_paul - May 3, 2006 - 19:30

OK, struggling with this one. Posting to try and get some help ;)

Role Weights now has a simple database table containing a {rid, weight} pair. Therefore, I should able to JOIN node to user_roles via uid, then user_roles to my role_weights table via rid.

Based on the Views developer docs and hunting through various contrib modules, here's what I have so far:

<?php
function role_weights_views_tables() {
 
$tables['users_roles'] = array(
   
"name" => "users_roles",
   
"join" => array(
     
"left" => array(
       
"table" => "node",
       
"field" => "uid",
      ),
     
"right" => array(
       
"field" => "uid",
      ),
    ),
  );

 
$tables['role_weights'] = array(
   
"name" => "role_weights",
   
"join" => array(
     
"left" => array(
       
"table" => "users_roles",
       
"field" => "rid",
      ),
     
"right" => array(
       
"field" => "rid",
      ),
    ),
   
"sorts" => array(
     
"weight" => array(
       
'name' => "Role Weights: role weight",
       
'field' => array('weight'),
       
'help' => t("Order nodes by author's role weight"),
      ),
    ),
  );

  return
$tables;
}
?>

Which, I thought could work, but alas no. Can anyone spot what I'm doing wrong? Thanks!

#2

leafish_paul - May 3, 2006 - 20:03
Status:active» fixed

Thanks to moshe and eaton on IRC for pointers! With Views and Role Weights enabled, views can now access/display or sort by the node author's role weight.

This is still relatively untested.

#3

eaton - May 3, 2006 - 20:12

Slowly but surely, views.module marches towards world domination. ;-) Looks like a great piece of work, paul. I'll have to try it on one of my editor/user oriented sites.

#4

leafish_paul - May 3, 2006 - 20:19

Please do, it needs proper testing!

(I also use it on a dev site to display different icons for roles next to usernames - users can be in multiple roles, but the icon will always show the 'highest' role icon)

#5

Anonymous - May 17, 2006 - 20:30
Status:fixed» closed
 
 

Drupal is a registered trademark of Dries Buytaert.