<?php
namespace App\Entity;
use App\Filter\UserFilter;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Entity\Interfaces\LikeEntityInterface;
use App\Entity\Interfaces\OwnerMappedInterface;
use App\Repository\CommonCommentLikeRepository;
use Symfony\Component\Serializer\Annotation\Groups;
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"={"CommonCommentLike:Read"}, "skip_null_values"=false},
* collectionOperations={
* "get"
* },
* itemOperations={
* "get"
* }
* )
* @ApiFilter(SearchFilter::class, properties={"user.id": "exact", "commonComment.id": "exact"})
* @ApiFilter(UserFilter::class, properties={"search": "partial"})
* @ApiFilter(OrderFilter::class, properties={"id": "DESC"})
* @ORM\Entity(repositoryClass=CommonCommentLikeRepository::class)
*/
class CommonCommentLike implements LikeEntityInterface, OwnerMappedInterface
{
/**
* @var \DateTime
* @Gedmo\Timestampable(on="create")
* @ORM\Column(type="datetime")
*/
protected $createdAt;
/**
* Sets createdAt.
*
* @return $this
*/
public function setCreatedAt(\DateTime $createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* Returns createdAt.
*
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=CommonComment::class)
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
* @Groups({"User:Me-Subscribed"})
*/
private $commonComment;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="commonCommentLikes")
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
* @Groups({"CommonCommentLike:Read"})
*/
private $user;
public function __construct($commonComment = null, $user = null)
{
if ($commonComment) {
$this->commonComment = $commonComment;
}
if ($user) {
$this->user = $user;
}
}
public function getId(): ?int
{
return $this->id;
}
public function getCommonComment(): ?CommonComment
{
return $this->commonComment;
}
public function setCommonComment(?CommonComment $commonComment): self
{
$this->commonComment = $commonComment;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getParent()
{
return $this->getCommonComment();
}
public function getParentClass()
{
return CommonComment::class;
}
}