Get Atributes Based on User ID

Permalink 4 users found helpful
How do you get a User's email address based on their user ID.

For example, imagine a block that lists all the users and the email address associated to each user.

I thought the __call function might be the key, but I'm not sure how to use it. It was mentioned here:http://www.concrete5.org/index.php?cID=2984...

HALP!

ijessup
 
ijessup replied on at Permalink Reply
ijessup
bumpity bump
andrew replied on at Permalink Best Answer Reply
andrew
You're on the right track. What you'll want to do is user the UserInfo class.

So, say your user's ID is 4.

<?php
Loader::model('userinfo');
$ui = UserInfo::getByID(4);
print $ui->getUserEmail();
?>


Now, the __call function actually works with the custom user attributes. So, say you define a custom user attribute named "bio_information". To get that information about a user, you can just run this method:

<?php
Loader::model('userinfo');
$ui = UserInfo::getByID(4);
print $ui->getUserBioInformation();
?>


It'll go into the database and retrieve the user attribute, even though it's one you created.
ijessup replied on at Permalink Reply
ijessup
Ah ha. That makes sense.

I don't have the code in front of me, but I remember a second parameter ($a I think). What does it do?
andrew replied on at Permalink Reply
andrew
Oh - the $a is just an array of the arguments passed to the function that is being called through __call. But since these are always getters that probably will always be empty (and it's not used by our custom function anyway.)
cyandesigns replied on at Permalink Reply
Any way to use this script for the currently signed in user?

I like the simplicity of this, but I want to create a custom profile page that allows me to display the current and my custom user attributes in specified areas, not just list them underneath each other.
ijessup replied on at Permalink Reply
ijessup
First initiate the user:
$u = new User();
Then get the UserInfo object based on the user's ID:
$ui = UserInfo::getByID($u->getUserID());
Then call functions of the UserInfo object to get the information you need.
print $ui->getUserEmail();
print $ui->getAttribute('custom_attribute_handle');


List of functions to GET information:
getFileAddLevel()
getFileAdminLevel()
getFileReadLevel()
getFileSearchLevel()
getFileWriteLevel()
getGroupMemberType()
getLastLogin()
getLastOnline()
getNumLogins()
getPreviousLogin()
getUserDateAdded()
getUserEmail()
getUserEndDate()
getUserID()
getUserName()
getUserObject()
getUserPassword()
getUserStartDate()
hasAvatar()
isActive()
isFullRecord()
isValidated()

More functions at:http://concrete5.org/api/
cyandesigns replied on at Permalink Reply
Thank you so much - very helpful!
wormracer08 replied on at Permalink Reply
wormracer08
Awesome! I've been looking for some of these functions for awhile.