Difference between revisions of "JomSocial User Object"

(Retrieve User Object)
Line 1: Line 1:
__FORCETOC__
 
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==
 
==Retrieve User Object==
 
There are several ways you can retrieve the user object which is going to be manipulated.<br/>
 
There are several ways you can retrieve the user object which is going to be manipulated.<br/>
Line 22: Line 19:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==Extending The User Object==
+
==Extending The CUser 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
 
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
 +
 +
===Accessing Joomla User Properties===
 +
Whenever CUser object is retrieved, it inherit most of the JUser object properties and you can access them as well
 +
* '''id''' - The unique, numerical user id. Use this when referencing the user record in other database tables.
 +
* '''name''' - The name of the user. (e.g. Vint Cerf)
 +
* '''username''' - The login/screen name of the user. (e.g. shmuffin1979)
 +
* '''email''' - The email address of the user. (e.g. [email protected])
 +
* '''password''' - The encrypted version of the user's password
 +
* '''block''' - Set to '1' when the user is set to 'blocked' in Joomla!.
 +
* '''registerDate''' - Set to the date when the user was first registered.
 +
* '''lastvisitDate''' - Set to the date the user last visited the site.
 +
Usage example:
 +
<syntaxhighlight lang="php">
 +
$user = CFactory::getUser();
 +
echo $user->username;
 +
//echoes the username of the user
 +
</syntaxhighlight>
 +
<br />
  
 
===Retrieve Value From Custom Profile Field===
 
===Retrieve Value From Custom Profile Field===

Revision as of 13:41, 5 September 2013

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 CUser 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

Accessing Joomla User Properties

Whenever CUser object is retrieved, it inherit most of the JUser object properties and you can access them as well

  • id - The unique, numerical user id. Use this when referencing the user record in other database tables.
  • name - The name of the user. (e.g. Vint Cerf)
  • username - The login/screen name of the user. (e.g. shmuffin1979)
  • email - The email address of the user. (e.g. [email protected])
  • password - The encrypted version of the user's password
  • block - Set to '1' when the user is set to 'blocked' in Joomla!.
  • registerDate - Set to the date when the user was first registered.
  • lastvisitDate - Set to the date the user last visited the site.

Usage example:

$user = CFactory::getUser();
echo $user->username;
//echoes the username of the user


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.