CB API getField for DropDown Values

12 years 7 months ago #176261 by _Pascal_
CB API getField for DropDown Values was created by _Pascal_
Hi,

How to implement the search to find the value of a related table in CB ?

For instance :
$cbUser->getField( 'atextfield' , null, 'html', null, 'profile' );
=> This is working when values are in com_comprofiler table directly

What happens with the use of a plugin (example : DropDown plugin)
$cbUser->getField( 'adropdownid' , null, 'html', null, 'profile' );
=> I'll get the value ID and not the label associated of that ID.

Could you tell me if it if possible to use CB API to find the label of a dropdrown list on a profile user ?

Thanks, in advance,
Regards,
Pascal

Please Log in to join the conversation.

12 years 7 months ago #176290 by krileon
Replied by krileon on topic Re: CB API getField for DropDown Values
Don't understand what you're trying to obtain. Are you trying to get the name such as "cb_myfield" or the fields ID within database? Please clarify further what you're trying to obtain.


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.

12 years 7 months ago #176326 by _Pascal_
Replied by _Pascal_ on topic Re: CB API getField for DropDown Values
I've a CB drop down SQL field named 'department' linked with a table ('id' + 'label of department') named departments_list.
The comprofiler table stores the ID in the profile.

I'm writing a component using CB API to retrieve the label of the departement but not the ID.
The getField('department') returns only the ID. That doesn't use the dropdown plugin to display the label of the department.

How could I do ?

Please Log in to join the conversation.

12 years 7 months ago - 12 years 7 months ago #176431 by krileon
Replied by krileon on topic Re: CB API getField for DropDown Values
You're always going to get the ID as that's what CB has stored for the user. To get the label you'll need to perform a database query. When creating a drop-down in CB the values are the labels though so this shouldn't be an issue unless you're using some sort of custom drop-down field that pulls values from elsewhere. That API is used to get field values for a user, not get a field itself.


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: mmjurado

Please Log in to join the conversation.

12 years 7 months ago #177243 by _Pascal_
Replied by _Pascal_ on topic Re: CB API getField for DropDown Values
I confirm the issue :


Multiple calls to getField() doesn't return the same value !

For instance : my field is a drop down value from mysql / CB 1.7
$a->value = $cbUser->getField( $a->field_name, '-', 'html', 'none', 'profile' );
echo $a->value;
$a->value = $cbUser->getField( $a->field_name, '-', 'html', 'none', 'profile' );
echo $a->value;
$a->value = $cbUser->getField( $a->field_name, '-', 'html', 'none', 'profile' );
echo $a->value;
The return is
  • DIRECTOR
  • 119
  • 119

The 2nd & 3rd values are the Id instead of 'DIRECTOR' which is the label corresponding to the id='119'.

It may be linked with forge.joomlapolis.com/issues/2166

Could you light me on this point ?

Regards
Pascal

Please Log in to join the conversation.

12 years 7 months ago - 12 years 7 months ago #177296 by krileon
Replied by krileon on topic Re: CB API getField for DropDown Values
You just executed the same API 3 times, don't see why this would cause what you're experiencing. There is a bug regarding select fieldtypes, you're welcome to apply the bug and retry. The API doesn't return the actual field, it returns the fields value stored to the users database table row. It's getting that fields value for that user (cbUser).


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

Facebook Twitter LinkedIn