I am using Yii2 basic and RBAC. I have a scenario where admin creates various centers. Then admin create users and assigns the users to these centers. Each centers has multiple users. Now these users create different persons record and each person can have access to records created by persons belonging to a particular center.
Say Center A has Two Users. User 1 and User 2 can create persons record. Now User 1 and User 2 can access these persons record. Other centers users cannot access these persons record created by either User 1 or User 2. Now In RBAC while creating rules first return statement is valid or second return statement is valid
Satement 1 :
return isset($params['model']) ? ('user-' . $params['model']->UserId == $user) :false ;
Statement 2 :
return isset($params['model']) ? ('center-' . $params['model']->CenterId== $user) :false ;
Users from one center can have access to persons record. But users from other centers should not be able to access these records.
Database Structure
Center Table
CenterId
CenterName
User Table
UserId
Name
Person Table
PersonId
CenterId
UserId
PersonName
Center_Assign
CenterAssignId
CenterId
UserId