src/Entity/JournalDomain.php line 46
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups,
Symfony\Component\Validator\Constraints as Assert;
use ApiPlatform\Metadata\ApiResource,
ApiPlatform\Metadata\ApiProperty,
ApiPlatform\Metadata\Get,
ApiPlatform\Metadata\GetCollection,
ApiPlatform\Metadata\Post,
ApiPlatform\Metadata\Put,
ApiPlatform\Metadata\Delete,
ApiPlatform\Metadata\ApiFilter,
ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
use App\Entity\Trait\IdTrait,
App\Entity\Trait\UuidTrait,
App\Entity\Trait\OrdStatTrait,
App\Entity\Trait\TimestampableTrait,
App\Entity\Interface\OrdStatableInterface,
App\Repository\JournalDomainRepository;
use App\Filter\IriFilter;
#[ApiResource(
description: 'Journal domains',
normalizationContext: ['groups' => ['read', 'read:' . self::class]],
denormalizationContext: ['groups' => ['write']],
security: 'is_granted("' . Journal::class . '")',
order: ['ord' => 'desc'],
operations: [
new GetCollection(),
new Post(denormalizationContext: ['groups' => ['write', 'post']]),
new Get(),
new Put(),
new Delete(),
],
extraProperties: ['standard_put' => false],
)]
#[ApiFilter(IriFilter::class, properties: ['parent'])]
#[ApiFilter(OrderFilter::class, properties: ['ord'])]
#[ORM\Entity(repositoryClass: JournalDomainRepository::class)]
class JournalDomain implements OrdStatableInterface
{
use IdTrait,
UuidTrait,
OrdStatTrait,
TimestampableTrait;
#[ApiProperty(description: 'Parent', readableLink: false, writableLink: false)]
#[Groups(['read', 'post'])]
#[Assert\NotNull]
#[ORM\ManyToOne(targetEntity: Journal::class, inversedBy: 'domains')]
#[ORM\JoinColumn(onDelete: 'cascade', nullable: false)]
private Journal $parent;
#[ApiProperty(description: 'Domain', writableLink: false)]
#[Groups(['read', 'write'])]
#[Assert\NotNull]
#[ORM\ManyToOne(targetEntity: Domain::class)]
#[ORM\JoinColumn(onDelete: 'cascade', nullable: false)]
private Domain $domain;
public function __construct(Journal $parent, Domain $domain)
{
$this->setUuid();
$this->parent = $parent;
$this->setDomain($domain);
$this->createdAt = new \DateTimeImmutable();
$this->updatedAt = new \DateTimeImmutable();
$parent->addDomain($this);
}
public function getParent(): Journal
{
return $this->parent;
}
public function getDomain(): Domain
{
return $this->domain;
}
public function setDomain(Domain $domain): self
{
$this->domain = $domain;
if (null === $domain->getParent()) {
return $this;
}
$parent = $domain->getParent();
foreach($this->parent->getDomains() as $domain) {
if ($domain === $parent) {
return $this;
}
}
new JournalDomain($this->parent, $parent);
return $this;
}
}