Documentation

UserRoleManager extends StaticFactory

User Extended by Shawn Clake Class UserRoleManager User Extended is licensed under the MIT license.

Tags
author

Shawn Clake shawn.clake@gmail.com

link
https://github.com/ShawnClake/UserExtended
license

https://github.com/ShawnClake/UserExtended/blob/master/LICENSE MIT

Handles all interactions with roles on a user level

Table of Contents

$user  : mixed
The user instance
$userRoles  : mixed
A collection of User Roles Format like "groupCode" => RoleModel
__callStatic()  : mixed
Main factory function which utilizes PHP's magic method to call a suffixed factory function on the child class.
addRole()  : bool
Gives a user a role.
allRoles()  : $this
Preforms the logic for getting which roles the user is a part of TODO: Just utilize the 'roles' relation on the UserExtended user model if possible
currentUser()  :
currentUserFactory()  : $this
Used to setup the class using the logged in user
demote()  : $this
All in one function demotion of a user. Please read the promote documentation to learn how to use this function
factory()  : mixed
Helper function which can also be used to simply create an instance of a child class in cases where initialization functions aren't needed.
getRoleByGroup()  : mixed
Returns the users role for a specific group they are a part of.
getUsersRoles()  : mixed
Returns the collection of user roles
isInRole()  : bool
Returns whether or not the user is in a specific role
promote()  : $this
All in one function promotion of a user. Use case: Promote a user in a writer group from jr. writer to senior writer This does error checking, and saving.. Use eg: UserRoleManager::currentUser()->all()->promote('writer');
removeRole()  : bool
Removes a role from a user
saveRoles()  : $this
Saves changes made to a users roles. Useful ONLY for changing existing groups and roles and not useful for creating or deleting them.
setRoleByGroup()  : mixed
Sets the users role for a specific group they are a part of.
with()  :
withFactory()  : $this
Sets up the class using a User model

Properties

$userRoles

A collection of User Roles Format like "groupCode" => RoleModel

private mixed $userRoles

Methods

__callStatic()

Main factory function which utilizes PHP's magic method to call a suffixed factory function on the child class.

public static __callStatic( $name,  $arguments) : mixed
Parameters
$name :
$arguments :
Return values
mixed

addRole()

Gives a user a role.

public addRole( $roleCode) : bool

If they don't exist in the group required for the role yet, it will also add them to the group

Parameters
$roleCode :
Return values
bool

allRoles()

Preforms the logic for getting which roles the user is a part of TODO: Just utilize the 'roles' relation on the UserExtended user model if possible

public allRoles() : $this
Return values
$this

currentUser()

public static currentUser() :

UserRoleManager

Return values

currentUserFactory()

Used to setup the class using the logged in user

public currentUserFactory() : $this
Return values
$this

demote()

All in one function demotion of a user. Please read the promote documentation to learn how to use this function

public demote( $groupCode) : $this
Parameters
$groupCode :
Return values
$this

factory()

Helper function which can also be used to simply create an instance of a child class in cases where initialization functions aren't needed.

public static factory() : mixed

Generally you will want to use the static magic method below.

Return values
mixed

getRoleByGroup()

Returns the users role for a specific group they are a part of.

public getRoleByGroup( $groupCode) : mixed
Parameters
$groupCode :
Return values
mixed

getUsersRoles()

Returns the collection of user roles

public getUsersRoles() : mixed
Return values
mixed

isInRole()

Returns whether or not the user is in a specific role

public isInRole( $roleCode[, null $roles = null ]) : bool
Parameters
$roleCode :
$roles : null = null
Return values
bool

promote()

All in one function promotion of a user. Use case: Promote a user in a writer group from jr. writer to senior writer This does error checking, and saving.. Use eg: UserRoleManager::currentUser()->all()->promote('writer');

public promote( $groupCode) : $this
Parameters
$groupCode :
Return values
$this

removeRole()

Removes a role from a user

public removeRole( $roleCode) : bool
Parameters
$roleCode :
Return values
bool

saveRoles()

Saves changes made to a users roles. Useful ONLY for changing existing groups and roles and not useful for creating or deleting them.

public saveRoles() : $this
Return values
$this

setRoleByGroup()

Sets the users role for a specific group they are a part of.

public setRoleByGroup( $groupCode,  $role) : mixed

DOES NOT SAVE.

Parameters
$groupCode :
$role :
Return values
mixed

with()

public static with(mixed $user) :

UserRoleManager

Parameters
$user : mixed
Return values

withFactory()

Sets up the class using a User model

public withFactory([null $user = null ]) : $this
Parameters
$user : null = null
Return values
$this

Search results