From 7c85b98df6e67a0a595d06aa23091e1c4097643e Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Fri, 21 Sep 2018 16:27:49 +0200 Subject: [PATCH] Optimized creation process --- .../Modificator/Entity/LawModificator.php | 29 +++++++++++++++++++ application/src/Entity/Law.php | 14 ++------- application/src/Entity/Right.php | 1 + application/src/Entity/User.php | 3 +- 4 files changed, 34 insertions(+), 13 deletions(-) create mode 100644 application/src/Creator/Modificator/Entity/LawModificator.php diff --git a/application/src/Creator/Modificator/Entity/LawModificator.php b/application/src/Creator/Modificator/Entity/LawModificator.php new file mode 100644 index 0000000..b3bccf8 --- /dev/null +++ b/application/src/Creator/Modificator/Entity/LawModificator.php @@ -0,0 +1,29 @@ + $layerValue) { + foreach (RightType::getChoices() as $rightKey => $rightValue) { + $right = new Right(); + $right->setType($rightKey); + $right->setLaw($this); + $right->setLayer($layerKey); + $right->setNode($node); + $law->getRights()->add($right); + } + } + } +} diff --git a/application/src/Entity/Law.php b/application/src/Entity/Law.php index bc5c816..ca29369 100644 --- a/application/src/Entity/Law.php +++ b/application/src/Entity/Law.php @@ -5,9 +5,7 @@ namespace App\Entity; use Doctrine\ORM\Mapping as ORM; use App\Entity\Attribut\RightsAttribute; use Doctrine\Common\Collections\ArrayCollection; -use App\DBAL\Types\RightType; use App\Entity\Attribut\NodeAttribut; -use App\DBAL\Types\LayerType; /** * @author kevinfrantz @@ -41,20 +39,12 @@ class Law extends AbstractEntity implements LawInterface private function initAllRights(): void { $this->rights = new ArrayCollection(); - foreach (LayerType::getChoices() as $layerKey => $layerValue) { - foreach (RightType::getChoices() as $rightKey => $rightValue) { - $right = new Right(); - $right->setType($rightKey); - $right->setLaw($this); - $right->setLayer($layerKey); - $this->rights->add($right); - } - } } public function isGranted(NodeInterface $node, string $layer, string $right): bool { - /** + /* + * * @var RightInterface */ foreach ($this->rights->toArray() as $right) { diff --git a/application/src/Entity/Right.php b/application/src/Entity/Right.php index 8443c04..8ca0f64 100644 --- a/application/src/Entity/Right.php +++ b/application/src/Entity/Right.php @@ -84,6 +84,7 @@ class Right extends AbstractEntity implements RightInterface { parent::__construct(); $this->grant = true; + $this->recieverGroup = new RecieverGroup(); } public function isGranted(NodeInterface $node, string $layer, string $right): bool diff --git a/application/src/Entity/User.php b/application/src/Entity/User.php index 0cc5017..d2338f7 100644 --- a/application/src/Entity/User.php +++ b/application/src/Entity/User.php @@ -7,6 +7,7 @@ use FOS\UserBundle\Model\User as BaseUser; use App\Entity\Attribut\SourceAttributInterface; use App\Entity\Attribut\SourceAttribut; use App\Entity\Attribut\IdAttribut; +use App\Creator\Modificator\Entity\LawModificator; /** * @author kevinfrantz @@ -41,6 +42,6 @@ class User extends BaseUser implements SourceAttributInterface parent::__construct(); $this->isActive = true; $this->source = new UserSource(); - $this->source->setUser($this); + LawModificator::grantAllRights($this->source->getNode()->getLaw(), $this->source->getNode()); } }