Jump to content

User ID selector sometimes work, other times doesn't.


Harmster
 Share

Recommended Posts

Hey hi hello,

And here I am again with a new question :-[

So I've been making a check for a balance check (In Dutch: Saldo) and this basicly checks all transactions made over a time and adds or substracts an amount to a variable which in the end gets returned... Simple right?

No.

The selector I user to select all the transactions from a user does not always work.

this is my Selector:

$transacties = wire('pages')->find("template=transaction, users=$user->id");

Straight forward I thought.

When I add a new transaction page with the user ID of someone else it doesn't get added to $transacties

Then I change the user ID to mine (the logged in user) it gets added so far so good

BUT when I change it back to some other ID it still gets added... I don't get it. I figured the selector must still select it somehow.. but why and how?

--EDIT

Just to be clear, the $user->id is from the argument in a method... also tried to use this different namings etc but that wont do much.

public function get_saldo($u)
   {
    $user_saldo = 0;
    $transacties = wire('pages')->find("template=transaction, users=$u->id");

I can't make any errors in this part since there's money involved.

Please can someone answer this question?

Much appreciated,

Harm.

Link to comment
Share on other sites

What type of field is "users" in the "transaction" template? And how is it populated?

Edit: I'm wondering if this is what you are looking for:

$transacties = wire('pages')->find("template=transaction, created_users_id=$user->id");
Link to comment
Share on other sites

What type of field is "users" in the "transaction" template? And how is it populated?

Edit: I'm wondering if this is what you are looking for:

$transacties = wire('pages')->find("template=transaction, created_users_id=$user->id");

The field Users is a PAGE type, its a list of users ID's in admin already so that should be fine right?

Euhm, I am not looking for that since other users can make transactions too... so that it wouldnt be account linked anynmore...

Link to comment
Share on other sites

With the page type field, you have to use the page object itself and not the ID. Assuming that you are using the "Users" pages under "Access" for the field, this should work:

$u = wire('pages')->get($user->id); //get the user page
$transacties = wire('pages')->find("template=transaction, users=$u");

edit: funny, In Portuguese balance check is also "Saldo" :)

Link to comment
Share on other sites

With the page type field, you have to use the page object itself and not the ID. Assuming that you are using the "Users" pages under "Access" for the field, this should work:

$u = wire('pages')->get($user->id); //get the user page
$transacties = wire('pages')->find("template=transaction, users=$u");

edit: funny, In Portuguese balance check is also "Saldo" :)

I think its taken from spanish or portuguese..

/offtopic

tried and uit still doesnt work...

I thought it makes sense and I already did facepalm myself but it sitll odesnt work if I change a record to another users ID it still does add up to my saldo...

Link to comment
Share on other sites

$u = wire('pages')->get($user->id); //get the user page
$transacties = wire('pages')->find("template=transaction, users=$u");

vs.

$transacties = $pages->find("template=transaction, users=$user"); 

Those two above are actually identical, so I would just use the shorter one. There's no need to retrieve $u, because it would be the same thing as $user, an API variable already present.

What I'm wondering is if these "transaction" pages are access protected in some way? I'm guessing they are, based on the name. :) So what you want is probably this:

$transacties = $pages->find("template=transaction, users=$user, check_access=0"); 

or this

$transacties = $pages->find("template=transaction, users=$user, include=all"); 

The "check_access=0" does nothing other than cancel access checking. Whereas "include=all" does even more, as it cancels access checking and enables hidden and unpublished pages to be included as well.

Link to comment
Share on other sites

$u = wire('pages')->get($user->id); //get the user page
$transacties = wire('pages')->find("template=transaction, users=$u");

vs.

$transacties = $pages->find("template=transaction, users=$user"); 

Those two above are actually identical, so I would just use the shorter one. There's no need to retrieve $u, because it would be the same thing as $user, an API variable already present.

What I'm wondering is if these "transaction" pages are access protected in some way? I'm guessing they are, based on the name. :) So what you want is probably this:

$transacties = $pages->find("template=transaction, users=$user, check_access=0"); 

or this

$transacties = $pages->find("template=transaction, users=$user, include=all"); 

The "check_access=0" does nothing other than cancel access checking. Whereas "include=all" does even more, as it cancels access checking and enables hidden and unpublished pages to be included as well.

Okay, tried, no result... still the same...

All the transactions are in a transaction page this one does have the property hidden... The others don't.

But what I find strange is that as soon as enter a new page with a different user ID that it works but when I start changing them that it just screws up everything...

Link to comment
Share on other sites

Can you try renaming your Page reference field to something other than 'users'? Since that is the name of an API variable, I'm just wondering if it's causing a conflict somewhere. I checked and 'users' is not a reserved word in the system, but maybe it should be.

Link to comment
Share on other sites

Well the strange thing here is that when I create a new record with a different user ID it does exactly what it should do but when I change it to the user id of the currently logged in user it does do what it should too but when i change the id back to a different one it still shows up as in the current user transactions, which it shouldn't

My colleague asked me if it might be a sessions somewhere?

Link to comment
Share on other sites

Okay... I figured out what happens...

The user ID property has the following value.

1081|1068|1080

Which is all the ID's i switched around with...

I did not even think about echoing the value. -_-

How can i change this field to always be 1 user ID instead of a array like pipe id thingy?

Posted too fast, i found it in the field settings -> details.

Link to comment
Share on other sites

Harmster, for future reference;

I'm guessing you're talking about the "Dereference in API as" setting for page fieldtypes? You've now set it to Single page?

Not sure what to make of it. If you had 3 id values (PageArray) it means that you've had selected 3 users on the transaction page? I can understand that the result would be unpredictable with some of the code you posted. Actually, i'm surprised that you got results some of the times.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...