This topic is locked
[SOLVED]

 Dynamic Permissions - Can more than one user "own" the same record?

11/12/2013 9:02:22 AM
PHPRunner General questions
D
DUKE author

At this stage I have no problem using dynamic permissions when each record in a table is "owned" by one user.
Is there any way of implementing a situation where a specific record can have multiple owners?
ie:
a field called "Owners" storing the following: "1,5,11,89,23" which are the User IDs of all the users "owning" that record.

Sergey Kornilov admin 11/12/2013

Yes, this is possible, some manual coding will be required.
You can use 'Dynamic SQL Query' approach to only list records that belong to certain person:

http://xlinesoft.com/phprunner/docs/modify_sql_query_on_the_fly.htm
For instance, if user id is stored in the session variable $_SESSION["id"] here is the query you can try:

$query->addWhere("Owners like '".$_SESSION["id"].",%' or Owners like '%,"$_SESSION["id"]",%'or Owners like '%,".$_SESSION["id"]."'");


This WHERE clause covers scenarios when ID of the current user is in the beginning, in the middle or at the end of Owners field.

D
DUKE author 11/26/2013

Hi Sergey,
This works perfectly. Thanks!



Yes, this is possible, some manual coding will be required.
You can use 'Dynamic SQL Query' approach to only list records that belong to certain person:

http://xlinesoft.com/phprunner/docs/modify_sql_query_on_the_fly.htm
For instance, if user id is stored in the session variable $_SESSION["id"] here is the query you can try:

$query->addWhere("Owners like '".$_SESSION["id"].",%' or Owners like '%,"$_SESSION["id"]",%'or Owners like '%,".$_SESSION["id"]."'");


This WHERE clause covers scenarios when ID of the current user is in the beginning, in the middle or at the end of Owners field.