src/Entity/JournalIssueSection.php line 48
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups,
Symfony\Component\Validator\Constraints as Assert,
Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
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\JournalIssueSectionRepository;
use App\Filter\IriFilter;
#[ApiResource(
description: 'Journal issue sections',
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'])]
#[UniqueEntity(fields: ['parent', 'section'])]
#[ORM\Entity(repositoryClass: JournalIssueSectionRepository::class)]
class JournalIssueSection implements OrdStatableInterface
{
use IdTrait,
UuidTrait,
OrdStatTrait,
TimestampableTrait;
#[ApiProperty(description: 'Parent', readableLink: false, writableLink: false)]
#[Groups(['read', 'post'])]
#[Assert\NotNull]
#[ORM\ManyToOne(targetEntity: JournalIssue::class, inversedBy: 'sections')]
#[ORM\JoinColumn(onDelete: 'cascade', nullable: false)]
private JournalIssue $parent;
#[ApiProperty(description: 'Section', writableLink: false)]
#[Groups(['read', 'write'])]
#[Assert\Expression(
expression: '!value || value.getParent() === this.getParent().getParent()',
message: 'Cannot assign section from the outside of current journal.'
)]
#[ORM\ManyToOne(targetEntity: JournalSection::class)]
#[ORM\JoinColumn(onDelete: 'cascade', nullable: true)]
private ?JournalSection $section = null;
public function __construct(JournalIssue $parent)
{
$this->setUuid();
$this->parent = $parent;
$this->createdAt = new \DateTimeImmutable();
$this->updatedAt = new \DateTimeImmutable();
$parent->addSection($this);
}
public function getParent(): JournalIssue
{
return $this->parent;
}
public function getSection(): ?JournalSection
{
return $this->section;
}
public function setSection(JournalSection $section): self
{
$this->section = $section;
return $this;
}
public function clone(JournalIssue $parent): self
{
$clone = clone $this;
$clone->id = null;
$clone->setUuid();
$clone->parent = $parent;
$clone->parent->addSection($clone);
$clone->createdAt = new \DateTimeImmutable();
$clone->updatedAt = new \DateTimeImmutable();
return $clone;
}
}