Notice

The forum is in read only mode.

Support Forum

Welcome! Support Forums have been reactivated
Welcome the Technical Support section. Help us in assisting you by providing us with a concise and descriptive elaboration of your issues. Be specific and if possible, provide us with a step-by-step instruction in replicating your problem.

How can I get the userid of currently displayed profile in PHP?

10 years 3 months ago
  • Roger's Avatar
    Topic Author
  • Roger
  • Offline
  • Fresh Boarder
  • Posts: 23
  • Thank you received: 1
Licenses:
JomSocial Active Socialize Expired

I'm tweaking a module and want to get the userid of the currently displayed profile. How can I do this?

I found this on the web:

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

Is this correct?

Thanks,

Roger

10 years 3 months ago
Licenses:
JomSocial Expired GURU Expired Publisher Expired AdAgency Expired iSEO Expired Socialize Expired

Try with this

$my = CFactory::getUser();

This is deprecated since 1.6.x
CFactory::getActiveProfile();

10 years 3 months ago
  • Roger's Avatar
    Topic Author
  • Roger
  • Offline
  • Fresh Boarder
  • Posts: 23
  • Thank you received: 1
Licenses:
JomSocial Active Socialize Expired

According to documentation...

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

But I don't want the current user, I want the profile being viewed. How?

10 years 3 months ago
  • Roger's Avatar
    Topic Author
  • Roger
  • Offline
  • Fresh Boarder
  • Posts: 23
  • Thank you received: 1
Licenses:
JomSocial Active Socialize Expired

So this seems to work...Just posting it as a code example for others.

The statement to get the currently viewed profile is, I think:

$myUser = CFactory::getActiveProfile();

Then I plugged the code below into Flexi Custom Content , and it did great. Note that you can get custom fields easily.

<?php
include_once JPATH_ROOT.'/components/com_community/libraries/core.php';
$myUser = CFactory::getActiveProfile();

$multiprofile = JTable::getInstance( 'MultiProfile' , 'CTable' );
$multiprofile->load( $myUser->getProfileType() );
if ($multiprofile->name == 'Non-Governmental Organization') {

$Founded = $myUser->getInfo('Field_Date_Founded');
$Mobile = $myUser->getInfo('FIELD_LANDPHONE');
$Address = $myUser->getInfo('FIELD_ADDRESS');
$Province = $myUser->getInfo('FIELD_STATE');
$City = $myUser->getInfo('FIELD_CITY');
$Website = $myUser->getInfo('FIELD_WEBSITE');
$About = $myUser->getInfo('FIELD_ABOUTME');
$Mission = $myUser->getInfo('FIELD_MISSON_STATMENT');

$MyEcho = "";
$MyEcho = $MyEcho . '<p>' . '<b>About:</b> ' . $About . '</p>';
$MyEcho = $MyEcho . '<p>' . '<b>Mission:</b> ' . $Mission . '</p>';
$MyEcho = $MyEcho . '<ul>';
$MyEcho = $MyEcho . '<li>' . '<b>Street:</b> ' . $Address . '</li>';
$MyEcho = $MyEcho . '<li>' . '<b>Province:</b> ' . $Province . '</li>';
$MyEcho = $MyEcho . '<li>' . '<b>City:</b> ' . $City . '</li>';
$MyEcho = $MyEcho . '<li>' . '<b>Website:</b> ' . $Website . '</li>';
$MyEcho = $MyEcho . '</ul>';
$MyEcho = $MyEcho . '<p>' . '<b>Date Founded:</b> ' . $Founded . '</p>';

echo $MyEcho;

$HumanServices = $myUser->getInfo('FIELD_HUMAN_SERVICES');
$HumanRights = $myUser->getInfo('FIELD_HUMAN_RIGHTS');
$Culture = $myUser->getInfo('FIELD_RELIGION');
$Science = $myUser->getInfo('FIELD_SCIENCE');
$Animal = $myUser->getInfo('FIELD_ANIMAL_CONCERNS');
$Culture = $myUser->getInfo('FIELD_CULTURE');
$Education = $myUser->getInfo('FIELD_EDUCATION');
$Environment = $myUser->getInfo('FIELD_ENVIRONMENTAL_ISSUES');

$comma = ',';
$HumanServices = rtrim($HumanServices , $comma);
$HumanRights = rtrim($HumanRights , $comma);
$Culture = rtrim($Culture , $comma);
$Science = rtrim($Science , $comma);
$Animal = rtrim($Animal , $comma);
$Culture = rtrim($Culture , $comma);
$Education = rtrim($Education , $comma);
$Environment = rtrim($Environment , $comma);

$MyAreas = '';
if ($HumanServices <> '' ) $MyAreas = $MyAreas . '<p>Human Services: ' . $HumanServices . '</p>';
if ($HumanRights <> '' ) $MyAreas = $MyAreas . '<p>HumanRights: ' . $HumanRights . '</p>';
if ($Culture <> '' ) $MyAreas = $MyAreas . '<p>Culture: ' . $Culture . '</p>';
if ($Science <> '' ) $MyAreas = $MyAreas . '<p>Science: ' . $Science . '</p>';
if ($Animal <> '' ) $MyAreas = $MyAreas . '<p>Animal: ' . $Animal . '</p>';
if ($Culture <> '' ) $MyAreas = $MyAreas . '<p>Culture: ' . $Culture . '</p>';
if ($Education <> '' ) $MyAreas = $MyAreas . '<p>Education: ' . $Education . '</p>';
if ($Environment <> '' ) $MyAreas = $MyAreas . '<p>Environment: ' . $Environment . '</p>';

echo $MyAreas ;

}
?>

The following user(s) said Thank You: Ashraf
10 years 3 months ago
Licenses:
JomSocial Expired GURU Expired Publisher Expired AdAgency Expired iSEO Expired Socialize Expired
10 years 3 months ago
  • Roger's Avatar
    Topic Author
  • Roger
  • Offline
  • Fresh Boarder
  • Posts: 23
  • Thank you received: 1
Licenses:
JomSocial Active Socialize Expired

Well, the nice thing about this is... You can create fields on sign up that don't display in the profile. They display only in a module that you create and assign to some position.

Now, if only you could include extra images. Now we'd have a social network that was also a Content Construction Kit. :)

Moderators: Piotr Garasiński
Powered by Kunena Forum

Join 180,000 websites creating Amazing communities

JomSocial is the most complete, easy-to-use addon that turns Joomla CMS into a
full -fledged, social networking site

TRY NOW BUY NOW