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
Try with this
$my = CFactory::getUser();
CFactory::getActiveProfile();
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?
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 ;
}
?>
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. :)