src/Entity/JournalArticleDownloadEntry.php line 42
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM,
Doctrine\DBAL\Types\Types;
use Symfony\Component\Serializer\Annotation\Groups;
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;
use App\Entity\Trait\IdTrait,
App\Entity\Trait\UuidTrait,
App\Entity\Trait\TimestampableTrait;
use App\Filter\IriFilter,
App\Repository\JournalArticleDownloadEntryRepository;
#[ApiResource(
description: 'Journal article download entries',
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'])]
#[ORM\Entity(repositoryClass: JournalArticleDownloadEntryRepository::class)]
class JournalArticleDownloadEntry
{
use IdTrait,
UuidTrait,
TimestampableTrait;
#[ApiProperty(description: 'Parent', readableLink: false, writableLink: false)]
#[Groups(['read', 'post'])]
#[ORM\ManyToOne(targetEntity: JournalArticle::class, inversedBy: 'downloadEntries')]
#[ORM\JoinColumn(onDelete: 'cascade', nullable: false)]
private JournalArticle $parent;
#[ApiProperty(description: 'Downloader ip')]
#[ORM\Column(type: Types::STRING, length: 191)]
private string $ip;
public function __construct(JournalArticle $parent, string $ip)
{
$this->setUuid();
$this->parent = $parent;
$this->ip = $ip;
$this->createdAt = new \DateTimeImmutable();
$this->updatedAt = new \DateTimeImmutable();
$parent
->addDownloadEntry($this)
->hitStatsDownload();
}
public function getParent(): JournalArticle
{
return $this->parent;
}
public function getIp(): string
{
return $this->ip;
}
}