2018-09-13 15:55:48 +02:00
|
|
|
<?php
|
2018-09-13 16:51:58 +02:00
|
|
|
|
2018-10-28 15:25:32 +01:00
|
|
|
namespace App\Entity\Meta;
|
2018-09-13 15:55:48 +02:00
|
|
|
|
|
|
|
use App\Entity\Attribut\TypeAttribut;
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
use Fresh\DoctrineEnumBundle\Validator\Constraints as DoctrineAssert;
|
2018-09-13 16:37:33 +02:00
|
|
|
use App\Entity\Attribut\LawAttribut;
|
2018-09-21 15:48:23 +02:00
|
|
|
use App\DBAL\Types\LayerType;
|
|
|
|
use App\DBAL\Types\RightType;
|
|
|
|
use App\Entity\Attribut\GrantAttribut;
|
|
|
|
use App\Logic\Operation\OperationInterface;
|
|
|
|
use App\Entity\Attribut\ConditionAttribut;
|
2018-10-31 16:15:39 +01:00
|
|
|
use App\Entity\Attribut\RecieverAttribut;
|
2018-09-21 15:48:23 +02:00
|
|
|
use App\Entity\Attribut\LayerAttribut;
|
2018-10-27 14:56:26 +02:00
|
|
|
use App\Entity\Attribut\RelationAttribut;
|
2018-11-04 15:35:16 +01:00
|
|
|
use App\Entity\Source\SourceInterface;
|
2018-09-13 15:55:48 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author kevinfrantz
|
2018-10-28 15:41:43 +01:00
|
|
|
* @ORM\Table(name="meta_right")
|
2018-09-13 15:55:48 +02:00
|
|
|
* @ORM\Entity(repositoryClass="App\Repository\RightRepository")
|
|
|
|
*/
|
2018-10-28 20:28:29 +01:00
|
|
|
final class Right extends AbstractMeta implements RightInterface
|
2018-09-13 15:55:48 +02:00
|
|
|
{
|
2018-10-31 16:15:39 +01:00
|
|
|
use TypeAttribut,LawAttribut, RelationAttribut, GrantAttribut,ConditionAttribut,RecieverAttribut,LayerAttribut;
|
2018-09-13 16:51:58 +02:00
|
|
|
|
2018-09-13 16:37:33 +02:00
|
|
|
/**
|
2018-09-14 18:26:09 +02:00
|
|
|
* @ORM\ManyToOne(targetEntity="Law", inversedBy="rights")
|
2018-09-13 16:37:33 +02:00
|
|
|
* @ORM\JoinColumn(name="law_id", referencedColumnName="id")
|
2018-09-13 16:51:58 +02:00
|
|
|
*
|
2018-09-13 16:37:33 +02:00
|
|
|
* @var LawInterface
|
|
|
|
*/
|
|
|
|
protected $law;
|
2018-09-13 16:51:58 +02:00
|
|
|
|
2018-09-21 15:48:23 +02:00
|
|
|
/**
|
2018-09-21 16:44:58 +02:00
|
|
|
* @ORM\Column(name="layer", type="LayerType", nullable=false)
|
2018-09-21 15:48:23 +02:00
|
|
|
* @DoctrineAssert\Enum(entity="App\DBAL\Types\LayerType")
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $layer;
|
|
|
|
|
|
|
|
/**
|
2018-10-31 21:53:30 +01:00
|
|
|
* @ORM\OneToOne(targetEntity="Reciever",cascade={"persist", "remove"})
|
2018-09-21 15:48:23 +02:00
|
|
|
* @ORM\JoinColumn(name="reciever_id", referencedColumnName="id")
|
|
|
|
*
|
2018-10-31 16:15:39 +01:00
|
|
|
* @var RecieverInterface
|
2018-09-21 15:48:23 +02:00
|
|
|
*/
|
2018-10-31 16:15:39 +01:00
|
|
|
protected $reciever;
|
2018-09-21 15:48:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @ORM\Column(type="boolean",name="`grant`")
|
|
|
|
*
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
protected $grant;
|
|
|
|
|
2018-09-13 15:55:48 +02:00
|
|
|
/**
|
|
|
|
* @ORM\Column(name="type", type="RightType", nullable=false)
|
|
|
|
* @DoctrineAssert\Enum(entity="App\DBAL\Types\RightType")
|
2018-09-13 16:51:58 +02:00
|
|
|
*
|
2018-09-13 15:55:48 +02:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $type;
|
2018-09-13 16:51:58 +02:00
|
|
|
|
|
|
|
/**
|
2018-10-03 16:48:16 +02:00
|
|
|
* @ORM\OneToOne(targetEntity="App\Entity\Source\Operation\AbstractOperation",cascade={"persist"})
|
2018-09-21 19:43:48 +02:00
|
|
|
* @ORM\JoinColumn(name="operation_id", referencedColumnName="id",nullable=true)
|
|
|
|
*
|
2018-09-21 15:48:23 +02:00
|
|
|
* @var OperationInterface
|
2018-09-13 16:51:58 +02:00
|
|
|
*/
|
2018-09-21 15:48:23 +02:00
|
|
|
protected $condition;
|
2018-09-13 16:51:58 +02:00
|
|
|
|
2018-09-21 15:48:23 +02:00
|
|
|
public function __construct()
|
2018-09-13 16:51:58 +02:00
|
|
|
{
|
2018-09-21 15:48:23 +02:00
|
|
|
parent::__construct();
|
|
|
|
$this->grant = true;
|
2018-11-04 15:51:16 +01:00
|
|
|
$this->reciever = new Reciever();
|
2018-09-13 16:51:58 +02:00
|
|
|
}
|
2018-09-13 15:55:48 +02:00
|
|
|
|
2018-11-04 15:35:16 +01:00
|
|
|
public function isGranted(SourceInterface $source, string $layer, string $right): bool
|
2018-09-13 16:51:58 +02:00
|
|
|
{
|
2018-10-27 14:56:26 +02:00
|
|
|
if ($this->layer == $layer && $this->type == $right && $this->checkIfNodeIsReciever($relation) && $this->getConditionBoolOrTrue()) {
|
2018-09-21 15:48:23 +02:00
|
|
|
return $this->grant;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !($this->grant);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getConditionBoolOrTrue(): bool
|
|
|
|
{
|
|
|
|
if ($this->hasCondition()) {
|
|
|
|
return $this->condition->getResult()->getBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-10-27 14:56:26 +02:00
|
|
|
private function checkIfNodeIsReciever(RelationInterface $relation): bool
|
2018-09-21 15:48:23 +02:00
|
|
|
{
|
2018-10-27 14:56:26 +02:00
|
|
|
return $this->recieverGroup->getAllRecievers()->contains($relation);
|
2018-09-13 16:51:58 +02:00
|
|
|
}
|
2018-09-13 15:55:48 +02:00
|
|
|
}
|