<?php
namespace App\Entity;
use App\Filter\UserFilter;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\AccessLogRepository;
use ApiPlatform\Core\Annotation\ApiFilter;
use App\Entity\Traits\TimestampableEntity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Entity\Interfaces\OwnerMappedInterface;
use App\Entity\Interfaces\ContainerMappedInterface;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
/**
* @ApiResource(
* attributes={"security"="is_granted('IS_AUTHENTICATED_FULLY')"},
* normalizationContext={"groups"={"AccessLog:Read", "TZ:Read"}, "skip_null_values"=false},
* denormalizationContext={"groups"={"AccessLog:Write"}},
* collectionOperations={
* "get"={"security"="is_granted('ROLE_OPERATOR')"},
* "get_report"={
* "path"="/access_logs/get-report",
* "method"="GET",
* "security"="is_granted('ROLE_ADMIN')"
* },
* "get_public"={
* "path"="/access_logs/get-public",
* "method"="GET"
* },
* "get_by_url"={
* "path"="/access_logs/get-by-url",
* "method"="GET",
* "pagination_enabled"=false
* },
* "post"
* },
* itemOperations={
* "get"={"security"="is_granted('IS_CO_OPR', object)"},
* "delete"={"security"="is_granted('IS_CO_OPR', object)"}
* }
* )
* @ApiFilter(SearchFilter::class, properties={"container.id": "exact", "user.id": "exact", "user.roleContainers.role": "exact", "url": "partial", "pageTitle": "partial"})
* @ApiFilter(UserFilter::class, properties={"search": "partial"})
* @ApiFilter(OrderFilter::class, properties={"id": "DESC", "url", "user.id"})
* @ApiFilter(DateFilter::class, properties={"createdAt"})
* @ORM\Entity(repositoryClass=AccessLogRepository::class)
* @ORM\Table(name="access_log",indexes={@ORM\Index(name="access_log_url_idx", columns={"url"}), @ORM\Index(name="access_log_page_title_idx", columns={"page_title"})})
*/
class AccessLog implements ContainerMappedInterface, OwnerMappedInterface
{
/**
* Hook timestampable behavior
* updates createdAt, updatedAt fields
*/
use TimestampableEntity;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"AccessLog:Read"})
*/
private $id;
/**
* @var string
* @ORM\Column(type="string", length=255)
* @Groups({"AccessLog:Read", "AccessLog:Write"})
*
* @Assert\NotBlank(message="validation.accessLog:url.notBlank")
* @Assert\Length(max=255, maxMessage="validation.accessLog:url.max")
*/
private $url;
/**
* @var string
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"AccessLog:Read", "AccessLog:Write"})
*
* @Assert\Length(max=255, maxMessage="validation.accessLog:pageTitle.max")
*/
private $pageTitle;
/**
* @var Container
* @ORM\ManyToOne(targetEntity=Container::class)
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
* @Groups({"AccessLog:Read", "AccessLog:Write"})
*/
private $container;
/**
* @var User
* @ORM\ManyToOne(targetEntity=User::class)
* @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
* @Groups({"AccessLog:Read"})
*/
private $user;
public function __construct()
{
}
public function getId(): ?int
{
return $this->id;
}
public function getUrl(): string
{
return $this->url;
}
public function setUrl(string $url): self
{
$this->url = $url;
return $this;
}
public function getPageTitle(): ?string
{
return $this->pageTitle;
}
public function setPageTitle(string $pageTitle): self
{
$this->pageTitle = $pageTitle;
return $this;
}
public function getContainer(): ?Container
{
return $this->container;
}
public function setContainer(?Container $container): self
{
$this->container = $container;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
}