diff --git a/src/UwPermissions/UwPermissions.php b/src/UwPermissions/UwPermissions.php index a97a2f87c33f4e026bd0d2aade1081e29d19ec89..6c1f0bac7b672d714869bb802a0ba665a9c5cc30 100644 --- a/src/UwPermissions/UwPermissions.php +++ b/src/UwPermissions/UwPermissions.php @@ -203,4 +203,43 @@ class UwPermissions { $uw_role['object']->save(); } } + + /** + * Add UW permission to roles and save. + * + * @parm array $permissions_to_add + * The array of permissions to be added. + */ + public static function uw_add_permissions(array $permissions_to_add) { + + // Get the UW roles. + $uw_roles = UwPermissions::uw_get_roles(); + + // The array of uw permissions. + $uw_permissions = UwPermissions::uw_get_permissions_array(); + + // Step through each of the permissions to add and get teh feature. + foreach ($permissions_to_add as $feature => $permission_to_add) { + + // Step through the feature and get the roles. + foreach ($permission_to_add as $permission => $roles) { + + // Step through each of the roles and grant the permission. + foreach ($roles as $role) { + + // Step through each of the permissions that need to be granted + // for that actually permission and grant them for the specified + // uw role. + foreach($uw_permissions[$feature][$permission][$role] as $uw_perm) { + + // Grant the permission for the specified role. + $uw_roles[$role]['object']->grantPermission($uw_perm); + } + } + } + } + + // Save the permissions. + UwPermissions::uw_save_permissions($uw_roles); + } } \ No newline at end of file