Added new entity draft

This commit is contained in:
Kevin Frantz 2018-09-13 14:39:03 +02:00
parent 0ee29d3456
commit 00965aab5c
23 changed files with 331 additions and 34 deletions

View File

@ -0,0 +1,24 @@
<?php
namespace App\Entity;
use App\Entity\Attribut\IdAttribut;
use Doctrine\ORM\Mapping as ORM;
/**
*
* @author kevinfrantz
*
*/
class AbstractEntity
{
use IdAttribut;
/**
* @ORM\Id()
* @ORM\GeneratedValue
* @ORM\Column(type="integer")(strategy="AUTO")
* @var int
*/
protected $id;
}

View File

@ -2,7 +2,6 @@
namespace App\Entity; namespace App\Entity;
use App\Entity\Attribut\IdAttribut;
use App\Entity\Attribut\NodeAttribut; use App\Entity\Attribut\NodeAttribut;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
@ -13,13 +12,21 @@ use Doctrine\ORM\Mapping as ORM;
* @ORM\Entity * @ORM\Entity
* @ORM\InheritanceType("JOINED") * @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="discr", type="string") * @ORM\DiscriminatorColumn(name="discr", type="string")
* @ORM\DiscriminatorMap({"user" = "User"}) * @ORM\DiscriminatorMap({"user" = "UserSource"})
*/ */
abstract class AbstractSource implements SourceInterface abstract class AbstractSource extends AbstractEntity implements SourceInterface
{ {
use IdAttribut,NodeAttribut; use NodeAttribut;
/**
* @var NodeInterface
* @ORM\OneToOne(targetEntity="Node",cascade={"persist", "remove"})
* @ORM\JoinColumn(name="node_id", referencedColumnName="id")
*/
protected $node;
public function __construct(){ public function __construct(){
$this->node = new Node(); $this->node = new Node();
$this->node->setSource($this);
} }
} }

View File

@ -0,0 +1,15 @@
<?php
namespace App\Entity\Attribut;
/**
*
* @author kevinfrantz
*
*/
interface BlacklistAttributInterface
{
public function setBlacklist(?bool $value): void;
public function getBlacklist(): ?bool;
}

View File

@ -2,17 +2,13 @@
namespace App\Entity\Attribut; namespace App\Entity\Attribut;
use Doctrine\ORM\Mapping as ORM;
/** /**
* @author kevinfrantz * @author kevinfrantz
*/ */
trait IdAttribut trait IdAttribut
{ {
/** /**
* @ORM\Id() * @var int
* @ORM\GeneratedValue
* @ORM\Column(type="integer")(strategy="AUTO")
*/ */
protected $id; protected $id;

View File

@ -0,0 +1,26 @@
<?php
namespace App\Entity\Attribut;
use App\Entity\LawInterface;
/**
*
* @author kevinfrantz
*
*/
trait LawAttribut {
/**
* @var LawInterface
*/
protected $law;
public function setLaw(LawInterface $law):void{
$this->law = $law;
}
public function getLaw(): LawInterface{
return $this->law;
}
}

View File

@ -0,0 +1,18 @@
<?php
namespace App\Entity\Attribut;
use App\Entity\LawInterface;
/**
*
* @author kevinfrantz
*
*/
interface LawAttributInterface
{
public function setLaw(LawInterface $law):void;
public function getLaw(): LawInterface;
}

View File

@ -11,8 +11,6 @@ trait NodeAttribut
{ {
/** /**
* @var NodeInterface * @var NodeInterface
* @ORM\OneToOne(targetEntity="Node",cascade={"persist", "remove"})
* @ORM\JoinColumn(name="node_id", referencedColumnName="id")
*/ */
protected $node; protected $node;

View File

@ -0,0 +1,15 @@
<?php
namespace Entity\Attribut;
/**
*
* @author kevinfrantz
*
*/
interface RightAttributInterface
{
public function setRight(string $right):void;
public function getRight():string;
}

View File

@ -0,0 +1,26 @@
<?php
namespace App\Entity\Attribut;
use App\Entity\User;
/**
*
* @author kevinfrantz
*
*/
trait UserAttribut {
/**
* @var User
*/
protected $user;
public function setUser(User $user):void{
$this->user = $user;
}
public function getUser():User{
return $this->user;
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace App\Entity\Attribut;
use App\Entity\User;
/**
*
* @author kevinfrantz
*
*/
interface UserAttributInterface
{
public function setUser(User $user):void;
public function getUser():User;
}

View File

@ -0,0 +1,28 @@
<?php
namespace Entity\Attribut;
use App\Entity\UserSourceInterface;
/**
*
* @author kevinfrantz
*
*/
trait UserSource {
/**
*
* @var UserSourceInterface
* @ORM\OneToOne(targetEntity="UserSource",cascade={"persist", "remove"})
* @ORM\JoinColumn(name="source_user_id", referencedColumnName="id")
*/
protected $userSource;
public function setUserSource(UserSourceInterface $userSource):void{
$this->user = $userSource;
}
public function getUserSource():UserSourceInterface{
return $this->userSource;
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace Entity\Attribut;
use App\Entity\UserSourceInterface;
/**
*
* @author kevinfrantz
*
*/
interface UserSourceAttributInterface
{
public function setUserSource(UserSourceInterface $user):void;
public function getUserSource():UserSourceInterface;
}

View File

@ -0,0 +1,15 @@
<?php
namespace Entity\Attribut;
/**
*
* @author kevinfrantz
*
*/
interface WhitelistAttributInterface
{
public function setWhitelist(?bool $value): void;
public function getWhitelist(): ?bool;
}

View File

@ -0,0 +1,15 @@
<?php
namespace App\Entity;
use App\Entity\Attribut\NodeAttribut;
/**
*
* @author kevinfrantz
*
*/
class Law implements LawInterface
{
use NodeAttribut;
}

View File

@ -0,0 +1,14 @@
<?php
namespace App\Entity;
use App\Entity\Attribut\NodeAttributInterface;
/**
*
* @author kevinfrantz
*
*/
interface LawInterface extends NodeAttributInterface
{
}

View File

@ -7,16 +7,22 @@ use App\Entity\Attribut\IdAttribut;
use App\Entity\Attribut\SourceAttribut; use App\Entity\Attribut\SourceAttribut;
use App\Entity\Attribut\ParentAttribut; use App\Entity\Attribut\ParentAttribut;
use App\Entity\Attribut\ChildsAttribut; use App\Entity\Attribut\ChildsAttribut;
use App\Entity\Attribut\LawAttribut;
/** /**
* @author kevinfrantz * @author kevinfrantz
* @ORM\Table(name="node") * @ORM\Table(name="node")
* @ORM\Entity(repositoryClass="App\Repository\NodeRepository") * @ORM\Entity(repositoryClass="App\Repository\NodeRepository")
*/ */
class Node implements NodeInterface class Node extends AbstractEntity implements NodeInterface
{ {
use IdAttribut, use IdAttribut,
SourceAttribut, SourceAttribut,
ParentAttribut, ParentAttribut,
LawAttribut,
ChildsAttribut; ChildsAttribut;
public function __construct(){
$this->law = new Law();
}
} }

View File

@ -6,10 +6,11 @@ use App\Entity\Attribut\SourceAttributInterface;
use App\Entity\Attribut\IdAttributInterface; use App\Entity\Attribut\IdAttributInterface;
use App\Entity\Attribut\ParentsAttributInterface; use App\Entity\Attribut\ParentsAttributInterface;
use App\Entity\Attribut\ChildsAttributeInterface; use App\Entity\Attribut\ChildsAttributeInterface;
use App\Entity\Attribut\LawAttributInterface;
/** /**
* @author kevinfrantz * @author kevinfrantz
*/ */
interface NodeInterface extends SourceAttributInterface, IdAttributInterface, ParentsAttributInterface, ChildsAttributeInterface interface NodeInterface extends SourceAttributInterface, IdAttributInterface, ParentsAttributInterface, ChildsAttributeInterface, LawAttributInterface
{ {
} }

View File

@ -0,0 +1,15 @@
<?php
namespace Entity;
use App\Entity\Attribut\BlacklistAttributInterface;
use Entity\Attribut\WhitelistAttributInterface;
/**
*
* @author kevinfrantz
*
*/
interface PermissionInterface extends BlacklistAttributInterface, WhitelistAttributInterface
{
}

View File

@ -0,0 +1,12 @@
<?php
namespace App\Entity;
/**
*
* @author kevinfrantz
*
*/
interface RightInterface
{
}

View File

@ -4,16 +4,25 @@ namespace App\Entity;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser; use FOS\UserBundle\Model\User as BaseUser;
use App\Entity\Attribut\NodeAttribut; use App\Entity\Attribut\SourceAttributInterface;
use App\Entity\Attribut\SourceAttribut;
use App\Entity\Attribut\IdAttribut;
/** /**
* @author kevinfrantz * @author kevinfrantz
* @ORM\Table(name="source_user") * @ORM\Table(name="user")
* @ORM\Entity(repositoryClass="App\Repository\UserRepository") * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
*/ */
class User extends BaseUser implements SourceInterface class User extends BaseUser implements SourceAttributInterface
{ {
use NodeAttribut; use SourceAttribut,IdAttribut;
/**
* @var UserSourceInterface
* @ORM\OneToOne(targetEntity="UserSource",cascade={"persist", "remove"})
* @ORM\JoinColumn(name="source_user_id", referencedColumnName="id")
*/
protected $source;
/** /**
* @ORM\Column(name="is_active", type="boolean") * @ORM\Column(name="is_active", type="boolean")
@ -27,24 +36,10 @@ class User extends BaseUser implements SourceInterface
*/ */
protected $id; protected $id;
public function setId(int $id): void
{
$this->id = $id;
}
public function getId(): int
{
return $this->id;
}
public function __construct() public function __construct()
{ {
parent::__construct(); parent::__construct();
/*
* @todo Remove this later
* @var \App\Entity\User $isActive
*/
$this->isActive = true; $this->isActive = true;
$this->node = new Node(); $this->source = new UserSource();
} }
} }

View File

@ -0,0 +1,24 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Attribut\UserAttribut;
/**
*
* @author kevinfrantz
* @ORM\Table(name="source_user")
* @ORM\Entity(repositoryClass="App\Repository\UserSourceRepository")
*/
class UserSource extends AbstractSource implements UserSourceInterface
{
use UserAttribut;
/**
* @ORM\OneToOne(targetEntity="User")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
* @var User
*/
protected $user;
}

View File

@ -0,0 +1,14 @@
<?php
namespace App\Entity;
use App\Entity\Attribut\UserAttributInterface;
/**
*
* @author kevinfrantz
*
*/
interface UserSourceInterface extends SourceInterface, UserAttributInterface
{
}

View File

@ -69,7 +69,6 @@ A **node** MAY be a member of one or more **relative collection** s.
A **node** MAY be a member of one or more **collection** entity. A **node** MAY be a member of one or more **collection** entity.
A **node** MUST have a **law**. A **node** MUST have a **law**.
A **node** MUST have a **history**. A **node** MUST have a **history**.