<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ORM\Entity(repositoryClass="App\Repository\UserActivityLogRepository")
* @ORM\HasLifecycleCallbacks()
*/
#[ApiResource(
attributes: ['security' => "is_granted('ROLE_USER')"],
normalizationContext: ['groups' => ['userActivityLog:read']],
collectionOperations: ['get'],
itemOperations: ['get'],
)]
#[ApiFilter(SearchFilter::class, properties: ['old_value' => 'partial', 'new_value' => 'partial', 'activity' => 'partial', 'user' => 'exact', 'surveyCompany' => 'exact'])]
#[ApiFilter(PropertyFilter::class)]
#[ApiFilter(OrderFilter::class, properties: ['id', 'old_value', 'new_value', 'user', 'surveyCompany', 'activity', 'createdAt'], arguments: ['orderParameterName' => 'order'])]
class UserActivityLog
{
use TimestampableEntity;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @var User
*
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="userActivitylog")
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
* @Groups({"userActivityLog:read"})
*/
private $user;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"userActivityLog:read"})
*/
private $activity;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"userActivityLog:read"})
*/
private $old_value;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"userActivityLog:read"})
*/
private $new_value;
/**
* @ORM\ManyToOne(targetEntity=SurveyCompany::class)
* @Groups({"userActivityLog:read"})
*/
private $surveyCompany;
/**
* UserActivityLog constructor.
*
* @throws Exception
*/
public function __construct()
{
$this->createdAt = new \DateTime();
$this->updatedAt = new \DateTime();
}
public function getId(): ?int
{
return $this->id;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getActivity(): ?string
{
return $this->activity;
}
public function setActivity(?string $activity): self
{
$this->activity = $activity;
return $this;
}
public function getOldValue(): ?string
{
return $this->old_value;
}
public function setOldValue(?string $old_value): self
{
$this->old_value = $old_value;
return $this;
}
public function getNewValue(): ?string
{
return $this->new_value;
}
public function setNewValue(?string $new_value): self
{
$this->new_value = $new_value;
return $this;
}
public function getSurveyCompany(): ?SurveyCompany
{
return $this->surveyCompany;
}
public function setSurveyCompany(?SurveyCompany $surveyCompany): self
{
$this->surveyCompany = $surveyCompany;
return $this;
}
/**
* @Groups({"userActivityLog:read"})
*/
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
}