View table two different ways

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
patsd102
Veteran Member
Posts: 142
Joined: 2013-01-15 19:59

View table two different ways

Post by patsd102 » 2020-01-21 21:34

Is it possible to view a table two different ways,

1, Your own entries
2. All entries.

The group permission will only allow me to view one way or the other.

Thanks in advance

Pat
23.17

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

Re: View table two different ways

Post by pbottcher » 2020-01-21 22:20

Hi,

not sure if I get what you try to achieve, but what you could do is to create a second table which a mirror of the first table in AppGini.
In your database you drop that table and replace it with a view to the first table. Like that both tables are in sync.
Now you can assign to the first table the right to see only your own records and to the second table the right to see all records. (Or whatever you need).
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.

patsd102
Veteran Member
Posts: 142
Joined: 2013-01-15 19:59

Re: View table two different ways

Post by patsd102 » 2020-01-21 22:25

Yes, that's what I want.
I will try that,

Thanks

Pat
23.17

patsd102
Veteran Member
Posts: 142
Joined: 2013-01-15 19:59

Re: View table two different ways

Post by patsd102 » 2020-01-22 21:33

Got that working,
Many thanks pbottcher

Pat
23.17

User avatar
ronwill
Veteran Member
Posts: 228
Joined: 2015-08-08 10:12
Location: Cheltenham UK +Weatherford USA

Re: View table two different ways

Post by ronwill » 2020-01-28 22:04

pböttcher wrote:
2020-01-21 22:20
Hi,

not sure if I get what you try to achieve, but what you could do is to create a second table which a mirror of the first table in AppGini.
In your database you drop that table and replace it with a view to the first table. Like that both tables are in sync.
Now you can assign to the first table the right to see only your own records and to the second table the right to see all records. (Or whatever you need).
I want to do the same, I have created a second (copied) table in my AppGini project and uploaded etc.
How do I replace the database table with a view to the first table?
- I'm using phpMyAdmin on database and don't have much experience on making changes in that, I can see how to drop a table but not how to create a view to first table!
Would appreciate your guidance,
Cheers, Ron
Ron - Gloucestershire, UK: AppGini Pro V 23.15 Rev 1484 - LOVING IT!
Plugins: Mass Update + Search Page Maker + Summary Reports + Calendar + Messages
Bizzworxx: AppGiniHelper + Inline Detail View
Alejandro Landini: To-Do List + MPI + TV Field Editor
Other: Udemy Course

User avatar
pilandros
Veteran Member
Posts: 93
Joined: 2014-02-13 18:19

Re: View table two different ways

Post by pilandros » 2020-01-28 22:43

ronwill wrote:
2020-01-28 22:04
pböttcher wrote:
2020-01-21 22:20
Hi,

not sure if I get what you try to achieve, but what you could do is to create a second table which a mirror of the first table in AppGini.
In your database you drop that table and replace it with a view to the first table. Like that both tables are in sync.
Now you can assign to the first table the right to see only your own records and to the second table the right to see all records. (Or whatever you need).
I want to do the same, I have created a second (copied) table in my AppGini project and uploaded etc.
How do I replace the database table with a view to the first table?
- I'm using phpMyAdmin on database and don't have much experience on making changes in that, I can see how to drop a table but not how to create a view to first table!
Would appreciate your guidance,
Cheers, Ron
This learning video from youtube might help you: https://www.youtube.com/watch?v=6d9OflCXmjo

User avatar
ronwill
Veteran Member
Posts: 228
Joined: 2015-08-08 10:12
Location: Cheltenham UK +Weatherford USA

Re: View table two different ways

Post by ronwill » 2020-01-29 01:03

Thanks for that.
Followed the video and managed to learn how to create a view.
Then followed the instructions:
1. Made duplicate of table1 as table2 in AppGini.
2. Generated project
3. In database, dropped table2
4. Went to table1 in database and created view: table2 (the view correctly shows all records of table1)
5. Returned to project in browser and set up table1 as view/add permissions for user1 and table2 as view only for same user.
6. logged on as user1: selected table1 - can view TV records and on DV can view/add etc. all as normal
7. Then selected table2 - could see all the records in TV view but on selecting any record, DV loads but no record data is being shown?

Have I missed something?
Ron
Ron - Gloucestershire, UK: AppGini Pro V 23.15 Rev 1484 - LOVING IT!
Plugins: Mass Update + Search Page Maker + Summary Reports + Calendar + Messages
Bizzworxx: AppGiniHelper + Inline Detail View
Alejandro Landini: To-Do List + MPI + TV Field Editor
Other: Udemy Course

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

Re: View table two different ways

Post by pbottcher » 2020-01-29 20:35

Hi Ron,

there is a little feature to using this "View" logic. It works fine as long as you only need the tableview. If you go to the detail view and you have some lookups that need to be resolved it does not work out of the box. You need to disable the AppGini cache for the view.

To do so, go to your hooks/TABLENAME.php file and add to the TABLENAME_init function:

Code: Select all

		if (file_exists('templates/TABLENAME-ajax-cache.php')) {
			rename('templates/TABLENAME-ajax-cache.php', 'templates/TABLENAME-ajax-cache.orig.php');
		}
Hope that helps
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.

User avatar
ronwill
Veteran Member
Posts: 228
Joined: 2015-08-08 10:12
Location: Cheltenham UK +Weatherford USA

Re: View table two different ways

Post by ronwill » 2020-01-29 21:43

Excellent thanks for that will give it a go now. I never would have solved that by myself, your help as always is very appreciated,
Cheers,
Ron
Ron - Gloucestershire, UK: AppGini Pro V 23.15 Rev 1484 - LOVING IT!
Plugins: Mass Update + Search Page Maker + Summary Reports + Calendar + Messages
Bizzworxx: AppGiniHelper + Inline Detail View
Alejandro Landini: To-Do List + MPI + TV Field Editor
Other: Udemy Course

User avatar
ronwill
Veteran Member
Posts: 228
Joined: 2015-08-08 10:12
Location: Cheltenham UK +Weatherford USA

Re: View table two different ways

Post by ronwill » 2020-01-29 22:42

pböttcher wrote:
2020-01-29 20:35
Hi Ron,

there is a little feature to using this "View" logic. It works fine as long as you only need the tableview. If you go to the detail view and you have some lookups that need to be resolved it does not work out of the box. You need to disable the AppGini cache for the view.

To do so, go to your hooks/TABLENAME.php file and add to the TABLENAME_init function:

Code: Select all

		if (file_exists('templates/TABLENAME-ajax-cache.php')) {
			rename('templates/TABLENAME-ajax-cache.php', 'templates/TABLENAME-ajax-cache.orig.php');
		}
Hope that helps
Got it working with your solution. Only slight issue is I get a warning under ADMIN/UTILITIES/rebuild fields for the VIEW table:

Found 0 non-existing fields that need to be created.
Found 1 deviating fields that might need to be updated.

It's highly recommended that you create a database backup first before attempting to make any fixes here.
id INT unsigned not null primary key auto_increment INT(10) unsigned not null default '0'

Does not rectify itself with 'FIX ALL FIELDS' When creating view in database I used:
CREATE VIEW `blogview` AS SELECT * FROM `blog` WHERE 1
Should I have done field by field and not included the id field?

Cheers, Ron
Ron - Gloucestershire, UK: AppGini Pro V 23.15 Rev 1484 - LOVING IT!
Plugins: Mass Update + Search Page Maker + Summary Reports + Calendar + Messages
Bizzworxx: AppGiniHelper + Inline Detail View
Alejandro Landini: To-Do List + MPI + TV Field Editor
Other: Udemy Course

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

Re: View table two different ways

Post by pbottcher » 2020-01-29 22:45

Hi Ron,

glad it works.
For the error:
That is a false positive from the database verification. (The check goes for tables, not for views). You need to ignore this due to the fact, that it is correct that the table does not exist any more. But as you replaced the table by the view, the logic to handle all the forms, etc. works perfectly fine.
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.

User avatar
ronwill
Veteran Member
Posts: 228
Joined: 2015-08-08 10:12
Location: Cheltenham UK +Weatherford USA

Re: View table two different ways

Post by ronwill » 2020-02-01 19:55

pböttcher wrote:
2020-01-29 22:45
Hi Ron,

glad it works.
For the error:
That is a false positive from the database verification. (The check goes for tables, not for views). You need to ignore this due to the fact, that it is correct that the table does not exist any more. But as you replaced the table by the view, the logic to handle all the forms, etc. works perfectly fine.
Brill, thanks for explaining that. I've used it on one project now and am sure I'll need it again in the future.
Ron
Ron - Gloucestershire, UK: AppGini Pro V 23.15 Rev 1484 - LOVING IT!
Plugins: Mass Update + Search Page Maker + Summary Reports + Calendar + Messages
Bizzworxx: AppGiniHelper + Inline Detail View
Alejandro Landini: To-Do List + MPI + TV Field Editor
Other: Udemy Course

Post Reply