Here is the challenge I need to address, if anybody can help.
Scenario: Users all belong to one permissions group or another, based on their country - Thailand, UK etc. Records in a table include field 'Country' - Thailand, UK etc.
Users from Thailand can access all the table records, as can User from England. When User from User group 'Thailand' arrives, she wants the pre-filtered configured so she only sees records where country field = Thailand. (She can click View all if she wants to see the rest.) When UK guy arrives, he wants the pre-filter to only show where country = UK. That's it - not to much to ask!
But I can't figure out how to reference the current User in order to say - 'ah, she's in the Thai group, we need to filter by country="Thailand".
I have seen the partial solution at: https://bigprof.com/appgini/tips-and-tu ... ult-filter.
But after the usual time consuming non-result, this is my best effort to later it to reflect my needs. My solution doesn't work - any thoughts much appreciated. Thanks
function meetings_init(&$options, $memberInfo, &$args){
/* Apply a default filter only if no filter is already applied by the user */
if(!$_POST['FilterField'][1] && !$_GET['FilterField'][1]){
/*
In the call below, we want to display records of the meetings
table where the value of the 1st field is equal to '(the Group name of thge current user'.
*/
$group = $_REQUEST[Group'];
addFilter(1, 'and', 1, 'equal-to', '$group');
}
return TRUE;
}
pre-filter depending on user
- D Oliveira
- AppGini Super Hero
- Posts: 348
- Joined: 2018-03-04 09:30
- Location: David
Re: pre-filter depending on user
you can try:
Code: Select all
function meetings_init(&$options, $memberInfo, &$args){
/* Apply a default filter only if no filter is already applied by the user */
if(!$_POST['FilterField'][1] && !$_GET['FilterField'][1]){
/*
In the call below, we want to display records of the meetings
table where the value of the 1st field is equal to '(the Group name of thge current user'.
*/
$sql = "SELECT `name` FROM `membership_groups` WHERE `groupID` = '{$memberInfo['groupID']}' ";
$group_name= sqlValue($sql);
$groupID = $memberInfo['groupID'];
addFilter(1, 'and', 1, 'equal-to', '$group_name'); // or use $groupID if thats what you need
}
return TRUE;
}
Re: pre-filter depending on user
D Oliveira, thank you very much. To me your suggestion reads perfectly - but I can't get it to work. I've paid attention to the 1 in addFilter(1 - it is the only filter so 1 seems correct. The field I want to match with the group name is 2 (where I originally said was 1 as in 'and', 1, 'equal to..) which is the second field in the table (I've tried 1,2,3 etc!) So I can't see why it won't work? What I get is 'No results' (when I know there are). If I change it to 'not-equal-to' I get the full unfiltered list of records which is of course also wrong but perhaps that's a pointer? Thanks for any input - it would be really helpful to crack this and I think we're close.
- D Oliveira
- AppGini Super Hero
- Posts: 348
- Joined: 2018-03-04 09:30
- Location: David
Re: pre-filter depending on user
to diagnose this you would want to enable saving filters feature to that table, then manually apply the filters and look at the generated URL to see how that looks like, from that point on you can change the code
Re: pre-filter depending on user
Great, thanks for that - I'll look into it and report back. I really need to get this working - and I think it might be a common requirement.
Re: pre-filter depending on user
I found the problem .. addFilter(1, 'and', 1, 'equal-to', '$group_name'); - dropped the ' ' from $group_name so now reads:
addFilter(1, 'and', 1, 'equal-to', $group_name);
The above is the answer to the problem but in case it helps anyone I'll als mention that the field I was filtering on was 2 so my actual output is addFilter(1, 'and', 2, 'equal-to', $group_name);
Thanks D Oliveira for your help.
addFilter(1, 'and', 1, 'equal-to', $group_name);
The above is the answer to the problem but in case it helps anyone I'll als mention that the field I was filtering on was 2 so my actual output is addFilter(1, 'and', 2, 'equal-to', $group_name);
Thanks D Oliveira for your help.
Re: pre-filter depending on user
Oh dear! Problems. On the face of it, it works. BUT I have realised it's causing two errors:
1) You can't view a second page (or 3rd ..) of records.
When you first arrive, you see just your results - as per the above solution. In my example, 6 records out of 17. Then you click to see all records - which displays page one, 1-10 of 17 assorted records. Then click to go to page 2 of the results (11 -17) and I get my original 6 pre-filtered records. So the summary is I can't view all records after page 1. (It's fine when I remove the the pre-filter code)
2) The search errors when you use it (it's fine when I remove the the pre-filter code).
When I search for 'gum' I get the following error message:
Query:
SELECT `conferences`.`ID` AS 'ID', `conferences`.`country` AS 'country', if(`conferences`.`date`,date_format(`conferences`.`date`,'%d/%m/%Y'),'') AS 'date', concat('<i class="glyphicon glyphicon-', if(`conferences`.`date_provisional`, 'check', 'unchecked'), '"></i>') AS 'date_provisional', `conferences`.`title` AS 'title', `conferences`.`location` AS 'location', concat('<i class="glyphicon glyphicon-', if(`conferences`.`location_provisional`, 'check', 'unchecked'), '"></i>') AS 'location_provisional', `conferences`.`organiser` AS 'organiser', concat('<i class="glyphicon glyphicon-', if(`conferences`.`organiser_provisional`, 'check', 'unchecked'), '"></i>') AS 'organiser_provisional', `conferences`.`topic` AS 'topic', `conferences`.`purpose` AS 'purpose', `conferences`.`est_participants` AS 'est_participants', `conferences`.`results_evaluation` AS 'results_evaluation', `conferences`.`conf_materials` AS 'conf_materials', `conferences`.`programme` AS 'programme', `conferences`.`powerpoint` AS 'powerpoint', `conferences`.`speeches` AS 'speeches', `conferences`.`summary` AS 'summary', `conferences`.`media_reports` AS 'media_reports', `conferences`.`testimonies` AS 'testimonies', `conferences`.`images` AS 'images', `conferences`.`category` AS 'category', `conferences`.`origin` AS 'origin', COALESCE(`conferences`.`ID`) AS 'conferences.ID' FROM `conferences` where (`conferences`.`ID` LIKE '%gum%' or `conferences`.`country` LIKE '%gum%' or if(`conferences`.`date`,date_format(`conferences`.`date`,'%d/%m/%Y'),'') LIKE '%gum%' or concat('<i class="glyphicon glyphicon-', if(`conferences`.`date_provisional`, 'check', 'unchecked'), '"></i>') LIKE '%gum%' or `conferences`.`title` LIKE '%gum%' or `conferences`.`location` LIKE '%gum%' or concat('<i class="glyphicon glyphicon-', if(`conferences`.`location_provisional`, 'check', 'unchecked'), '"></i>') LIKE '%gum%' or `conferences`.`organiser` LIKE '%gum%' or concat('<i class="glyphicon glyphicon-', if(`conferences`.`organiser_provisional`, 'check', 'unchecked'), '"></i>') LIKE '%gum%' or `conferences`.`topic` LIKE '%gum%' or `conferences`.`purpose` LIKE '%gum%' or `conferences`.`est_participants` LIKE '%gum%' or `conferences`.`results_evaluation` LIKE '%gum%' or `conferences`.`conf_materials` LIKE '%gum%' or `conferences`.`programme` LIKE '%gum%' or `conferences`.`powerpoint` LIKE '%gum%' or `conferences`.`speeches` LIKE '%gum%' or `conferences`.`summary` LIKE '%gum%' or `conferences`.`media_reports` LIKE '%gum%' or `conferences`.`testimonies` LIKE '%gum%' or `conferences`.`images` LIKE '%gum%' or `conferences`.`category` LIKE '%gum%' or `conferences`.`origin` LIKE '%gum%') and ( `conferences`.`country` <=> 'Admins' ) ) LIMIT 0, 10
The above info is displayed because you are currently signed in as the super admin. Other users won't see this. So, any thoughts on how to address the two problems whilst retaining the pre-filter feature? (Or an alternative that achieves the original goal but without the side effects! Thanks in advance, any thoughts much appreciated as always.
1) You can't view a second page (or 3rd ..) of records.
When you first arrive, you see just your results - as per the above solution. In my example, 6 records out of 17. Then you click to see all records - which displays page one, 1-10 of 17 assorted records. Then click to go to page 2 of the results (11 -17) and I get my original 6 pre-filtered records. So the summary is I can't view all records after page 1. (It's fine when I remove the the pre-filter code)
2) The search errors when you use it (it's fine when I remove the the pre-filter code).
When I search for 'gum' I get the following error message:
Query:
SELECT `conferences`.`ID` AS 'ID', `conferences`.`country` AS 'country', if(`conferences`.`date`,date_format(`conferences`.`date`,'%d/%m/%Y'),'') AS 'date', concat('<i class="glyphicon glyphicon-', if(`conferences`.`date_provisional`, 'check', 'unchecked'), '"></i>') AS 'date_provisional', `conferences`.`title` AS 'title', `conferences`.`location` AS 'location', concat('<i class="glyphicon glyphicon-', if(`conferences`.`location_provisional`, 'check', 'unchecked'), '"></i>') AS 'location_provisional', `conferences`.`organiser` AS 'organiser', concat('<i class="glyphicon glyphicon-', if(`conferences`.`organiser_provisional`, 'check', 'unchecked'), '"></i>') AS 'organiser_provisional', `conferences`.`topic` AS 'topic', `conferences`.`purpose` AS 'purpose', `conferences`.`est_participants` AS 'est_participants', `conferences`.`results_evaluation` AS 'results_evaluation', `conferences`.`conf_materials` AS 'conf_materials', `conferences`.`programme` AS 'programme', `conferences`.`powerpoint` AS 'powerpoint', `conferences`.`speeches` AS 'speeches', `conferences`.`summary` AS 'summary', `conferences`.`media_reports` AS 'media_reports', `conferences`.`testimonies` AS 'testimonies', `conferences`.`images` AS 'images', `conferences`.`category` AS 'category', `conferences`.`origin` AS 'origin', COALESCE(`conferences`.`ID`) AS 'conferences.ID' FROM `conferences` where (`conferences`.`ID` LIKE '%gum%' or `conferences`.`country` LIKE '%gum%' or if(`conferences`.`date`,date_format(`conferences`.`date`,'%d/%m/%Y'),'') LIKE '%gum%' or concat('<i class="glyphicon glyphicon-', if(`conferences`.`date_provisional`, 'check', 'unchecked'), '"></i>') LIKE '%gum%' or `conferences`.`title` LIKE '%gum%' or `conferences`.`location` LIKE '%gum%' or concat('<i class="glyphicon glyphicon-', if(`conferences`.`location_provisional`, 'check', 'unchecked'), '"></i>') LIKE '%gum%' or `conferences`.`organiser` LIKE '%gum%' or concat('<i class="glyphicon glyphicon-', if(`conferences`.`organiser_provisional`, 'check', 'unchecked'), '"></i>') LIKE '%gum%' or `conferences`.`topic` LIKE '%gum%' or `conferences`.`purpose` LIKE '%gum%' or `conferences`.`est_participants` LIKE '%gum%' or `conferences`.`results_evaluation` LIKE '%gum%' or `conferences`.`conf_materials` LIKE '%gum%' or `conferences`.`programme` LIKE '%gum%' or `conferences`.`powerpoint` LIKE '%gum%' or `conferences`.`speeches` LIKE '%gum%' or `conferences`.`summary` LIKE '%gum%' or `conferences`.`media_reports` LIKE '%gum%' or `conferences`.`testimonies` LIKE '%gum%' or `conferences`.`images` LIKE '%gum%' or `conferences`.`category` LIKE '%gum%' or `conferences`.`origin` LIKE '%gum%') and ( `conferences`.`country` <=> 'Admins' ) ) LIMIT 0, 10
The above info is displayed because you are currently signed in as the super admin. Other users won't see this. So, any thoughts on how to address the two problems whilst retaining the pre-filter feature? (Or an alternative that achieves the original goal but without the side effects! Thanks in advance, any thoughts much appreciated as always.
Re: pre-filter depending on user
Ah! I think the issue might be that the recommendation at https://bigprof.com/appgini/tips-and-tu ... ult-filter may itself be not correct. I say this because when I implement the standard solution as outlined I get the same two exact problems - can't view the second page of results (because they immediately get pre-filtered) and the general search error. I have reported this to Ahmed so hopefully he will be able to reply. But, if anybody has any thoughts it would be most helpful as I'm trying to go live with this app and it's the only thing holding me up. Thanks.