2018-09-13 14:39:03 +02:00
|
|
|
<?php
|
2018-10-29 19:01:00 +01:00
|
|
|
|
2018-10-28 15:25:32 +01:00
|
|
|
namespace App\Entity\Meta;
|
2018-09-13 14:39:03 +02:00
|
|
|
|
2018-09-13 15:55:48 +02:00
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
2018-09-13 16:37:33 +02:00
|
|
|
use App\Entity\Attribut\RightsAttribute;
|
2018-09-13 15:55:48 +02:00
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
2018-10-27 14:56:26 +02:00
|
|
|
use App\Entity\Attribut\RelationAttribut;
|
2018-09-13 14:39:03 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author kevinfrantz
|
2018-10-28 15:41:43 +01:00
|
|
|
* @ORM\Table(name="meta_law")
|
2018-09-13 15:55:48 +02:00
|
|
|
* @ORM\Entity(repositoryClass="App\Repository\LawRepository")
|
2018-09-13 14:39:03 +02:00
|
|
|
*/
|
2018-10-28 20:28:29 +01:00
|
|
|
final class Law extends AbstractMeta implements LawInterface
|
2018-09-13 14:39:03 +02:00
|
|
|
{
|
2018-10-27 14:56:26 +02:00
|
|
|
use RightsAttribute, RelationAttribut;
|
2018-09-13 15:55:48 +02:00
|
|
|
|
|
|
|
/**
|
2018-09-14 18:26:09 +02:00
|
|
|
* @ORM\OneToMany(targetEntity="Right", mappedBy="law", cascade={"persist", "remove"})
|
2018-09-13 16:51:58 +02:00
|
|
|
*
|
2018-09-21 15:48:23 +02:00
|
|
|
* @var ArrayCollection | Right[]
|
2018-09-13 15:55:48 +02:00
|
|
|
*/
|
|
|
|
protected $rights;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->initAllRights();
|
|
|
|
}
|
|
|
|
|
|
|
|
private function initAllRights(): void
|
|
|
|
{
|
2018-09-13 16:37:33 +02:00
|
|
|
$this->rights = new ArrayCollection();
|
2018-09-13 15:55:48 +02:00
|
|
|
}
|
2018-09-21 15:48:23 +02:00
|
|
|
|
2018-10-27 14:56:26 +02:00
|
|
|
public function isGranted(RelationInterface $relation, string $layer, string $right): bool
|
2018-09-21 15:48:23 +02:00
|
|
|
{
|
2018-10-29 19:01:00 +01:00
|
|
|
/*
|
2018-10-28 15:25:32 +01:00
|
|
|
*
|
2018-09-21 15:48:23 +02:00
|
|
|
* @var RightInterface
|
|
|
|
*/
|
|
|
|
foreach ($this->rights->toArray() as $right) {
|
2018-10-27 14:56:26 +02:00
|
|
|
if ($right->isGranted($relation, $layer, $right)) {
|
2018-09-21 15:48:23 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2018-09-13 14:39:03 +02:00
|
|
|
}
|