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!
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!
bumpity bump
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.
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:
It'll go into the database and retrieve the user attribute, even though it's one you created.
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.
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?
I don't have the code in front of me, but I remember a second parameter ($a I think). What does it do?
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.)
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.
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.
First initiate the user:Then get the UserInfo object based on the user's ID:Then call functions of the UserInfo object to get the information you need.
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/
$u = new User();
$ui = UserInfo::getByID($u->getUserID());
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/
Thank you so much - very helpful!
Awesome! I've been looking for some of these functions for awhile.