Set record owner of external records

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
mekin
Veteran Member
Posts: 40
Joined: 2019-04-22 17:09

Set record owner of external records

Post by mekin » 2019-06-21 11:16

Hello,

I have a question about the ownership of records by user or group.
The records added with the AppGini-database-app are all linked to a user or group in a table in the DB.
But what if I import records with Excel into the DB, are these records auto-linked to an user/group or must I set the memberrights somewhere?

gr. Mustafa.

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Set record owner of external records

Post by jsetzer » 2019-06-21 11:30

Hi Mustafa,

if you insert records using your own code, for example by using sql or importing via an external SQL-tool, you will have to set the owner by yourself.

The good thing is: There is a useful built-in AppGini-function for that: set_record_owner

Code: Select all

set_record_owner($tablename, $primary_key, $owner_memberID) -- Set/update the owner of given record
For example:

Code: Select all

// TODO: create your record in MyTable and get the new record's id
$id = ...; // the primary key of your new record

// set owner
$user = getLoggedMemberID();
set_record_owner("MyTable", $id, $user);
Hope this helps!

Regards,
Jan
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

mekin
Veteran Member
Posts: 40
Joined: 2019-04-22 17:09

Re: Set record owner of external records

Post by mekin » 2019-06-21 11:39

Hello Jan, thanks for the reply.

I have 2 questions:
1. Is there any way that I can "Set Owner" multiple records at ones?
2. Is the "$owner_memberID" linked to the group, so that the whole group of the user can also access the updated records?

And 1 sub-question (edited):
And haven't tested it yet, but what if a records doesn't have a owner, so the record doesn't exist in the membership-table.
How does the application react to this, does it hide the records?

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Set record owner of external records

Post by jsetzer » 2019-06-21 11:53

Hello!

Question 1:
Yes, there are several ways.
  1. Your can load all records using the built-in sql()-function and for each item call the set_record_owner()-function. This method is less efficient than the next one, but easy to implement.
  2. Have a look at membership_userrecords-table. This table is not complex. You can build an INSERT statement for all items of your table which do not yet exist in membership_userrecords-table and insert them using pure SQL. This is a bit more efficient but more complex. See columns "tableName" and "pkValue" in membership_userrecords-table.
Question 2:
When you are using the built-in set_record_owner()-function, you will have to pass a memberID. Then AppGini will automatically detect the member's group and assign the record to that user and his/her group. It depends on the configured permissions on that table who can see, edit or delete that record. You can control all permissions from the administration area of your AppGini app.

Hope this helps!
Regards,
Jan
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

Post Reply