mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-09-13 21:57:16 +02:00
Moved meta entities to meta
This commit is contained in:
13
application/src/Entity/Meta/AbstractMeta.php
Normal file
13
application/src/Entity/Meta/AbstractMeta.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace App\Entity\Meta;
|
||||
|
||||
use App\Entity\AbstractEntity;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*
|
||||
*/
|
||||
abstract class AbstractMeta extends AbstractEntity implements MetaInterface
|
||||
{
|
||||
}
|
60
application/src/Entity/Meta/Law.php
Normal file
60
application/src/Entity/Meta/Law.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
namespace App\Entity\Meta;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use App\Entity\Attribut\RightsAttribute;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use App\Entity\Attribut\RelationAttribut;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author kevinfrantz
|
||||
* @ORM\Table(name="law")
|
||||
* @ORM\Entity(repositoryClass="App\Repository\LawRepository")
|
||||
*/
|
||||
class Law extends AbstractMeta implements LawInterface
|
||||
{
|
||||
use RightsAttribute, RelationAttribut;
|
||||
|
||||
/**
|
||||
*
|
||||
* @ORM\OneToMany(targetEntity="Right", mappedBy="law", cascade={"persist", "remove"})
|
||||
*
|
||||
* @var ArrayCollection | Right[]
|
||||
*/
|
||||
protected $rights;
|
||||
|
||||
/**
|
||||
*
|
||||
* @ORM\OneToOne(targetEntity="Relation",cascade={"persist", "remove"})
|
||||
* @ORM\JoinColumn(name="relation_id", referencedColumnName="id")
|
||||
*
|
||||
* @var RelationInterface
|
||||
*/
|
||||
protected $relation;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->initAllRights();
|
||||
}
|
||||
|
||||
private function initAllRights(): void
|
||||
{
|
||||
$this->rights = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function isGranted(RelationInterface $relation, string $layer, string $right): bool
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var RightInterface
|
||||
*/
|
||||
foreach ($this->rights->toArray() as $right) {
|
||||
if ($right->isGranted($relation, $layer, $right)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
14
application/src/Entity/Meta/LawInterface.php
Normal file
14
application/src/Entity/Meta/LawInterface.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\Meta;
|
||||
|
||||
use App\Entity\Attribut\RightsAttributInterface;
|
||||
use App\Entity\Attribut\RelationAttributInterface;
|
||||
use App\Entity\Method\RelationGrantedInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface LawInterface extends RightsAttributInterface, RelationGrantedInterface, RelationAttributInterface,MetaInterface
|
||||
{
|
||||
}
|
15
application/src/Entity/Meta/MetaInterface.php
Normal file
15
application/src/Entity/Meta/MetaInterface.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace App\Entity\Meta;
|
||||
|
||||
use App\Entity\EntityInterface;
|
||||
|
||||
/**
|
||||
* Meta entities contain informations which describe sources.
|
||||
* If you refer from a meta entity to an source be aware to catch infinite loops!
|
||||
* @author kevinfrantz
|
||||
*
|
||||
*/
|
||||
interface MetaInterface extends EntityInterface
|
||||
{
|
||||
}
|
||||
|
53
application/src/Entity/Meta/RecieverGroup.php
Normal file
53
application/src/Entity/Meta/RecieverGroup.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\Meta;
|
||||
|
||||
use App\Entity\Attribut\RecieverAttribut;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use App\DBAL\Types\RecieverType;
|
||||
use Symfony\Component\Intl\Exception\NotImplementedException;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Fresh\DoctrineEnumBundle\Validator\Constraints as DoctrineAssert;
|
||||
use App\Entity\Attribut\RelationAttribut;
|
||||
use App\Entity\Attribut\RelationAttributInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
* @ORM\Table(name="reciever_group")
|
||||
* @ORM\Entity()
|
||||
*/
|
||||
class RecieverGroup extends AbstractMeta implements RecieverGroupInterface
|
||||
{
|
||||
use RelationAttribut,RecieverAttribut;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="reciever", type="RecieverType", nullable=false)
|
||||
* @DoctrineAssert\Enum(entity="App\DBAL\Types\RecieverType")
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reciever;
|
||||
|
||||
/**
|
||||
* The node for which the right exists.
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="Relation")
|
||||
* @ORM\JoinColumn(name="relation_id", referencedColumnName="id")
|
||||
*
|
||||
* @var RelationAttributInterface
|
||||
*/
|
||||
protected $relation;
|
||||
|
||||
public function getAllRecievers(): ArrayCollection
|
||||
{
|
||||
switch ($this->reciever) {
|
||||
case RecieverType::PARENTS:
|
||||
return $this->node->getParents();
|
||||
case RecieverType::NODE:
|
||||
return new ArrayCollection([$this->node]);
|
||||
case RecieverType::CHILDREN:
|
||||
return $this->node->getChilds();
|
||||
}
|
||||
throw new NotImplementedException('Reciever '.$this->reciever.' not implemented.');
|
||||
}
|
||||
}
|
15
application/src/Entity/Meta/RecieverGroupInterface.php
Normal file
15
application/src/Entity/Meta/RecieverGroupInterface.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\Meta;
|
||||
|
||||
use App\Entity\Attribut\RecieverAttributInterface;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use App\Entity\Attribut\RelationAttributInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface RecieverGroupInterface extends RelationAttributInterface, RecieverAttributInterface,MetaInterface
|
||||
{
|
||||
public function getAllRecievers(): ArrayCollection;
|
||||
}
|
81
application/src/Entity/Meta/Relation.php
Normal file
81
application/src/Entity/Meta/Relation.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\Meta;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use App\Entity\Attribut\IdAttribut;
|
||||
use App\Entity\Attribut\SourceAttribut;
|
||||
use App\Entity\Attribut\ParentsAttribut;
|
||||
use App\Entity\Attribut\ChildsAttribut;
|
||||
use App\Entity\Attribut\LawAttribut;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use App\Entity\Source\SourceInterface;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
|
||||
/**
|
||||
* This class represents a relation.
|
||||
* It allows a better right management of the meta informations.
|
||||
* Also it is used to capsel the logic relation to an own logical unit.
|
||||
* @author kevinfrantz
|
||||
* @todo rename and refactor this class
|
||||
* @ORM\Table(name="node")
|
||||
* @ORM\Entity()
|
||||
*/
|
||||
class Relation extends AbstractMeta implements RelationInterface
|
||||
{
|
||||
use IdAttribut,
|
||||
SourceAttribut,
|
||||
ParentsAttribut,
|
||||
LawAttribut,
|
||||
ChildsAttribut;
|
||||
|
||||
/**
|
||||
* Parents represent the creators of the relation
|
||||
* @ORM\ManyToMany(targetEntity="Relation")
|
||||
* @ORM\JoinTable(name="relation_parents",
|
||||
* joinColumns={@ORM\JoinColumn(name="relation_id", referencedColumnName="id")},
|
||||
* inverseJoinColumns={@ORM\JoinColumn(name="relation_id", referencedColumnName="id")}
|
||||
* )
|
||||
*
|
||||
* @var Collection|RelationInterface[]
|
||||
*/
|
||||
protected $parents;
|
||||
|
||||
/**
|
||||
* Childs represent the by the object produced relations
|
||||
* @todo Replace this by self referencing
|
||||
* @see https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/association-mapping.html
|
||||
* @ORM\ManyToMany(targetEntity="Relation")
|
||||
* @ORM\JoinTable(name="relation_childs",
|
||||
* joinColumns={@ORM\JoinColumn(name="relation_id", referencedColumnName="id")},
|
||||
* inverseJoinColumns={@ORM\JoinColumn(name="relation_id", referencedColumnName="id")}
|
||||
* )
|
||||
*
|
||||
* @var Collection|RelationInterface[]
|
||||
*/
|
||||
protected $childs;
|
||||
|
||||
/**
|
||||
* @ORM\OneToOne(targetEntity="App\Entity\Source\AbstractSource",cascade={"persist", "remove"})
|
||||
* @ORM\JoinColumn(name="source_id", referencedColumnName="id")
|
||||
*
|
||||
* @var SourceInterface
|
||||
*/
|
||||
protected $source;
|
||||
|
||||
/**
|
||||
* @ORM\OneToOne(targetEntity="Law",cascade={"persist", "remove"})
|
||||
* @ORM\JoinColumn(name="law_id", referencedColumnName="id")
|
||||
*
|
||||
* @var LawInterface
|
||||
*/
|
||||
protected $law;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->law = new Law();
|
||||
$this->parents = new ArrayCollection();
|
||||
$this->childs = new ArrayCollection();
|
||||
$this->law->setNode($this);
|
||||
}
|
||||
}
|
16
application/src/Entity/Meta/RelationInterface.php
Normal file
16
application/src/Entity/Meta/RelationInterface.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\Meta;
|
||||
|
||||
use App\Entity\Attribut\SourceAttributInterface;
|
||||
use App\Entity\Attribut\IdAttributInterface;
|
||||
use App\Entity\Attribut\ParentsAttributInterface;
|
||||
use App\Entity\Attribut\ChildsAttributeInterface;
|
||||
use App\Entity\Attribut\LawAttributInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface RelationInterface extends SourceAttributInterface, IdAttributInterface, ParentsAttributInterface, ChildsAttributeInterface, LawAttributInterface,MetaInterface
|
||||
{
|
||||
}
|
112
application/src/Entity/Meta/Right.php
Normal file
112
application/src/Entity/Meta/Right.php
Normal file
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\Meta;
|
||||
|
||||
use App\Entity\Attribut\TypeAttribut;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Fresh\DoctrineEnumBundle\Validator\Constraints as DoctrineAssert;
|
||||
use App\Entity\Attribut\LawAttribut;
|
||||
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;
|
||||
use App\Entity\Attribut\RecieverGroupAttribut;
|
||||
use App\Entity\Attribut\LayerAttribut;
|
||||
use App\Entity\Attribut\RelationAttribut;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
* @ORM\Table(name="`right`")
|
||||
* @ORM\Entity(repositoryClass="App\Repository\RightRepository")
|
||||
*/
|
||||
class Right extends AbstractMeta implements RightInterface
|
||||
{
|
||||
use TypeAttribut,LawAttribut, RelationAttribut, GrantAttribut,ConditionAttribut,RecieverGroupAttribut,LayerAttribut;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Law", inversedBy="rights")
|
||||
* @ORM\JoinColumn(name="law_id", referencedColumnName="id")
|
||||
*
|
||||
* @var LawInterface
|
||||
*/
|
||||
protected $law;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="layer", type="LayerType", nullable=false)
|
||||
* @DoctrineAssert\Enum(entity="App\DBAL\Types\LayerType")
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $layer;
|
||||
|
||||
/**
|
||||
* @ORM\OneToOne(targetEntity="RecieverGroup",cascade={"persist", "remove"})
|
||||
* @ORM\JoinColumn(name="reciever_id", referencedColumnName="id")
|
||||
*
|
||||
* @var RecieverGroupInterface
|
||||
*/
|
||||
protected $recieverGroup;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="boolean",name="`grant`")
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $grant;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Relation")
|
||||
* @ORM\JoinColumn(name="relation_id", referencedColumnName="id")
|
||||
*
|
||||
* @var RelationInterface
|
||||
*/
|
||||
protected $relation;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="type", type="RightType", nullable=false)
|
||||
* @DoctrineAssert\Enum(entity="App\DBAL\Types\RightType")
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* @ORM\OneToOne(targetEntity="App\Entity\Source\Operation\AbstractOperation",cascade={"persist"})
|
||||
* @ORM\JoinColumn(name="operation_id", referencedColumnName="id",nullable=true)
|
||||
*
|
||||
* @var OperationInterface
|
||||
*/
|
||||
protected $condition;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->grant = true;
|
||||
//$this->node = new Node();
|
||||
//$this->recieverGroup = new RecieverGroup();
|
||||
}
|
||||
|
||||
public function isGranted(RelationInterface $relation, string $layer, string $right): bool
|
||||
{
|
||||
if ($this->layer == $layer && $this->type == $right && $this->checkIfNodeIsReciever($relation) && $this->getConditionBoolOrTrue()) {
|
||||
return $this->grant;
|
||||
}
|
||||
|
||||
return !($this->grant);
|
||||
}
|
||||
|
||||
private function getConditionBoolOrTrue(): bool
|
||||
{
|
||||
if ($this->hasCondition()) {
|
||||
return $this->condition->getResult()->getBool();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function checkIfNodeIsReciever(RelationInterface $relation): bool
|
||||
{
|
||||
return $this->recieverGroup->getAllRecievers()->contains($relation);
|
||||
}
|
||||
}
|
19
application/src/Entity/Meta/RightInterface.php
Normal file
19
application/src/Entity/Meta/RightInterface.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace App\Entity\Meta;
|
||||
|
||||
use App\Entity\Attribut\TypeAttributInterface;
|
||||
use App\Entity\Attribut\LawAttributInterface;
|
||||
use App\Entity\Attribut\RecieverGroupAttributInterface;
|
||||
use App\Entity\Attribut\GrantAttributInterface;
|
||||
use App\Entity\Attribut\ConditionAttributInterface;
|
||||
use App\Entity\Attribut\LayerAttributInterface;
|
||||
use App\Entity\Method\RelationGrantedInterface;
|
||||
use App\Entity\Attribut\RelationAttributInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface RightInterface extends TypeAttributInterface, LawAttributInterface, RelationGrantedInterface, GrantAttributInterface, RecieverGroupAttributInterface, RelationAttributInterface, ConditionAttributInterface, LayerAttributInterface, MetaInterface
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user