Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F56903543
AddToGroupUserAction.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
AddToGroupUserAction.php
View Options
<?php
/**
* _, __, _, _ __, _ _, _, _
* / \ |_) (_ | | \ | /_\ |\ |
* \ / |_) , ) | |_/ | | | | \|
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*
* Add to group user action class
*
* @package ObsidianWorkspaces
* @subpackage Auth
* @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @filesource
*
*/
namespace
Waystone\Workspaces\Engines\Auth\Actions
;
use
Waystone\Workspaces\Engines\Auth\UserAction
;
use
Waystone\Workspaces\Engines\Serialization\ArrayDeserializable
;
use
Exception
;
use
JsonSerializable
;
use
UserGroup
;
/**
* User action to add a user into a group
*/
class
AddToGroupUserAction
extends
UserAction
implements
ArrayDeserializable
,
JsonSerializable
{
/**
* @var UserGroup The group to add the user to
*/
public
$group
;
/**
* @var boolean Determines if the target user has to be added to the group
* in the quality of admin
*/
public
$isAdmin
;
/**
* Executes the user action
*/
public
function
run
()
{
if
(
$this
->
targetUser
->
isMemberOfGroup
(
$this
->
group
))
{
if
(
$this
->
isAdmin
)
{
//Promotes to admin if needed
$this
->
targetUser
->
addToGroup
(
$this
->
group
,
true
);
}
}
else
{
//Adds user to the group
$this
->
targetUser
->
addToGroup
(
$this
->
group
,
$this
->
isAdmin
);
}
}
/**
* Loads an AddToGroupUserAction instance from an object.
*
* @param array $data The associative array to deserialize
*
* @return AddToGroupUserAction The deserialized instance
* @throws Exception when the group code is not found
*/
public
static
function
loadFromArray
(
array
$data
)
:
self
{
$instance
=
new
AddToGroupUserAction
();
$instance
->
group
=
UserGroup
::
fromCode
(
$data
[
"code"
]);
$instance
->
isAdmin
=
(
$data
[
"isAdmin"
]
==
true
);
return
$instance
;
}
public
function
jsonSerialize
()
:
array
{
return
[
"code"
=>
$this
->
group
->
code
,
"isAdmin"
=>
$this
->
isAdmin
];
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Thu, Nov 12, 13:05 (1 w, 2 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4226894
Default Alt Text
AddToGroupUserAction.php (2 KB)
Attached To
Mode
rOBSIDIAN Obsidian Workspaces
Attached
Detach File
Event Timeline
Log In to Comment