From 043c8d45b7605be20cbf810fb12d2c0109c50be2 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Fri, 14 Sep 2018 00:18:21 +0200 Subject: [PATCH] Implemented Reciever --- application/config/packages/doctrine.yaml | 1 + application/src/DBAL/Types/RecieverType.php | 23 ++++++++++++++++++ ...onAttribut.php => PermissionsAttribut.php} | 8 ++++++- .../Attribut/PermissionsAttributInterface.php | 3 +++ .../src/Entity/Attribut/RecieverAttribut.php | 24 +++++++++++++++++++ .../Attribut/RecieverAttributInterface.php | 13 ++++++++++ application/src/Entity/Node.php | 14 +++++++++++ application/src/Entity/Permission.php | 19 ++++++++++++++- .../src/Entity/PermissionInterface.php | 3 ++- application/src/Entity/Right.php | 4 ++-- 10 files changed, 107 insertions(+), 5 deletions(-) create mode 100644 application/src/DBAL/Types/RecieverType.php rename application/src/Entity/Attribut/{PermissionAttribut.php => PermissionsAttribut.php} (68%) create mode 100644 application/src/Entity/Attribut/RecieverAttribut.php create mode 100644 application/src/Entity/Attribut/RecieverAttributInterface.php diff --git a/application/config/packages/doctrine.yaml b/application/config/packages/doctrine.yaml index f7fbb4e..a148a44 100644 --- a/application/config/packages/doctrine.yaml +++ b/application/config/packages/doctrine.yaml @@ -17,6 +17,7 @@ doctrine: url: '%env(resolve:DATABASE_URL)%' types: RightType: App\DBAL\Types\RightType + RecieverType: App\DBAL\Types\RecieverType orm: auto_generate_proxy_classes: '%kernel.debug%' naming_strategy: doctrine.orm.naming_strategy.underscore diff --git a/application/src/DBAL/Types/RecieverType.php b/application/src/DBAL/Types/RecieverType.php new file mode 100644 index 0000000..07f3611 --- /dev/null +++ b/application/src/DBAL/Types/RecieverType.php @@ -0,0 +1,23 @@ + 'node', + self::PARENTS => 'parents', + self::CHILDREN => 'children', + ]; +} diff --git a/application/src/Entity/Attribut/PermissionAttribut.php b/application/src/Entity/Attribut/PermissionsAttribut.php similarity index 68% rename from application/src/Entity/Attribut/PermissionAttribut.php rename to application/src/Entity/Attribut/PermissionsAttribut.php index fcffbb5..fbfdd85 100644 --- a/application/src/Entity/Attribut/PermissionAttribut.php +++ b/application/src/Entity/Attribut/PermissionsAttribut.php @@ -3,11 +3,12 @@ namespace App\Entity\Attribut; use Doctrine\Common\Collections\ArrayCollection; +use App\Entity\PermissionInterface; /** * @author kevinfrantz */ -trait PermissionAttribut +trait PermissionsAttribut { /** * @var ArrayCollection @@ -23,4 +24,9 @@ trait PermissionAttribut { return $this->permissions; } + + public function addPermission(PermissionInterface $permission): void + { + $this->permissions->add($permission); + } } diff --git a/application/src/Entity/Attribut/PermissionsAttributInterface.php b/application/src/Entity/Attribut/PermissionsAttributInterface.php index 700c72e..94e85b6 100644 --- a/application/src/Entity/Attribut/PermissionsAttributInterface.php +++ b/application/src/Entity/Attribut/PermissionsAttributInterface.php @@ -3,6 +3,7 @@ namespace App\Entity\Attribut; use Doctrine\Common\Collections\ArrayCollection; +use App\Entity\PermissionInterface; /** * @author kevinfrantz @@ -12,4 +13,6 @@ interface PermissionsAttributInterface public function setPermissions(ArrayCollection $permissions): void; public function getPermissions(): ArrayCollection; + + public function addPermission(PermissionInterface $permission): void; } diff --git a/application/src/Entity/Attribut/RecieverAttribut.php b/application/src/Entity/Attribut/RecieverAttribut.php new file mode 100644 index 0000000..be92e6b --- /dev/null +++ b/application/src/Entity/Attribut/RecieverAttribut.php @@ -0,0 +1,24 @@ +reciever = $type; + } + + public function getReciever(): string + { + return $this->reciever; + } +} diff --git a/application/src/Entity/Attribut/RecieverAttributInterface.php b/application/src/Entity/Attribut/RecieverAttributInterface.php new file mode 100644 index 0000000..0085ea9 --- /dev/null +++ b/application/src/Entity/Attribut/RecieverAttributInterface.php @@ -0,0 +1,13 @@ +law = new Law(); $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); + } } } diff --git a/application/src/Entity/Permission.php b/application/src/Entity/Permission.php index 58a2977..07ee4af 100644 --- a/application/src/Entity/Permission.php +++ b/application/src/Entity/Permission.php @@ -7,6 +7,9 @@ use App\Entity\Attribut\BlacklistAttribut; use App\Entity\Attribut\WhitelistAttribut; use App\Entity\Attribut\NodeAttribut; use App\Entity\Attribut\RightAttribut; +use App\Entity\Attribut\RecieverAttribut; +use App\DBAL\Types\RecieverType; +use Fresh\DoctrineEnumBundle\Validator\Constraints as DoctrineAssert; /** * @author kevinfrantz @@ -15,7 +18,15 @@ use App\Entity\Attribut\RightAttribut; */ 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") @@ -46,4 +57,10 @@ class Permission extends AbstractEntity implements PermissionInterface * @var RightInterface */ protected $right; + + public function __construct() + { + $this->blacklist = false; + $this->whitelist = false; + } } diff --git a/application/src/Entity/PermissionInterface.php b/application/src/Entity/PermissionInterface.php index e8db967..81ac55f 100644 --- a/application/src/Entity/PermissionInterface.php +++ b/application/src/Entity/PermissionInterface.php @@ -6,10 +6,11 @@ use App\Entity\Attribut\BlacklistAttributInterface; use App\Entity\Attribut\WhitelistAttributInterface; use App\Entity\Attribut\NodeAttributInterface; use App\Entity\Attribut\RightAttributInterface; +use App\Entity\Attribut\RecieverAttributInterface; /** * @author kevinfrantz */ -interface PermissionInterface extends BlacklistAttributInterface, WhitelistAttributInterface, NodeAttributInterface, RightAttributInterface +interface PermissionInterface extends BlacklistAttributInterface, WhitelistAttributInterface, NodeAttributInterface, RightAttributInterface, RecieverAttributInterface { } diff --git a/application/src/Entity/Right.php b/application/src/Entity/Right.php index cdb0452..06fe683 100644 --- a/application/src/Entity/Right.php +++ b/application/src/Entity/Right.php @@ -8,7 +8,7 @@ use App\DBAL\Types\RightType; use Doctrine\ORM\Mapping as ORM; use Fresh\DoctrineEnumBundle\Validator\Constraints as DoctrineAssert; use App\Entity\Attribut\LawAttribut; -use App\Entity\Attribut\PermissionAttribut; +use App\Entity\Attribut\PermissionsAttribut; /** * @author kevinfrantz @@ -17,7 +17,7 @@ use App\Entity\Attribut\PermissionAttribut; */ class Right extends AbstractEntity implements RightInterface { - use TypeAttribut,LawAttribut,PermissionAttribut; + use TypeAttribut,LawAttribut,PermissionsAttribut; /** * @ORM\ManyToOne(targetEntity="Law")