JomSocial User Object

Revision as of 13:26, 5 September 2013 by Sinisakrisan (Talk | contribs)

Each user within JomSocial is represented by a special object called CUser. CUser inherit all JUser object properties and added a couple new functionality.

Retrieve User Object

There are several ways you can retrieve the user object which is going to be manipulated.
The basic way to retrieve the currently logged in user is shown bellow. If no one is logged in, it will return "guest" object.

$user = CFactory::getUser();


Most common practice to get the user object in third-party component which are likely to already have user object is with given ID

// $userid here is the given ID you should already have retrieved
$user = CFactory::getUser($userId);


And finaly, you can retrieve the user object of the currently requested user.
In simpler terms, this means that you can retrieve the user object that currently is being looked at.
This is particulary useful for profile applications as it will always return the currently requested user object (the user that is currently loaded)

$user = CFactory::getRequestUser();

Extending The User Object

JomSocial user object can be extended on many other ways. You can also get a lot of information from it. We will give you few examples

Retrieve Value From Custom Profile Field

If you need to retrieve any value from custom profile fields, you can use:

$user = CFactory::getUser($userId);
$data = $user->getInfo('FIELD_CODE');


Note: This API will retrieve any custom profile field information regardless of its privacy setting. If you echo the value, it will completely ignore the privacy set by user.