Optimized law draft

This commit is contained in:
Kevin Frantz 2018-09-13 16:37:33 +02:00
parent b9f483bf7f
commit 92886a14ce
9 changed files with 31 additions and 12 deletions

View File

@ -1,5 +1,5 @@
<?php <?php
namespace Entity\Attribut; namespace App\Entity\Attribut;
use App\Entity\RightInterface; use App\Entity\RightInterface;

View File

@ -1,5 +1,5 @@
<?php <?php
namespace Entity\Attribut; namespace App\Entity\Attribut;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;

View File

@ -1,5 +1,5 @@
<?php <?php
namespace Entity\Attribut; namespace App\Entity\Attribut;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;

View File

@ -13,7 +13,7 @@ trait TypeAttribut {
*/ */
protected $type; protected $type;
public function setType(string $right):void{ public function setType(string $type):void{
$this->type = $type; $this->type = $type;
} }

View File

@ -8,7 +8,7 @@ namespace App\Entity\Attribut;
*/ */
interface TypeAttributInterface interface TypeAttributInterface
{ {
public function setType(string $right):void; public function setType(string $type):void;
public function getType():string; public function getType():string;
} }

View File

@ -2,9 +2,10 @@
namespace App\Entity; namespace App\Entity;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use 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\DBAL\Types\RightType;
use App\Entity\Attribut\NodeAttribut;
/** /**
* *
@ -14,7 +15,7 @@ use App\DBAL\Types\RightType;
*/ */
class Law extends AbstractEntity implements LawInterface class Law extends AbstractEntity implements LawInterface
{ {
use RightsAttribute; use RightsAttribute, NodeAttribut;
/** /**
* *
@ -23,17 +24,25 @@ class Law extends AbstractEntity implements LawInterface
*/ */
protected $rights; protected $rights;
/**
* @ORM\OneToOne(targetEntity="Node",cascade={"persist", "remove"})
* @ORM\JoinColumn(name="node_id", referencedColumnName="id")
* @var NodeInterface
*/
protected $node;
public function __construct() public function __construct()
{ {
parent::__contruct();
$this->initAllRights(); $this->initAllRights();
} }
private function initAllRights(): void private function initAllRights(): void
{ {
$this->rights = new ArrayCollection();
foreach (RightType::getChoices() as $key=>$value){ foreach (RightType::getChoices() as $key=>$value){
$right = new Right(); $right = new Right();
$right->setType($value); $right->setType($value);
$right->setLaw($this);
$this->rights->set($key, $right); $this->rights->set($key, $right);
} }
} }

View File

@ -1,7 +1,7 @@
<?php <?php
namespace App\Entity; namespace App\Entity;
use Entity\Attribut\RightsAttributInterface; use App\Entity\Attribut\RightsAttributInterface;
/** /**
* *

View File

@ -6,16 +6,25 @@ use App\Entity\Attribut\TypeAttribut;
use App\DBAL\Types\RightType; use App\DBAL\Types\RightType;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Fresh\DoctrineEnumBundle\Validator\Constraints as DoctrineAssert; use Fresh\DoctrineEnumBundle\Validator\Constraints as DoctrineAssert;
use App\Entity\Attribut\LawAttributInterface;
use App\Entity\Attribut\LawAttribut;
/** /**
* *
* @author kevinfrantz * @author kevinfrantz
* @ORM\Table(name="right") * @ORM\Table(name="`right`")
* @ORM\Entity(repositoryClass="App\Repository\RightRepository") * @ORM\Entity(repositoryClass="App\Repository\RightRepository")
*/ */
class Right extends AbstractEntity implements RightInterface class Right extends AbstractEntity implements RightInterface
{ {
use TypeAttribut; use TypeAttribut,LawAttribut;
/**
* @ORM\ManyToOne(targetEntity="Law",cascade={"persist", "remove"})
* @ORM\JoinColumn(name="law_id", referencedColumnName="id")
* @var LawInterface
*/
protected $law;
/** /**
* @ORM\Column(name="type", type="RightType", nullable=false) * @ORM\Column(name="type", type="RightType", nullable=false)

View File

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