[SOLVED] userlist and $_CB_framework::displayedUser()

11 years 6 months ago - 11 years 6 months ago #212282 by ahmaniea
I have a CB field "cb_companydescription", which is a relatively long description of each user. I would like to create a CB user list that involves a truncated version of this field, say the first 100 characters.

I created another CB field in which I read the cb_companydescription from API and then truncate the resulted output:
global $_CB_framework;
$vid = $_CB_framework->displayedUser();
//echo "disp userid $vid";
$cbUser = &CBuser::getInstance( $vid );
$cname = $cbUser->getField('cb_companydescription');
$sho = substr($cname, 0, 100) . "...read more.";
echo $sho;

Now this CB field works perfectly well if used inside CB profile, but when I try to use the field in my user list, $_CB_framework->displayedUser() always returns NULL.

Also, if I have a CB field with a substitution like this [cb:userdata field="username" user="#displayed" /], the field doesn't work in userlist.

1) Is there a way to use $_CB_framework::displayedUser() (or something similar) in a CB field that is used in a userlist?
or
2) Is there some other way to achieve what I'm trying to do?

I have the latest CB and Joomla 2.5.

thanks in advance

Please Log in to join the conversation.

11 years 6 months ago #212341 by krileon
I suggest installing CB Query Field and simply using the below query to grab the fields value in a query field then adding the field to a column. Note it won't be searchable, you'll need to use the original field to search it.
SELECT IF( CHAR_LENGTH( `cb_companydescription` ) >= 100, CONCAT( SUBSTR( `cb_companydescription`, 0, 100 ), '...read more.' ), `cb_companydescription` ) FROM `#__comprofiler` WHERE `id` = '[user_id]'


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.

11 years 6 months ago #212356 by ahmaniea
Thank you so much, I got it working now. I'm quite new to Joomla & CB and I thought [user_id] always references to the user who is logged in, but that was a false assumption.

In case someone tries to copy/paste this SQL-query, I had to change the second parameter of SUBSTR from 0 to 1. I appreciate your quick response.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.864 seconds

Facebook Twitter LinkedIn