Hi,

I made a voting api relationship in views.

I can now add a field to show which user has voted. Views shows me the uid of that user. Is it possible to show the username as well? I'd like to have the username instead of the uid.

Thanx in advance!!!

Comments

timlie’s picture

Managed to get it to work with a views tpl file, views-view-field--viewname--uid.tpl.php

and the following code:

  $user = user_load($row->{$field->field_alias});
  $userpath = 'user/' . $user->uid;
  print l($user->name, $userpath);

I could have used a custom theme function as well but I'd like to have the default theme function.

altparty’s picture

I'm looking for a solution too! But I don't understand yours. Can you be a little more specific?

ntt’s picture

subscribing

ntt’s picture

See http://thedrupalblog.com/category/tags/views-view-fieldtplphp for more about the workaround provided by timlie.

I would think there should be an appropriate views relationship between the users table and the votingapi tables so that it would be easier to accomplish this.

altparty’s picture

Piece of cake now. Thanks.

eaton’s picture

Status: Active » Closed (duplicate)

#327903: Add "Individual voter" relationship - fixed in the official 2.0 release. Thanks!

emartos’s picture

Be very careful, timlie. Your code has a security bug. When you override $user variable, you could be giving access to your backend to anonymous visitors.

It's always better to use another name, such as $testUser or something similar.

wasimhyder09’s picture

Issue summary: View changes

It is very simple to do.

All you need to do is:

  1. Go to your view.
  2. Add a new Relationship
  3. Select UID from the list.
  4. Click Add
  5. Then go to Fields.
  6. Add new field.
  7. Select username from list.
  8. In relationship box, select the relation name that you made with user.
  9. Click Add.

And you are all set.
Hope this helps :)