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

Comments

pfaocle’s picture

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:

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!

pfaocle’s picture

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.

eaton’s picture

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.

pfaocle’s picture

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)

Anonymous’s picture

Status: Fixed » Closed (fixed)