Difference between revisions of "JomSocial User Object"

(Created page with "__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. ===Re...")
 
(Retrieve User Object)
Line 2: Line 2:
 
Each user within JomSocial is represented by a special object called CUser. CUser inherit all JUser object properties and added a couple new functionality.
 
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/>
 +
Most common practice to get the user object in third-party component which are likely to already have user object is with given ID
 
<syntaxhighlight lang="php">
 
<syntaxhighlight lang="php">
// Return user with the given id
+
// $userid here is the given ID you should already have retrieved
$user =& CFactory::getUser($userId);
+
$user = CFactory::getUser($userId);
+
// Return current logged-in user. If no one is logged-in, it will
+
// return a visitor object
+
$user =& CFactory::getUser();
+
 
</syntaxhighlight>
 
</syntaxhighlight>
 
<br />
 
<br />
 +
You can also retrieve the currently logged in user. If no one is logged in, it will return "guest" object.
 +
<syntaxhighlight lang="php">
 +
$user = CFactory::getUser();
 +
</syntaxhighlight>
 +
<br />
 +
And finaly, you can retrieve the user object of the currently requested user.<br/>
 +
In simpler terms, this means that you can retrieve the user object that currently is being looked at. <br/>
 +
This is particulary useful for profile applications as it will always return the currently requested user object (the user that is currently loaded)
 +
<syntaxhighlight lang="php">
 +
$user = CFactory::getRequestUser();
 +
</syntaxhighlight>
 +
 +
==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
 +
 +
===1===
 +
 
===Retrieve any user-specific information from custom field===
 
===Retrieve any user-specific information from custom field===
 
<syntaxhighlight lang="php">
 
<syntaxhighlight lang="php">

Revision as of 13:09, 5 September 2013

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.
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);


You can also retrieve the currently logged in user. If no one is logged in, it will return "guest" object.

$user = CFactory::getUser();


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

1

Retrieve any user-specific information from custom field

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