[SOLVED] What's the best way to load field values externaly

13 years 4 months ago #146984 by sfraise
I'm building a jquery app that basically looks like a book and paginates through 5 pages showing different user content. The app sits in a tab on the user's profile, I'm using cb profile pro to customize the profiles.

Everything is working fine outside of I'm having trouble pulling the user's field values into the app. I had hoped that I could simply use the {fld value} tag that cb profile pro uses to do this but it seems I can't.

I've tried doing this by setting up a database query and echoing the field value but I'm apparently not pulling the user id properly.

I'm able to do this using the logged in user's id and pulling those values so I know this can be done, but I can't seem to find how to call the id of the person's profile you're viewing.
Example:
(Did this to simply test that it worked)
[code:1]
<?php global $_CB_framework, $_CB_database, $ueConfig, $mainframe, $_SERVER;
$user = &JFactory::getUser();
$db = &JFactory::getDBO();
$db->setQuery("SELECT * FROM jos_comprofiler WHERE id =" . $user->id);
$rows = $db->loadObjectList();
$query = "SELECT username FROM jos_users WHERE id = ". (int) $_CB_framework->myId();
$_CB_database->setQuery( $query );
$username = htmlspecialchars( cbUnHtmlspecialchars( $_CB_database->loadResult() ) );
?>
<?php echo($rows[0]->cb_aboutme); ?>
<?php echo $username; ?>
[/code:1]
works fine and pulls the logged in user's field values, but I don't want to show the person their own values, I want to show the values of the person's profile that they're looking at.

Does anyone know what I need to use for the WHERE id = value in order to do this? Or even better, maybe a way to bull the actual field in just like it would on the actual standard profile?

Post edited by: krileon, at: 2010/11/30 14:31

Please Log in to join the conversation.

13 years 4 months ago #146988 by krileon
See tutorials within my signature. You'll need to load CBs API then review the tutorial for getting fields. Direct queries does not respect API or privacy usages nor does it format data.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

13 years 4 months ago #147082 by sfraise
Thanks Krileon, I've gone through those api's and am able to pull the actual field using the api setup, but still just for the logged in user, it still shows the logged in user's values on other profiles as well. I guess what I was asking before is how to get the field values to show for the profile owner instead of the logged in user.

I'm assuming the problem here lies in the fact that I'm using a jquery pagination script to put these fields in. Even though it's sitting in a tab on the user's profile I'm guessing the issue lies with it being external from the actual profile and therefore when it does a user check it just pulls the logged in user's values, but maybe I'm wrong on that. The way I read it in the api the $cbuser check should determine if the profile you're viewing is your own or someone else's and then serve up the appropriate values in a normal situation but in this case there is no way to associate the content in the script with the actual user id of the profile owner. Or I could just be using the wrong method to define the $cbuser. Here's how I'm doing this with the api method:
[code:1]
<?php global $_CB_framework, $_CB_database, $ueConfig, $mainframe, $_SERVER;
$myId = $_CB_framework->myId();
$cbUser =& CBuser::getInstance( $myId );

if ( ! $cbUser ) {
$cbUser =& CBuser::getInstance( null );
}

$user = $cbUser->getUserData();

if ( ! $user ) {
return;
}
$query = "SELECT username FROM jos_users WHERE id = ". (int) $_CB_framework->myId();
$_CB_database->setQuery( $query );
$username = htmlspecialchars( cbUnHtmlspecialchars( $_CB_database->loadResult() ) );
if ( defined( 'JPATH_ADMINISTRATOR' ) ) {
if ( ! file_exists( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' ) ) {
echo 'CB not installed!';
return;
}

include_once( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' );
} else {
if ( ! file_exists( $mainframe->getCfg( 'absolute_path' ) . '/administrator/components/com_comprofiler/plugin.foundation.php' ) ) {
echo 'CB not installed!';
return;
}

include_once( $mainframe->getCfg( 'absolute_path' ) . '/administrator/components/com_comprofiler/plugin.foundation.php' );
}
cbimport( 'cb.database' ;

function getField( $fieldName, $defaultValue = null, $output = 'html', $formatting = 'none', $reason = 'profile', $list_compare_types = 0 ) {};
$cb_aboutme = $cbUser->getField( 'cb_aboutme', null, 'html', 'none', 'list' );
$cb_interests = $cbUser->getField( 'cb_interests', null, 'html', 'none', 'list' );
$cb_edhs = $cbUser->getField( 'cb_edhs', null, 'html', 'none', 'list' );
$cb_edhsclass = $cbUser->getField( 'cb_edhsclass', null, 'html', 'none', 'list' );
$cb_ed = $cbUser->getField( 'cb_ed', null, 'html', 'none', 'list' );
$cb_eddegree = $cbUser->getField( 'cb_eddegree', null, 'html', 'none', 'list' );
$cb_activities = $cbUser->getField( 'cb_activities', null, 'html', 'none', 'list' );
$cb_books = $cbUser->getField( 'cb_books', null, 'html', 'none', 'list' );
$cb_music = $cbUser->getField( 'cb_music', null, 'html', 'none', 'list' );
$cb_movies = $cbUser->getField( 'cb_movies', null, 'html', 'none', 'list' );
$cb_tv = $cbUser->getField( 'cb_tv', null, 'html', 'none', 'list' );
?>
[/code:1]

Maybe what I should really be asking here is how to identify the jquery script content with the profile that it's showing in? Maybe I need to include some extra stuff in the php to link it to the profile url it's being viewed in? I've gone through the cb api pdf as well but haven't really found anything regarding this.

I did glance at the cb content bot but wasn't sure if that would work in this situation since it's not actually a content section piece, however I thought I would ask u about it.

Post edited by: sfraise, at: 2010/11/27 20:12

Please Log in to join the conversation.

13 years 3 months ago #147142 by krileon

but still just for the logged in user, it still shows the logged in user's values on other profiles as well.

You're using myId, of course this is how it'll work. myId is of the logged in user. You need to pass the user_id of the user you want displayed.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

13 years 3 months ago #147188 by sfraise
Right, I wasn't very clear in my long post.
I posted it using myid as an example to say that everything works as far as using the api to make the call and pull the data. The issue is when trying to pull the data for another user. Completely disregard the second call for the username for the moment.

I've tried several variations to try and determine the owner id of the fields being displayed in the jquery content, such as uid userId, user_id, id, etc, but I simply get blank fields returned. So my question is how to go about linking the fields in the jquery content with the userid of the profile you're looking at dynamically?

Please Log in to join the conversation.

13 years 3 months ago #147205 by krileon
I see, so you're wanting to obtain this data from the profile of the user being viewed? In this case you could grab the ID from the URL using the below.

[code:1]
$user_id = cbGetParam( $_REQUEST, 'user', null );
[/code:1]

The above would obtain the userid from the URL directly assuming &user=ID is appended (viewing a user other then your self).


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.216 seconds

Facebook Twitter LinkedIn