Optimized creation process

This commit is contained in:
Kevin Frantz 2018-09-21 16:27:49 +02:00
parent 54615a458e
commit 7c85b98df6
4 changed files with 34 additions and 13 deletions

View File

@ -0,0 +1,29 @@
<?php
namespace App\Creator\Modificator\Entity;
use App\DBAL\Types\LayerType;
use App\DBAL\Types\RightType;
use App\Entity\NodeInterface;
use App\Entity\Right;
use App\Entity\LawInterface;
/**
* @author kevinfrantz
*/
abstract class LawModificator
{
public static function grantAllRights(LawInterface $law, NodeInterface $node): void
{
foreach (LayerType::getChoices() as $layerKey => $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);
}
}
}
}

View File

@ -5,9 +5,7 @@ namespace App\Entity;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use App\Entity\Attribut\RightsAttribute; use App\Entity\Attribut\RightsAttribute;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use App\DBAL\Types\RightType;
use App\Entity\Attribut\NodeAttribut; use App\Entity\Attribut\NodeAttribut;
use App\DBAL\Types\LayerType;
/** /**
* @author kevinfrantz * @author kevinfrantz
@ -41,20 +39,12 @@ class Law extends AbstractEntity implements LawInterface
private function initAllRights(): void private function initAllRights(): void
{ {
$this->rights = new ArrayCollection(); $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 public function isGranted(NodeInterface $node, string $layer, string $right): bool
{ {
/** /*
*
* @var RightInterface * @var RightInterface
*/ */
foreach ($this->rights->toArray() as $right) { foreach ($this->rights->toArray() as $right) {

View File

@ -84,6 +84,7 @@ class Right extends AbstractEntity implements RightInterface
{ {
parent::__construct(); parent::__construct();
$this->grant = true; $this->grant = true;
$this->recieverGroup = new RecieverGroup();
} }
public function isGranted(NodeInterface $node, string $layer, string $right): bool public function isGranted(NodeInterface $node, string $layer, string $right): bool

View File

@ -7,6 +7,7 @@ use FOS\UserBundle\Model\User as BaseUser;
use App\Entity\Attribut\SourceAttributInterface; use App\Entity\Attribut\SourceAttributInterface;
use App\Entity\Attribut\SourceAttribut; use App\Entity\Attribut\SourceAttribut;
use App\Entity\Attribut\IdAttribut; use App\Entity\Attribut\IdAttribut;
use App\Creator\Modificator\Entity\LawModificator;
/** /**
* @author kevinfrantz * @author kevinfrantz
@ -41,6 +42,6 @@ class User extends BaseUser implements SourceAttributInterface
parent::__construct(); parent::__construct();
$this->isActive = true; $this->isActive = true;
$this->source = new UserSource(); $this->source = new UserSource();
$this->source->setUser($this); LawModificator::grantAllRights($this->source->getNode()->getLaw(), $this->source->getNode());
} }
} }