CB query fields question

1 year 6 months ago #330852 by activha
Replied by activha on topic CB query fields question
It's a Query field type displaying a single row/column with 
SELECT `id` FROM `#__affiliate_tracker_accounts` WHERE `user_id` = '[user_id]' AND `id` != '0' LIMIT 1

and we retrieve it by 
$cbUser  = CBuser::getInstance($user_id, false);
$atid         = $cbUser->replaceUserVars('[cb:userdata field="cb_refid" user="' . $user_id . '" /]');
Then it displays the old column value instead of getting the query

Please Log in to join the conversation.

1 year 6 months ago #330853 by krileon
Replied by krileon on topic CB query fields question
A query field should not have a column in _comprofiler. Delete the column associated with the query field to fix your issue. This is simply one of the possible issues that can happen when changing a fields type (not recommended, but is allowed). In this case the column isn't deleted automatically encase the field type change was an accident and is only deleted if the field is deleted.

$cbUser = CBuser::getInstance($user_id, false);
$atid = $cbUser->replaceUserVars('[cb:userdata field="cb_refid" user="' . $user_id . '" /]');

You should be using the getFields API to do this not forcing a single substitution parse. See the below for getFields API.

www.joomlapolis.com/documentation/279-community-builder/tutorials/18361-obtaining-field-values-through-getfields-api


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.

1 year 6 months ago #330859 by activha
Replied by activha on topic CB query fields question
I have some issues with the API
$cbMyUser = CBuser::getMyInstance();
$MyId = $cbMyUser->getField( 'user_id', null, 'csv', 'none', 'profile' );
//print '<pre>' . htmlspecialchars(print_r($cbMyUser, true)) . '</pre>';
echo 'test:'.$MyId;

The "print" displays the whole user object correctly but the echo does not display the user_id or any fields neither. I also tried list instead of profile and other outputs without luck
That's why I used substitutions because I couldn't get the data of the user object
May be that you know while this fails ??

Please Log in to join the conversation.

1 year 6 months ago #330862 by krileon
Replied by krileon on topic CB query fields question
You're also trying to call getFields on a user_id field. There is no user_id field. You get user id from their user object directly.
$cbMyUser = CBuser::getMyInstance();
$MyId = $cbMyUser->getUserData()->getInt( 'id', 0 );

See the below tutorial on how to work with user objects from CBuser.

www.joomlapolis.com/documentation/279-community-builder/tutorials/18359-establishing-a-cb-user-object

Additionally you're trying to get 'csv' output. Typically you'll always want 'html' (profile output) or 'list' (userlist output).
$cbMyUser = CBuser::getMyInstance();
$MyId = $cbMyUser->getUserData()->getInt( 'id', 0 );
$refid = $cbMyUser->getField( 'cb_refid' );


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.
The following user(s) said Thank You: activha

Please Log in to join the conversation.

1 year 6 months ago - 1 year 6 months ago #330904 by activha
Replied by activha on topic CB query fields question
It seems that calling the query field with getField fails when the viewer is not logged in.
$user_id  = $action->string($user, '[var1_user_id]');
$cbUser  = CBuser::getInstance($user_id, false);
$cbId = $cbUser->getUserData()->getInt( 'id', 0 );
$reffirstname = $cbUser->getUserData()->getString( 'firstname', '' );
$atid = $cbUser->getField( 'cb_refid' );

The getUserData works fine to retrieve strings and integers but the getField for the query field fails.
Query field is 
SELECT `id` FROM `#__affiliate_tracker_accounts` WHERE `user_id` = '[user_id]' AND `id` != '0' LIMIT 1

Can you tell me what I miss here to have the display of the query field even if the viewer is not logged in ??

Also trying to drop the column cb_refid gives the sql error : ERROR: Invalid default value for 'message_last_sent'

Please Log in to join the conversation.

1 year 6 months ago - 1 year 6 months ago #330909 by krileon
Replied by krileon on topic CB query fields question

Can you tell me what I miss here to have the display of the query field even if the viewer is not logged in ??

Failing how? Sounds like you're just acting on a viewing users object so it's not going to return anything since their user id is always 0.

 Also trying to drop the column cb_refid gives the sql error : ERROR: Invalid default value for 'message_last_sent'

That's normal if you're trying to manage your database outside Joomla/CB as your database is setting an SQL mode. Run the below SQL then try again.
SET GLOBAL sql_mode = '';


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.270 seconds

Facebook Twitter LinkedIn