src/Entity/JournalArticleViewEntry.php line 42

  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM,
  4.     Doctrine\DBAL\Types\Types;
  5. use Symfony\Component\Serializer\Annotation\Groups;
  6. use ApiPlatform\Metadata\ApiResource,
  7.     ApiPlatform\Metadata\ApiProperty,
  8.     ApiPlatform\Metadata\Get,
  9.     ApiPlatform\Metadata\GetCollection,
  10.     ApiPlatform\Metadata\Post,
  11.     ApiPlatform\Metadata\Put,
  12.     ApiPlatform\Metadata\Delete,
  13.     ApiPlatform\Metadata\ApiFilter;
  14. use App\Entity\Trait\IdTrait,
  15.     App\Entity\Trait\UuidTrait,
  16.     App\Entity\Trait\TimestampableTrait;
  17. use App\Filter\IriFilter,
  18.     App\Repository\JournalArticleViewEntryRepository;
  19. #[ApiResource(
  20.     description'Journal article view entries',
  21.     normalizationContext: ['groups' => ['read''read:' self::class]],
  22.     denormalizationContext: ['groups' => ['write']],
  23.     security'is_granted("' Journal::class . '")',
  24.     order: ['ord' => 'desc'],
  25.     operations: [
  26.         new GetCollection(),
  27.         new Post(denormalizationContext: ['groups' => ['write',  'post']]),
  28.         new Get(),
  29.         new Put(),
  30.         new Delete(),
  31.     ],
  32.     extraProperties: ['standard_put' => false],
  33. )]
  34. #[ApiFilter(IriFilter::class, properties: ['parent'])]
  35. #[ORM\Entity(repositoryClassJournalArticleViewEntryRepository::class)]
  36. class JournalArticleViewEntry
  37. {
  38.     use IdTrait,
  39.         UuidTrait,
  40.         TimestampableTrait;
  41.     #[ApiProperty(description'Parent'readableLinkfalsewritableLinkfalse)]
  42.     #[Groups(['read''post'])]
  43.     #[ORM\ManyToOne(targetEntityJournalArticle::class, inversedBy'viewEntries')]
  44.     #[ORM\JoinColumn(onDelete'cascade'nullablefalse)]
  45.     private JournalArticle $parent;
  46.     #[ApiProperty(description'Viewer ip')]
  47.     #[ORM\Column(typeTypes::STRINGlength191)]
  48.     private string $ip;
  49.     public function __construct(JournalArticle $parentstring $ip)
  50.     {
  51.         $this->setUuid();
  52.         $this->parent $parent;
  53.         $this->ip $ip;
  54.         $this->createdAt = new \DateTimeImmutable();
  55.         $this->updatedAt = new \DateTimeImmutable();
  56.         $parent
  57.             ->addViewEntry($this)
  58.             ->hitStatsView();
  59.     }
  60.     public function getParent(): JournalArticle
  61.     {
  62.         return $this->parent;
  63.     }
  64.     public function getIp(): string
  65.     {
  66.         return $this->ip;
  67.     }
  68. }