Trying to list all the name of users in a particular group.

Permalink 1 user found helpful
I have a group called Test_Group, and a custom attribute with handle full_name. I would like to list out the value of full_name for all the users in the this group. Here is my attempt so far:


$gSelection = "Test_Group";
    Loader::model('user_list');
    Loader::model('user');
    Loader::model('userinfo');
    $ul = new UserList();
    $ul->filterByGroup($gSelection);
    foreach ($ul as $u) {
   $ui = UserInfo::getByID($ul->getUserID());
   echo $ui->getAttribute('full_name');
   echo "<br>";
   }


The problem is
echo $ui->getAttribute('full_name');
gives the error:
Fatal error: Call to a member function getAttribute() on a non-object

I tried wrapping it in an if statement:
if(is_object($ui)){
   echo $ui->getAttribute('full_name');
    }

But then nothing at all prints.

 
mhawke replied on at Permalink Reply
mhawke
Haven't tested this but shouldn't $ul->getUserID be $u->getUserID

$u is the individual user from which you are pulling the user attribute 'full_name'.
looeee replied on at Permalink Reply
I had originally thought that, but it gives the error:

Fatal error: Call to a member function getUserID() on a non-object

putting
if(is_object($u)){
   $ui = UserInfo::getByID($u->getUserID());
}

again results in no output.

Just to be clear, there is currently only one user in this group, called test_user with full name Test User.
mhawke replied on at Permalink Best Answer Reply
mhawke
Try this loop:
foreach($ul->getPage() as $u) {
  $ui = UserInfo::getByID($u->getUserID());
  echo "First Name: " . $ui->getAttribute('full_name') . "<br />";
}


Credit: http://www.concrete5.org/community/forums/customizing_c5/user_list-...
looeee replied on at Permalink Reply
It works! Thank you.
looeee replied on at Permalink Reply
I'm having an additional problem with this - it only lists the first ten users in the group (which now has 28 members).
My code is now:
Loader::model('user_list');
Loader::model('userinfo');
$ul = new UserList();
$ul->filterByGroup("Test_Group");
foreach($ul->getPage() as $u) {
    $ui = UserInfo::getByID($u->getUserID());
    $name =  $ui->getAttribute('full_name');
    echo "Name: ".$name."</br>";
}



For some reason this userList $ul has only ten elements - trying to access anything after the tenth returns null. I'm stumped as to why.
mhawke replied on at Permalink Reply
mhawke
The default 'pagination' on the user_list is 10 so try tossing this in just before the foreach loop :

$ul->setItemsPerPage( 100 ); //set to whatever value


You can also try putting this in at the bottom of the page if that makes sense:

<?php echo $ul->displayPagingV2()?>


See this thread:
http://www.concrete5.org/community/forums/customizing_c5/how-to-dis...
pvernaglia replied on at Permalink Reply
pvernaglia
I think you can use 'all' in place of a numeric value as well
looeee replied on at Permalink Reply
"All" doesn't seem to work (with or without quotes).
looeee replied on at Permalink Reply
Yes, that fixed it. Once again, thank you for your prompt reply!