Automatically filter queries with user information

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
curban
Posts: 2
Joined: 2020-05-22 20:35

Automatically filter queries with user information

Post by curban » 2020-05-27 20:05

Hello all.

I am currently working on an AppGini application but have hit something of a roadblock. I would like to automatically filter the results of a user's query with information that the user provides to the application when they create an account. Users can already filter their search results by this information manually, but for quality of life reasons I would like to make this more automatic.

For example, our business application would work in a number of cities, and we already have tables that contain information for a variety of places, and while some clients need to see information relating to multiple areas, other clients would only need to see the information for one city. For those clients, it would be more convenient for them to automatically filter results by their own city, rather than have to input the filter every time. However, I'm not sure exactly how to implement this. This type of user already has their own group set up, and I understand that in the tablename_init() function you can alter the information displayed before it renders on the page. However the customer's custom user info is part of a SQL table, and is not included in the information provided from getMemberInfo(). Is there a way to access this custom information via PHP, then modify the SQL query with that info in a way that works with the hooks files?

Thank you in advance.

User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

Re: Automatically filter queries with user information

Post by D Oliveira » 2020-05-27 21:15

curban wrote:
2020-05-27 20:05
Hello all.

I am currently working on an AppGini application but have hit something of a roadblock. I would like to automatically filter the results of a user's query with information that the user provides to the application when they create an account. Users can already filter their search results by this information manually, but for quality of life reasons I would like to make this more automatic.

For example, our business application would work in a number of cities, and we already have tables that contain information for a variety of places, and while some clients need to see information relating to multiple areas, other clients would only need to see the information for one city. For those clients, it would be more convenient for them to automatically filter results by their own city, rather than have to input the filter every time. However, I'm not sure exactly how to implement this. This type of user already has their own group set up, and I understand that in the tablename_init() function you can alter the information displayed before it renders on the page. However the customer's custom user info is part of a SQL table, and is not included in the information provided from getMemberInfo(). Is there a way to access this custom information via PHP, then modify the SQL query with that info in a way that works with the hooks files?

Thank you in advance.
you can always get member info:

php

Code: Select all

$mi = getMemberInfo(); echo $mi['username'];
html/js

Code: Select all

<script> var member = '<?php $mi = getMemberInfo(); echo $mi['username']; ?>'; </script>
*you can always use templates .html (templates folder) and tablename_view.php in home directory, just be cautious when generating new apps because those files will be replaced unless set for read-only.

useful links to build your queries:

https://bigprof.com/appgini/help/advanc ... Info-array

https://bigprof.com/appgini/help/advanc ... lculations



hope it helps, cheers!

curban
Posts: 2
Joined: 2020-05-22 20:35

Re: Automatically filter queries with user information

Post by curban » 2020-05-29 17:36

Thank you for your reply. Upon review of the links you provided, I found that I can indeed get all the relevant information from the getMemberInfo() function. However, building my queries seems more difficult. A calculated field is no good because the information that would be filtered would only be read by clients, not altered. So methods like tablename_before_update() can't be used because there's no update.

Upon inspecting the debug information on the DataList object, I noticed that the query information is stored in this object and can be edited in the tablename_init() method since it is passed by reference in that method. Specifically, it is contained inside the QueryFrom and QueryWhere strings. Unfortunately, documentation on these two strings and how they interact with the broader code structure is somewhat scarce. It seems that I could write some PHP code to append the QueryWhere with something like 'WHERE cityname = MemberInfo[customInfo]'. But that assumes that QueryWhere is a conditional SQL string appended to QueryFrom that is then fed into the SQL database. Is this accurate?

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1638
Joined: 2018-04-01 10:12

Re: Automatically filter queries with user information

Post by pbottcher » 2020-05-30 06:37

Hi,

your assumption is right. the QueryWhere is appended. There are a couple posts in the forum where you can find more information.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

Post Reply