Bristol SU Support Package
ModelPermission.php
Go to the documentation of this file.
1 <?php
2 
4 
9 
18 class ModelPermission extends Model
19 {
20  use HasRevisions;
21 
27  protected $table = 'model_permissions';
28 
34  protected $fillable = [
35  'ability',
36  'model',
37  'model_id',
38  'result',
39  'module_instance_id'
40  ];
41 
47  protected $casts = [
48  'result' => 'boolean'
49  ];
50 
58  public function moduleInstance()
59  {
60  return $this->belongsTo(ModuleInstance::class);
61  }
62 
72  public function scopeUser(Builder $query, ?int $userId = null, ?string $ability = null, ?int $moduleInstanceId = null)
73  {
74  $constraints = ['model' => 'user'];
75  if ($userId !== null) {
76  $constraints['model_id'] = $userId;
77  }
78  if ($ability !== null) {
79  $constraints['ability'] = $ability;
80  }
81  if ($moduleInstanceId !== null) {
82  $constraints['module_instance_id'] = $moduleInstanceId;
83  }
84  return $query->where($constraints);
85  }
86 
96  public function scopeLogic(Builder $query, ?int $logicId = null, ?string $ability = null, ?int $moduleInstanceId = null)
97  {
98  $constraints = ['model' => 'logic'];
99  if ($logicId !== null) {
100  $constraints['model_id'] = $logicId;
101  }
102  if ($ability !== null) {
103  $constraints['ability'] = $ability;
104  }
105  if ($moduleInstanceId !== null) {
106  $constraints['module_instance_id'] = $moduleInstanceId;
107  }
108  return $query->where($constraints);
109  }
110 
120  public function scopeGroup(Builder $query, ?int $groupId = null, ?string $ability = null, ?int $moduleInstanceId = null)
121  {
122  $constraints = ['model' => 'group'];
123  if ($groupId !== null) {
124  $constraints['model_id'] = $groupId;
125  }
126  if ($ability !== null) {
127  $constraints['ability'] = $ability;
128  }
129  if ($moduleInstanceId !== null) {
130  $constraints['module_instance_id'] = $moduleInstanceId;
131  }
132  return $query->where($constraints);
133  }
134 
144  public function scopeRole(Builder $query, ?int $roleId = null, ?string $ability = null, ?int $moduleInstanceId = null)
145  {
146  $constraints = ['model' => 'role'];
147  if ($roleId !== null) {
148  $constraints['model_id'] = $roleId;
149  }
150  if ($ability !== null) {
151  $constraints['ability'] = $ability;
152  }
153  if ($moduleInstanceId !== null) {
154  $constraints['module_instance_id'] = $moduleInstanceId;
155  }
156  return $query->where($constraints);
157  }
158 }
scopeGroup(Builder $query, ?int $groupId=null, ?string $ability=null, ?int $moduleInstanceId=null)
scopeRole(Builder $query, ?int $roleId=null, ?string $ability=null, ?int $moduleInstanceId=null)
scopeLogic(Builder $query, ?int $logicId=null, ?string $ability=null, ?int $moduleInstanceId=null)
scopeUser(Builder $query, ?int $userId=null, ?string $ability=null, ?int $moduleInstanceId=null)