infinito/application/src/Entity/Law.php

51 lines
1.2 KiB
PHP
Raw Normal View History

2018-09-13 14:39:03 +02:00
<?php
2018-09-13 16:51:58 +02:00
2018-09-13 14:39:03 +02:00
namespace App\Entity;
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;
use App\DBAL\Types\RightType;
2018-09-13 16:37:33 +02:00
use App\Entity\Attribut\NodeAttribut;
2018-09-13 14:39:03 +02:00
/**
* @author kevinfrantz
2018-09-13 15:55:48 +02:00
* @ORM\Table(name="law")
* @ORM\Entity(repositoryClass="App\Repository\LawRepository")
2018-09-13 14:39:03 +02:00
*/
2018-09-13 15:55:48 +02:00
class Law extends AbstractEntity implements LawInterface
2018-09-13 14:39:03 +02:00
{
2018-09-13 16:37:33 +02:00
use RightsAttribute, NodeAttribut;
2018-09-13 15:55:48 +02:00
/**
* @ORM\OneToMany(targetEntity="Right", mappedBy="id", cascade={"persist", "remove"})
2018-09-13 16:51:58 +02:00
*
2018-09-13 15:55:48 +02:00
* @var ArrayCollection
*/
protected $rights;
2018-09-13 16:37:33 +02:00
/**
* @ORM\OneToOne(targetEntity="Node",cascade={"persist", "remove"})
* @ORM\JoinColumn(name="node_id", referencedColumnName="id")
2018-09-13 16:51:58 +02:00
*
2018-09-13 16:37:33 +02:00
* @var NodeInterface
*/
protected $node;
2018-09-13 16:51:58 +02:00
2018-09-13 15:55:48 +02:00
public function __construct()
{
$this->initAllRights();
}
private function initAllRights(): void
{
2018-09-13 16:37:33 +02:00
$this->rights = new ArrayCollection();
2018-09-13 16:51:58 +02:00
foreach (RightType::getChoices() as $key => $value) {
2018-09-13 15:55:48 +02:00
$right = new Right();
$right->setType($value);
2018-09-13 16:37:33 +02:00
$right->setLaw($this);
2018-09-13 15:55:48 +02:00
$this->rights->set($key, $right);
}
}
2018-09-13 14:39:03 +02:00
}