<?php
declare(strict_types=1);
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\UserBlockRepository;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* Blocage d'un utilisateur par un autre (guideline Apple 1.2) : le bloqueur ne voit plus les messages du bloqué
* ni leur chat privé, et aucun des deux ne peut plus écrire à l'autre en privé.
*
* API : POST (bloqueur forcé à l'utilisateur connecté, contrôles dans App\EventSubscriber\UserBlockSubscriber),
* GET de ses propres blocages (App\Doctrine\UserBlockExtension), DELETE pour débloquer. Le bloqué n'expose que
* id, firstName, lastName et avatar (URL), groupe user_block:read.
*
* @ApiResource(
* normalizationContext={"groups"={"user_block:read"}},
* denormalizationContext={"groups"={"user_block:write"}},
* collectionOperations={
* "get"={"security"="is_granted('ROLE_USER')"},
* "post"={"security"="is_granted('ROLE_USER')"}
* },
* itemOperations={
* "get"={"security"="is_granted('ROLE_ADMIN') or object.getBlocker() == user"},
* "delete"={"security"="is_granted('ROLE_ADMIN') or object.getBlocker() == user"}
* }
* )
* @ORM\Entity(repositoryClass=UserBlockRepository::class)
* @ORM\Table(uniqueConstraints={
* @ORM\UniqueConstraint(name="user_block_unique", columns={"blocker_id", "blocked_id"})
* })
*/
class UserBlock
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"user_block:read"})
*/
private ?int $id = null;
/**
* @ORM\ManyToOne(targetEntity=User::class)
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
*/
private ?User $blocker = null;
/**
* @ORM\ManyToOne(targetEntity=User::class)
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
* @Groups({"user_block:read", "user_block:write"})
*/
private ?User $blocked = null;
/**
* @ORM\Column(type="datetime")
* @Gedmo\Timestampable(on="create")
* @Groups({"user_block:read"})
*/
private ?\DateTimeInterface $createdAt = null;
/**
* @ORM\Column(type="datetime")
* @Gedmo\Timestampable(on="update")
*/
private ?\DateTimeInterface $updatedAt = null;
public function getId(): ?int
{
return $this->id;
}
public function getBlocker(): ?User
{
return $this->blocker;
}
public function setBlocker(?User $blocker): self
{
$this->blocker = $blocker;
return $this;
}
public function getBlocked(): ?User
{
return $this->blocked;
}
public function setBlocked(?User $blocked): self
{
$this->blocked = $blocked;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
}