1

I'm trying to develop a custom module in PHP for jomsocial.

How can I retrieve information about the current profile being visualized by user? (Not info about looged user itself but about the profile displayed!) It would be enough getting username and id, but does anyone know a way to get info and how much info? I've being searching in Jomsocial API with no luck ;(

Thanks a lot for any help!

4

5 に答える 5

5
// Return user with the given id
$user =& CFactory::getUser($userId);

// Return current logged-in user. If no one is logged-in, it will
// return a visitor object
$user =& CFactory::getUser();

カスタムフィールドからユーザー固有の情報を取得する

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

とても簡単です。コンテンツ全体を表示したい場合は、var_dump($ user)またはprint_r($ user);を実行してください。

たとえば、ユーザーの性別を取得したい場合は、次のように使用できます。

$gender = $user->getInfo('FIELD_GENDER');
于 2013-02-24T15:33:11.397 に答える
3

I think this answer is very late but here goes for those who have the same problem.

I recently finished some tasks related with Jomsocial Version: 2.8.3 in Joomla 2.5.11 and I faced the problem you described.

In the module you can add the following lines of code

require_once( JPATH_BASE . DS . 'components' . DS . 'com_community' . DS . 'libraries' . DS . 'core.php');
$userinfo = & CFactory::getActiveProfile();

So, the $userinfo object has all the information you want, the id of the current displayed profile will be:

$userinfo->_userid

Hope this help to other devs.

Cheers.

于 2013-05-23T06:10:27.600 に答える
2

NONE OF THE ABOVE ARE CORRECT, I HAD THE SAME ISSUE. To get the user info for the currently viewed profile you MUST use:

$this->_user = CFactory::getRequestUser();

This is the ONLY way to get the info of the currently viewed profile and not return logged in user profile info...

于 2014-01-02T04:23:17.640 に答える
0

$cuser = CFactory::getUser(); $userid = $cuser->id; echo $data This will give the id of current user, n like this we can get the username n other details of current user. Like $username = $cuser->username;

于 2014-01-06T10:11:46.893 に答える
0

The basic way to retrieve the currently logged in user is shown bellow. If no one is logged in, it will return "guest" object.

$cuser = CFactory::getUser();

  1. $cuser->id;
  2. $cuser->name;
  3. $cuser->username;
  4. $cuser->email;
  5. $cuser->password;
  6. $cuser->block;
  7. $cuser->registerDate;
  8. $cuser->lastvisitDate;
  9. $cuser->getThumbAvatar();

OR

You can refer this complete official documentation for JomSocial userObject on their website.

于 2016-02-15T06:57:41.477 に答える