コード例 #1
0
ファイル: UserGroup.php プロジェクト: sammy8806/gsi_laravel
 public function revokePermissionByObject($object)
 {
     $className = get_class($object);
     $return = [];
     /** @var UserSightPermission[] $perm */
     $perm = UserSightPermission::where('appObjectId', '=', $object->id)->get();
     foreach ($perm as $p) {
         if ($p->sightPermissionTypes[0]->objectName == $className) {
             $return[] = $p->delete();
         }
     }
     return $return;
 }
コード例 #2
0
 /**
  * @param \Illuminate\Database\Eloquent\Model $type
  * @param $target_id
  * @param $perm_id
  *
  * @return int
  */
 protected function sight_perm_del($type, $target_id, $perm_id)
 {
     $target = $type::findOrFail($target_id);
     $perm = UserSightPermission::findOrFail($perm_id);
     return $target->sightPermissions()->detach($perm);
 }
コード例 #3
0
 public function edit($id)
 {
     // Sight Permission Types
     /** @var UserSightPermissionType $sightPermissionType */
     $sightPermissionTypes = [];
     foreach (UserSightPermissionType::all() as $sightPermissionType) {
         $sightPermissionTypes[$sightPermissionType->id] = $sightPermissionType->objectName;
     }
     // Sight Permissions
     $aff_sightPerms = [];
     foreach (User::find($id)->sightPermissions as $sightPermission) {
         $aff_sightPerms[] = $sightPermission->id;
     }
     $sightPermissions = [];
     /** @var UserSightPermission $sightPermission */
     foreach (UserSightPermission::all() as $sightPermission) {
         if (!in_array($sightPermission->id, $aff_sightPerms)) {
             $sightPermissions[$sightPermission->id] = $sightPermission->sightPermissionTypes[0]->objectName;
         }
     }
     return View::make('admin.user_edit', ['user' => User::findOrFail($id), 'sightPermissionTypes' => $sightPermissionTypes, 'sightPermissions' => $sightPermissions]);
 }