Optimized Law draft

This commit is contained in:
Kevin Frantz 2018-09-13 22:35:32 +02:00
parent 69f2beac72
commit ff7fb57baf
13 changed files with 160 additions and 30 deletions

View File

@ -20,4 +20,8 @@ class AbstractEntity
* @var int
*/
protected $id;
protected function __construct()
{
}
}

View File

@ -27,6 +27,7 @@ abstract class AbstractSource extends AbstractEntity implements SourceInterface
public function __construct()
{
parent::__construct();
$this->node = new Node();
$this->node->setSource($this);
}

View File

@ -1,9 +1,6 @@
<?php
namespace App\Entity\Attribut;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\NodeInterface;
namespace Entity\Attribut;
/**
* @author kevinfrantz
@ -11,25 +8,17 @@ use App\Entity\NodeInterface;
trait ParentAttribut
{
/**
* Many Nodes have many parents.
*
* @ORM\ManyToMany(targetEntity="Node")
* @ORM\JoinTable(name="nodes_parents",
* joinColumns={@ORM\JoinColumn(name="node_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="node_id", referencedColumnName="id")}
* )
*
* @var ArrayCollection|NodeInterface[]
* @var ParentAttributInterface
*/
protected $parents;
protected $parent;
public function getParents(): ArrayCollection
public function setParent(ParentAttributInterface $parent): void
{
return $this->parents;
$this->parent = $parent;
}
public function setParents(ArrayCollection $parents): void
public function getParent(): ParentAttributInterface
{
$this->parents = $parents;
return $this->parent;
}
}

View File

@ -0,0 +1,13 @@
<?php
namespace Entity\Attribut;
/**
* @author kevinfrantz
*/
interface ParentAttributInterface
{
public function setParent(ParentAttributInterface $parent): void;
public function getParent(): ParentAttributInterface;
}

View File

@ -0,0 +1,35 @@
<?php
namespace App\Entity\Attribut;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\NodeInterface;
/**
* @author kevinfrantz
*/
trait ParentsAttribut
{
/**
* Many Nodes have many parents.
*
* @ORM\ManyToMany(targetEntity="Node")
* @ORM\JoinTable(name="nodes_parents",
* joinColumns={@ORM\JoinColumn(name="node_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="node_id", referencedColumnName="id")}
* )
*
* @var ArrayCollection|NodeInterface[]
*/
protected $parents;
public function getParents(): ArrayCollection
{
return $this->parents;
}
public function setParents(ArrayCollection $parents): void
{
$this->parents = $parents;
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace App\Entity\Attribut;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @author kevinfrantz
*/
trait PermissionAttribut
{
/**
* @var ArrayCollection
*/
protected $permissions;
public function setPermissions(ArrayCollection $permissions): void
{
$this->permissions = $permissions;
}
public function getPermissions(): ArrayCollection
{
return $this->permissions;
}
}

View File

@ -0,0 +1,15 @@
<?php
namespace App\Entity\Attribut;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @author kevinfrantz
*/
interface PermissionsAttributInterface
{
public function setPermissions(ArrayCollection $permissions): void;
public function getPermissions(): ArrayCollection;
}

View File

@ -0,0 +1,26 @@
<?php
namespace Entity\Attribut;
use App\Entity\RightInterface;
/**
* @author kevinfrantz
*/
trait RightAttribut
{
/**
* @var RightInterface
*/
protected $right;
public function setRight(RightInterface $right): void
{
$this->right = $right;
}
public function getRight(): RightInterface
{
return $this->getRight();
}
}

View File

@ -5,7 +5,7 @@ namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Attribut\IdAttribut;
use App\Entity\Attribut\SourceAttribut;
use App\Entity\Attribut\ParentAttribut;
use App\Entity\Attribut\ParentsAttribut;
use App\Entity\Attribut\ChildsAttribut;
use App\Entity\Attribut\LawAttribut;
@ -18,7 +18,7 @@ class Node extends AbstractEntity implements NodeInterface
{
use IdAttribut,
SourceAttribut,
ParentAttribut,
ParentsAttribut,
LawAttribut,
ChildsAttribut;

View File

@ -5,6 +5,8 @@ namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Attribut\BlacklistAttribut;
use App\Entity\Attribut\WhitelistAttribut;
use App\Entity\Attribut\NodeAttribut;
use Entity\Attribut\RightAttribut;
/**
* @author kevinfrantz
@ -13,7 +15,7 @@ use App\Entity\Attribut\WhitelistAttribut;
*/
class Permission extends AbstractEntity implements PermissionInterface
{
use BlacklistAttribut,WhitelistAttribut;
use BlacklistAttribut,WhitelistAttribut,NodeAttribut,RightAttribut;
/**
* @ORM\Column(type="boolean")
@ -28,4 +30,20 @@ class Permission extends AbstractEntity implements PermissionInterface
* @var bool
*/
protected $whitelist;
/**
* @ORM\ManyToOne(targetEntity="Node")
* @ORM\JoinColumn(name="node_id", referencedColumnName="id")
*
* @var NodeInterface
*/
protected $node;
/**
* @ORM\ManyToOne(targetEntity="Right")
* @ORM\JoinColumn(name="right_id", referencedColumnName="id")
*
* @var RightInterface
*/
protected $right;
}

View File

@ -4,10 +4,12 @@ namespace App\Entity;
use App\Entity\Attribut\BlacklistAttributInterface;
use Entity\Attribut\WhitelistAttributInterface;
use App\Entity\Attribut\NodeAttributInterface;
use App\Entity\Attribut\RightAttributInterface;
/**
* @author kevinfrantz
*/
interface PermissionInterface extends BlacklistAttributInterface, WhitelistAttributInterface
interface PermissionInterface extends BlacklistAttributInterface, WhitelistAttributInterface, NodeAttributInterface, RightAttributInterface
{
}

View File

@ -8,6 +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;
/**
* @author kevinfrantz
@ -16,10 +17,10 @@ use App\Entity\Attribut\LawAttribut;
*/
class Right extends AbstractEntity implements RightInterface
{
use TypeAttribut,LawAttribut;
use TypeAttribut,LawAttribut,PermissionAttribut;
/**
* @ORM\ManyToOne(targetEntity="Law",cascade={"persist", "remove"})
* @ORM\ManyToOne(targetEntity="Law")
* @ORM\JoinColumn(name="law_id", referencedColumnName="id")
*
* @var LawInterface
@ -35,7 +36,7 @@ class Right extends AbstractEntity implements RightInterface
protected $type;
/**
* @ORM\OneToMany(targetEntity="Right", mappedBy="id", cascade={"persist", "remove"})
* @ORM\OneToMany(targetEntity="Permission", mappedBy="id", cascade={"persist", "remove"})
*
* @var ArrayCollection
*/
@ -45,7 +46,9 @@ class Right extends AbstractEntity implements RightInterface
{
}
public function setPermissions(ArrayCollection $permissions): void
public function __construct()
{
parent::__construct();
$this->permissions = new ArrayCollection();
}
}

View File

@ -2,16 +2,14 @@
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Attribut\TypeAttributInterface;
use App\Entity\Attribut\LawAttributInterface;
use App\Entity\Attribut\PermissionsAttributInterface;
/**
* @author kevinfrantz
*/
interface RightInterface extends TypeAttributInterface, LawAttributInterface
interface RightInterface extends TypeAttributInterface, LawAttributInterface, PermissionsAttributInterface
{
public function isGranted(NodeInterface $node): bool;
public function setPermissions(ArrayCollection $permissions): void;
}