src/Entity/JournalArticleRelationship.php line 58
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM,
Doctrine\DBAL\Types\Types,
Doctrine\Common\Collections\ArrayCollection;
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\OrdTrait,
App\Entity\Trait\TimestampableTrait,
App\Entity\Trait\TranslatableTrait,
App\Entity\Trait\Languages\LanguageableChildTrait,
App\Entity\Interface\TranslatableInterface,
App\Entity\Interface\OrderableInterface,
App\Entity\Interface\LanguageableChildInterface;
use App\Filter\IriFilter,
App\Util\ClassUtils,
App\Enum\RelationshipIdentifierType,
App\Repository\JournalArticleRelationshipRepository;
#[ApiResource(
description: 'Journal article relationships',
normalizationContext: ['groups' => [
'read',
'read:' . self::class,
'read:' . self::class . 'Translation'
]],
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: JournalArticleRelationshipRepository::class)]
class JournalArticleRelationship implements TranslatableInterface, OrderableInterface, LanguageableChildInterface
{
use IdTrait,
UuidTrait,
OrdTrait,
TimestampableTrait,
TranslatableTrait,
LanguageableChildTrait;
#[ApiProperty(description: 'Parent', readableLink: false, writableLink: false)]
#[Groups(['read', 'post'])]
#[Assert\NotNull]
#[ORM\ManyToOne(targetEntity: JournalArticle::class, inversedBy: 'relationships')]
#[ORM\JoinColumn(onDelete: 'cascade', nullable: false)]
private JournalArticle $parent;
#[ApiProperty(description: 'Type', writableLink: false)]
#[Groups(['read:' . self::class, 'write'])]
#[ORM\ManyToOne(targetEntity: ReciprocalRelationshipType::class)]
#[ORM\JoinColumn(onDelete: 'cascade', nullable: false)]
private ReciprocalRelationshipType $type;
#[ApiProperty(description: 'Identifier')]
#[Groups(['read', 'write'])]
#[Assert\NotBlank]
#[ORM\Column(type: Types::STRING, length: 255)]
private string $identifier;
#[ApiProperty(description: 'Identifier type')]
#[Groups(['read:' . self::class, 'write'])]
#[ORM\Column(
type: Types::STRING,
enumType: RelationshipIdentifierType::class,
length: 255,
options: ['default' => RelationshipIdentifierType::DOI],
unique: true
)]
private RelationshipIdentifierType $identifierType = RelationshipIdentifierType::DOI;
public function __construct(JournalArticle $parent)
{
$this->setUuid();
$this->parent = $parent;
$this->translations = new ArrayCollection();
foreach ($this->getParentLanguages() as $lang) {
new JournalArticleRelationshipTranslation($this, $lang);
}
$this->createdAt = new \DateTimeImmutable();
$this->updatedAt = new \DateTimeImmutable();
$parent->addRelationship($this);
}
public function getParent(): JournalArticle
{
return $this->parent;
}
#[Groups(['read'])]
public function getTitle(): ?string
{
return $this->identifier;
}
public function getType(): ReciprocalRelationshipType
{
return $this->type;
}
public function setType(ReciprocalRelationshipType $type): self
{
$this->type = $type;
return $this;
}
public function getIdentifier(): ?string
{
return $this->identifier;
}
public function setIdentifier(string $identifier): self
{
$this->identifier = $identifier;
return $this;
}
public function getIdentifierType(): RelationshipIdentifierType
{
return $this->identifierType;
}
public function setIdentifierType(RelationshipIdentifierType $identifierType): self
{
$this->identifierType = $identifierType;
return $this;
}
public function clone(JournalArticle $parent): self
{
$clone = clone $this;
$clone->id = null;
$clone->setUuid();
$clone->parent = $parent;
$clone->parent->addRelationship($clone);
ClassUtils::cloneCollection($this, $clone, 'translations');
$clone->synchronizeTranslations();
$clone->createdAt = new \DateTimeImmutable();
$clone->updatedAt = new \DateTimeImmutable();
return $clone;
}
}