<?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 App\Repository\NewsfeedLikeRepository;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Entity\Interfaces\LikeEntityInterface;
use App\Entity\Interfaces\OwnerMappedInterface;
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"={"NewsfeedLike:Read"}, "skip_null_values"=false},
* collectionOperations={
* "get"
* },
* itemOperations={
* "get"
* }
* )
* @ApiFilter(SearchFilter::class, properties={"user.id": "exact", "newsfeed.id": "exact"})
* @ApiFilter(UserFilter::class, properties={"search": "partial"})
* @ApiFilter(OrderFilter::class, properties={"id": "DESC"})
* @ORM\Entity(repositoryClass=NewsfeedLikeRepository::class)
*/
class NewsfeedLike 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=Newsfeed::class)
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
* @Groups({"User:Me-Subscribed"})
*/
private $newsfeed;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="newsfeedLikes")
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
* @Groups({"NewsfeedLike:Read"})
*/
private $user;
public function __construct($newsfeed = null, $user = null)
{
if ($newsfeed) {
$this->newsfeed = $newsfeed;
}
if ($user) {
$this->user = $user;
}
}
public function getId(): ?int
{
return $this->id;
}
public function getNewsfeed(): ?Newsfeed
{
return $this->newsfeed;
}
public function setNewsfeed(?Newsfeed $newsfeed): self
{
$this->newsfeed = $newsfeed;
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->getNewsfeed();
}
public function getParentClass()
{
return Newsfeed::class;
}
}