src/Entity/AccessLog.php line 54

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Filter\UserFilter;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use App\Repository\AccessLogRepository;
  6. use ApiPlatform\Core\Annotation\ApiFilter;
  7. use App\Entity\Traits\TimestampableEntity;
  8. use ApiPlatform\Core\Annotation\ApiResource;
  9. use App\Entity\Interfaces\OwnerMappedInterface;
  10. use App\Entity\Interfaces\ContainerMappedInterface;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
  14. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  15. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  16. /**
  17.  * @ApiResource(
  18.  *      attributes={"security"="is_granted('IS_AUTHENTICATED_FULLY')"},
  19.  *      normalizationContext={"groups"={"AccessLog:Read", "TZ:Read"}, "skip_null_values"=false},
  20.  *      denormalizationContext={"groups"={"AccessLog:Write"}},
  21.  *      collectionOperations={
  22.  *          "get"={"security"="is_granted('ROLE_OPERATOR')"},
  23.  *          "get_report"={
  24.  *              "path"="/access_logs/get-report",
  25.  *              "method"="GET",
  26.  *              "security"="is_granted('ROLE_ADMIN')"
  27.  *          },
  28.  *          "get_public"={
  29.  *              "path"="/access_logs/get-public",
  30.  *              "method"="GET"
  31.  *          },
  32.  *          "get_by_url"={
  33.  *              "path"="/access_logs/get-by-url",
  34.  *              "method"="GET",
  35.  *              "pagination_enabled"=false
  36.  *          },
  37.  *          "post"
  38.  *      },
  39.  *      itemOperations={
  40.  *          "get"={"security"="is_granted('IS_CO_OPR', object)"},
  41.  *          "delete"={"security"="is_granted('IS_CO_OPR', object)"}
  42.  *     }
  43.  * )
  44.  * @ApiFilter(SearchFilter::class, properties={"container.id": "exact", "user.id": "exact", "user.roleContainers.role": "exact", "url": "partial", "pageTitle": "partial"})
  45.  * @ApiFilter(UserFilter::class, properties={"search": "partial"})
  46.  * @ApiFilter(OrderFilter::class, properties={"id": "DESC", "url", "user.id"})
  47.  * @ApiFilter(DateFilter::class, properties={"createdAt"})
  48.  * @ORM\Entity(repositoryClass=AccessLogRepository::class)
  49.  * @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"})})
  50.  */
  51. class AccessLog implements ContainerMappedInterfaceOwnerMappedInterface
  52. {
  53.     /**
  54.      * Hook timestampable behavior
  55.      * updates createdAt, updatedAt fields
  56.      */
  57.     use TimestampableEntity;
  58.     /**
  59.      * @ORM\Id
  60.      * @ORM\GeneratedValue
  61.      * @ORM\Column(type="integer")
  62.      * @Groups({"AccessLog:Read"})
  63.      */
  64.     private $id;
  65.     /**
  66.      * @var string
  67.      * @ORM\Column(type="string", length=255)
  68.      * @Groups({"AccessLog:Read", "AccessLog:Write"})
  69.      *
  70.      * @Assert\NotBlank(message="validation.accessLog:url.notBlank")
  71.      * @Assert\Length(max=255, maxMessage="validation.accessLog:url.max")
  72.      */
  73.     private $url;
  74.     /**
  75.      * @var string
  76.      * @ORM\Column(type="string", length=255, nullable=true)
  77.      * @Groups({"AccessLog:Read", "AccessLog:Write"})
  78.      *
  79.      * @Assert\Length(max=255, maxMessage="validation.accessLog:pageTitle.max")
  80.      */
  81.     private $pageTitle;
  82.     /**
  83.      * @var Container
  84.      * @ORM\ManyToOne(targetEntity=Container::class)
  85.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  86.      * @Groups({"AccessLog:Read", "AccessLog:Write"})
  87.      */
  88.     private $container;
  89.     /**
  90.      * @var User
  91.      * @ORM\ManyToOne(targetEntity=User::class)
  92.      * @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
  93.      * @Groups({"AccessLog:Read"})
  94.      */
  95.     private $user;
  96.     public function __construct()
  97.     {
  98.     }
  99.     public function getId(): ?int
  100.     {
  101.         return $this->id;
  102.     }
  103.     public function getUrl(): string
  104.     {
  105.         return $this->url;
  106.     }
  107.     public function setUrl(string $url): self
  108.     {
  109.         $this->url $url;
  110.         return $this;
  111.     }
  112.     public function getPageTitle(): ?string
  113.     {
  114.         return $this->pageTitle;
  115.     }
  116.     public function setPageTitle(string $pageTitle): self
  117.     {
  118.         $this->pageTitle $pageTitle;
  119.         return $this;
  120.     }
  121.     public function getContainer(): ?Container
  122.     {
  123.         return $this->container;
  124.     }
  125.     public function setContainer(?Container $container): self
  126.     {
  127.         $this->container $container;
  128.         return $this;
  129.     }
  130.     public function getUser(): ?User
  131.     {
  132.         return $this->user;
  133.     }
  134.     public function setUser(?User $user): self
  135.     {
  136.         $this->user $user;
  137.         return $this;
  138.     }
  139. }