Evaske Posted September 18, 2013 Report Posted September 18, 2013 Hey, Can anyone point me to how I would go about getting the logged in users id so I can use it in the following: print_r( money_format('£%i', $this->Transactions->getTotalCredit(**USER ID HERE**, "GBP"))); It's to display the amount of credit the logged in user has on the dashboard. Can't seem to find reference though to the users ID. Quote
Michael Posted September 18, 2013 Report Posted September 18, 2013 Hey, Can anyone point me to how I would go about getting the logged in users id so I can use it in the following: print_r( money_format('£%i', $this->Transactions->getTotalCredit(**USER ID HERE**, "GBP"))); It's to display the amount of credit the logged in user has on the dashboard. Can't seem to find reference though to the users ID. Try this mate: print_r( money_format('£%i', $this->Transactions->getTotalCredit($user_id, "GBP"))); Quote
Evaske Posted September 18, 2013 Author Report Posted September 18, 2013 That doesn't seem to work. $user_id is returning blank. Quote
Evaske Posted September 18, 2013 Author Report Posted September 18, 2013 As requested by Paul, some more information. I'm trying to add this code in to structure.pdt to show each client's credit. <?php Loader::loadModels($this, array("Transactions")); ?> <?php if ($this->Html->ifSet($logged_in)) { ?> <div id="credit">Credit: <?php print_r( money_format('£%i', $this->Transactions->getTotalCredit(1, "GBP"))); ?></div> <?php } ?> I need the number 1 to be the client that is currently logged in's ID. Quote
Tyson Posted September 18, 2013 Report Posted September 18, 2013 As requested by Paul, some more information. I'm trying to add this code in to structure.pdt to show each client's credit. <?php Loader::loadModels($this, array("Transactions")); ?> <?php if ($this->Html->ifSet($logged_in)) { ?> <div id="credit">Credit: <?php print_r( money_format('£%i', $this->Transactions->getTotalCredit(1, "GBP"))); ?></div> <?php } ?> I need the number 1 to be the client that is currently logged in's ID. This part happens to be the user ID: <?php if ($this->Html->ifSet($logged_in)) { ?> i.e. $this->Transactions->getTotalCredit($logged_in, "GBP") There is no explicit client information set to the structure, so if you're a staff member logged in as the client, then you would be using the wrong user ID in this case, but it should work fine for clients themselves. Alternatively, you could check to see if the staff is logged in as the client, and simply not display the credit section altogether. i.e. <?php if ($this->Html->ifSet($logged_in, false) && !$this->Html->ifSet($staff_as_client, false)) { ?> As for <div id="credit">Credit: <?php print_r( money_format('£%i', $this->Transactions->getTotalCredit(1, "GBP"))); ?></div> Is there any particular reason you're not using the CurrencyFormat helper? FYI, our future implentation of credits in the client interface will be much different than this. Quote
Evaske Posted September 18, 2013 Author Report Posted September 18, 2013 Didn't even know currencyformat was there. For some reason, that $logged_in is showing the incorrect client ID. I am logged in as client ID 1 (known to be correct because the correct credit amount shows when I manually use 1 in my code). I just echoed out $logged_in and it is showing the value of 4 and not 1? And then if I log in as staff... it becomes 1 and then returns to 4 after logging out as the staff member. Just logged in as another test account. That showed the number 14 but the client ID should be 9 :l Quote
Tyson Posted September 18, 2013 Report Posted September 18, 2013 I was going off of yours and CubicWebs previous comments mentioning user_id, which is the value of $logged_in. However, Transactions::getTotalCredit() requires the client_id, and so you must first determine the client by fetching them via Clients::getByUserId(). Michael and Evaske 2 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.