Implemented Reciever

This commit is contained in:
Kevin Frantz 2018-09-14 00:18:21 +02:00
parent 8a5efb2e1f
commit 043c8d45b7
10 changed files with 107 additions and 5 deletions

View File

@ -17,6 +17,7 @@ doctrine:
url: '%env(resolve:DATABASE_URL)%' url: '%env(resolve:DATABASE_URL)%'
types: types:
RightType: App\DBAL\Types\RightType RightType: App\DBAL\Types\RightType
RecieverType: App\DBAL\Types\RecieverType
orm: orm:
auto_generate_proxy_classes: '%kernel.debug%' auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore naming_strategy: doctrine.orm.naming_strategy.underscore

View File

@ -0,0 +1,23 @@
<?php
namespace App\DBAL\Types;
use Fresh\DoctrineEnumBundle\DBAL\Types\AbstractEnumType;
/**
* @author kevinfrantz
*/
final class RecieverType extends AbstractEnumType
{
public const NODE = 'node';
public const PARENTS = 'parents';
public const CHILDREN = 'children';
protected static $choices = [
self::NODE => 'node',
self::PARENTS => 'parents',
self::CHILDREN => 'children',
];
}

View File

@ -3,11 +3,12 @@
namespace App\Entity\Attribut; namespace App\Entity\Attribut;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\PermissionInterface;
/** /**
* @author kevinfrantz * @author kevinfrantz
*/ */
trait PermissionAttribut trait PermissionsAttribut
{ {
/** /**
* @var ArrayCollection * @var ArrayCollection
@ -23,4 +24,9 @@ trait PermissionAttribut
{ {
return $this->permissions; return $this->permissions;
} }
public function addPermission(PermissionInterface $permission): void
{
$this->permissions->add($permission);
}
} }

View File

@ -3,6 +3,7 @@
namespace App\Entity\Attribut; namespace App\Entity\Attribut;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\PermissionInterface;
/** /**
* @author kevinfrantz * @author kevinfrantz
@ -12,4 +13,6 @@ interface PermissionsAttributInterface
public function setPermissions(ArrayCollection $permissions): void; public function setPermissions(ArrayCollection $permissions): void;
public function getPermissions(): ArrayCollection; public function getPermissions(): ArrayCollection;
public function addPermission(PermissionInterface $permission): void;
} }

View File

@ -0,0 +1,24 @@
<?php
namespace App\Entity\Attribut;
/**
* @author kevinfrantz
*/
trait RecieverAttribut
{
/**
* @var string
*/
protected $reciever;
public function setReciever(string $type): void
{
$this->reciever = $type;
}
public function getReciever(): string
{
return $this->reciever;
}
}

View File

@ -0,0 +1,13 @@
<?php
namespace App\Entity\Attribut;
/**
* @author kevinfrantz
*/
interface RecieverAttributInterface
{
public function setReciever(string $type): void;
public function getReciever(): string;
}

View File

@ -42,5 +42,19 @@ class Node extends AbstractEntity implements NodeInterface
{ {
$this->law = new Law(); $this->law = new Law();
$this->law->setNode($this); $this->law->setNode($this);
$this->initPermissions();
}
private function initPermissions(): void
{
/*
* @var RightInterface
*/
foreach ($this->law->getRights()->toArray() as $right) {
$permission = new Permission();
$permission->setNode($this);
$permission->setRight($right);
$right->addPermission($permission);
}
} }
} }

View File

@ -7,6 +7,9 @@ use App\Entity\Attribut\BlacklistAttribut;
use App\Entity\Attribut\WhitelistAttribut; use App\Entity\Attribut\WhitelistAttribut;
use App\Entity\Attribut\NodeAttribut; use App\Entity\Attribut\NodeAttribut;
use App\Entity\Attribut\RightAttribut; use App\Entity\Attribut\RightAttribut;
use App\Entity\Attribut\RecieverAttribut;
use App\DBAL\Types\RecieverType;
use Fresh\DoctrineEnumBundle\Validator\Constraints as DoctrineAssert;
/** /**
* @author kevinfrantz * @author kevinfrantz
@ -15,7 +18,15 @@ use App\Entity\Attribut\RightAttribut;
*/ */
class Permission extends AbstractEntity implements PermissionInterface class Permission extends AbstractEntity implements PermissionInterface
{ {
use BlacklistAttribut,WhitelistAttribut,NodeAttribut,RightAttribut; use NodeAttribut,RightAttribut,WhitelistAttribut,BlacklistAttribut,RecieverAttribut;
/**
* @ORM\Column(name="reciever", type="RecieverType", nullable=false)
* @DoctrineAssert\Enum(entity="App\DBAL\Types\RecieverType")
*
* @var string
*/
protected $reciever;
/** /**
* @ORM\Column(type="boolean") * @ORM\Column(type="boolean")
@ -46,4 +57,10 @@ class Permission extends AbstractEntity implements PermissionInterface
* @var RightInterface * @var RightInterface
*/ */
protected $right; protected $right;
public function __construct()
{
$this->blacklist = false;
$this->whitelist = false;
}
} }

View File

@ -6,10 +6,11 @@ use App\Entity\Attribut\BlacklistAttributInterface;
use App\Entity\Attribut\WhitelistAttributInterface; use App\Entity\Attribut\WhitelistAttributInterface;
use App\Entity\Attribut\NodeAttributInterface; use App\Entity\Attribut\NodeAttributInterface;
use App\Entity\Attribut\RightAttributInterface; use App\Entity\Attribut\RightAttributInterface;
use App\Entity\Attribut\RecieverAttributInterface;
/** /**
* @author kevinfrantz * @author kevinfrantz
*/ */
interface PermissionInterface extends BlacklistAttributInterface, WhitelistAttributInterface, NodeAttributInterface, RightAttributInterface interface PermissionInterface extends BlacklistAttributInterface, WhitelistAttributInterface, NodeAttributInterface, RightAttributInterface, RecieverAttributInterface
{ {
} }

View File

@ -8,7 +8,7 @@ use App\DBAL\Types\RightType;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Fresh\DoctrineEnumBundle\Validator\Constraints as DoctrineAssert; use Fresh\DoctrineEnumBundle\Validator\Constraints as DoctrineAssert;
use App\Entity\Attribut\LawAttribut; use App\Entity\Attribut\LawAttribut;
use App\Entity\Attribut\PermissionAttribut; use App\Entity\Attribut\PermissionsAttribut;
/** /**
* @author kevinfrantz * @author kevinfrantz
@ -17,7 +17,7 @@ use App\Entity\Attribut\PermissionAttribut;
*/ */
class Right extends AbstractEntity implements RightInterface class Right extends AbstractEntity implements RightInterface
{ {
use TypeAttribut,LawAttribut,PermissionAttribut; use TypeAttribut,LawAttribut,PermissionsAttribut;
/** /**
* @ORM\ManyToOne(targetEntity="Law") * @ORM\ManyToOne(targetEntity="Law")