Skip to Content Skip to Menu

🎃 Happy Halloween! Treat yourself with an awesome discount on memberships! Get 20% off now with code SPOOKY-2024!

Missing username -> Bug?

  • KatoKalin
  • KatoKalin
  • OFFLINE
  • Posts: 265
  • Thanks: 11
  • Karma: -5
  • Add-ons
10 years 10 months ago - 10 years 10 months ago #238795 by KatoKalin
Missing username -> Bug? was created by KatoKalin
I am trying to do something really simple:

From a select statement I getting an array with user_ids and I want to transform it into CB user objects.

My array looks like this:
Code:
Array ( [0] => 9857 [1] => 9049 [2] => 7733 [3] => 7491 [4] => 7443 )

Now when I do a for loop to instantiate the users, I am not getting the results expectd:
I want to retrieve the usernames. So I do:
Code:
for($i=0;$i<count($rows);$i++){ $cbUser =& CBuser::getInstance($rows[$i]); $username =& $cbUser->getField( 'username', null, 'csv', 'none', 'profile' ); echo $username
Now for some reason when I set 'username' to not show on profile, it will show an empty value for 'username' but only for the first iteration, all others will have the username as value.
When I set $i=-1 then the iteration completes without showing an empty value.

When I set 'username' to show on profile then I can use $i=0 and it does not show that empty value.

I am just wondering why is this? Is this behaviour intentional?

Edit: Only fix I can think of right now is to hide field with Conditional plugin on profiles and set it the field to show on profiles in core profile settings.
Last edit: 10 years 10 months ago by KatoKalin.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48477
  • Thanks: 8281
  • Karma: 1443
10 years 10 months ago - 10 years 10 months ago #238802 by krileon
Replied by krileon on topic Missing username -> Bug?
API respects field configuration, privacy, etc.. To have a field fully accessible to API, but not visible on profile then move it to a tab that is in a not shown on profile position. Your alternative is to get a user data object and pull the value straight from there. Example as follows.

Code:
$user = CBuser::getUserDataInstance( $rows[$i] ); $username = $user->username;


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.
Last edit: 10 years 10 months ago by krileon.

Please Log in or Create an account to join the conversation.

  • KatoKalin
  • KatoKalin
  • OFFLINE
  • Posts: 265
  • Thanks: 11
  • Karma: -5
  • Add-ons
10 years 10 months ago #238810 by KatoKalin
Replied by KatoKalin on topic Missing username -> Bug?
Ok I see. Incorrect usage of mixture between API and non API calls can result in unexpected results. Solved it now.

Still, I am wondering why the results were inconsistant. I was just iterating over an arry of user ids and Api returned empty for the first call (respected privacy) and then it returned all other values (did not respect privacy). This still seems a little inconsistent.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48477
  • Thanks: 8281
  • Karma: 1443
10 years 10 months ago #238842 by krileon
Replied by krileon on topic Missing username -> Bug?
Each row is a separate user. My guess is some of them didn't have privacy stored. I don't know. Issues like that are generally specific to their environment and need to be debugged to determine the cause. In nearly 99% of the case it's just a configuration problem that causes the inconsistency. At any rate use raw object values to avoid all of this as you're pulling straight from their user object.


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 or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum