<?php
declare(strict_types=1);
namespace App\Entity;
use App\Repository\ContentReportRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
/**
* Signalement d'un contenu (guideline Apple 1.2) : un message, un profil (photo, nom) ou une team (nom, photo).
* Une seule table : targetType dit quelle clé étrangère est renseignée (message, reportedTeam, ou reportedUser seul
* pour un profil). reportedUser est toujours l'auteur visé : auteur du message, profil signalé, dernier éditeur de la team.
* La preuve (texte, copies d'images) est figée à la création : le contenu d'origine peut disparaître.
*
* @ORM\Entity(repositoryClass=ContentReportRepository::class)
* @ORM\Table(indexes={
* @ORM\Index(name="content_report_status_idx", columns={"status", "created_at"}),
* @ORM\Index(name="content_report_reporter_idx", columns={"reporter_id", "target_type"})
* })
*/
class ContentReport
{
public const TARGET_MESSAGE = 'message';
public const TARGET_USER = 'user';
public const TARGET_TEAM = 'team';
public const TARGETS = [self::TARGET_MESSAGE, self::TARGET_USER, self::TARGET_TEAM];
public const REASON_OFFENSIVE = 'offensive';
public const REASON_HARASSMENT = 'harassment';
public const REASON_SPAM = 'spam';
public const REASON_OTHER = 'other';
public const REASONS = [self::REASON_OFFENSIVE, self::REASON_HARASSMENT, self::REASON_SPAM, self::REASON_OTHER];
public const STATUS_PENDING = 'pending';
public const STATUS_REMOVED = 'removed';
public const STATUS_DISMISSED = 'dismissed';
public const STATUSES = [self::STATUS_PENDING, self::STATUS_REMOVED, self::STATUS_DISMISSED];
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private ?int $id = null;
/**
* @ORM\ManyToOne(targetEntity=User::class)
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
*/
private ?User $reporter = null;
/**
* @ORM\ManyToOne(targetEntity=ChatMessage::class)
* @ORM\JoinColumn(onDelete="SET NULL")
*/
private ?ChatMessage $message = null;
/**
* @ORM\ManyToOne(targetEntity=User::class)
* @ORM\JoinColumn(onDelete="SET NULL")
*/
private ?User $reportedUser = null;
/**
* @ORM\ManyToOne(targetEntity=Team::class)
* @ORM\JoinColumn(onDelete="SET NULL")
*/
private ?Team $reportedTeam = null;
/**
* @ORM\ManyToOne(targetEntity=User::class)
* @ORM\JoinColumn(onDelete="SET NULL")
*/
private ?User $handledBy = null;
/**
* @ORM\Column(type="string", length=10)
* @Assert\Choice(choices=ContentReport::TARGETS)
*/
private string $targetType = self::TARGET_MESSAGE;
/**
* @ORM\Column(type="string", length=20)
* @Assert\Choice(choices=ContentReport::REASONS)
*/
private string $reason = self::REASON_OTHER;
/**
* @ORM\Column(type="text", nullable=true)
* @Assert\Length(max=1000)
*/
private ?string $comment = null;
/**
* @ORM\Column(type="string", length=10, options={"default": "pending"})
* @Assert\Choice(choices=ContentReport::STATUSES)
*/
private string $status = self::STATUS_PENDING;
/**
* Copie du texte signalé au moment du signalement (message, nom de team, prénom et nom).
*
* @ORM\Column(type="text", nullable=true)
*/
private ?string $evidenceText = null;
/**
* Copies des images signalées, stockées en base (jamais publiques).
*
* @ORM\OneToMany(targetEntity=ContentReportEvidence::class, mappedBy="report", cascade={"persist"}, orphanRemoval=true)
*/
private Collection $evidences;
/**
* @ORM\Column(type="datetime")
* @Gedmo\Timestampable(on="create")
*/
private ?\DateTimeInterface $createdAt = null;
/**
* @ORM\Column(type="datetime")
* @Gedmo\Timestampable(on="update")
*/
private ?\DateTimeInterface $updatedAt = null;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private ?\DateTimeInterface $handledAt = null;
public function __construct()
{
$this->evidences = new ArrayCollection();
}
/**
* Exactement une cible, cohérente avec targetType.
*
* @Assert\Callback
*/
public function validateTarget(ExecutionContextInterface $context): void
{
$valid = [
self::TARGET_MESSAGE => null !== $this->message && null === $this->reportedTeam,
self::TARGET_TEAM => null !== $this->reportedTeam && null === $this->message,
self::TARGET_USER => null !== $this->reportedUser && null === $this->message && null === $this->reportedTeam,
][$this->targetType] ?? false;
if (!$valid) {
$context->buildViolation('La cible du signalement ne correspond pas à targetType.')->atPath('targetType')->addViolation();
}
}
public function getId(): ?int
{
return $this->id;
}
public function getReporter(): ?User
{
return $this->reporter;
}
public function setReporter(?User $reporter): self
{
$this->reporter = $reporter;
return $this;
}
public function getMessage(): ?ChatMessage
{
return $this->message;
}
public function setMessage(?ChatMessage $message): self
{
$this->message = $message;
return $this;
}
public function getReportedUser(): ?User
{
return $this->reportedUser;
}
public function setReportedUser(?User $reportedUser): self
{
$this->reportedUser = $reportedUser;
return $this;
}
public function getReportedTeam(): ?Team
{
return $this->reportedTeam;
}
public function setReportedTeam(?Team $reportedTeam): self
{
$this->reportedTeam = $reportedTeam;
return $this;
}
public function getHandledBy(): ?User
{
return $this->handledBy;
}
public function setHandledBy(?User $handledBy): self
{
$this->handledBy = $handledBy;
return $this;
}
public function getTargetType(): string
{
return $this->targetType;
}
public function setTargetType(string $targetType): self
{
$this->targetType = $targetType;
return $this;
}
public function getReason(): string
{
return $this->reason;
}
public function setReason(string $reason): self
{
$this->reason = $reason;
return $this;
}
public function getComment(): ?string
{
return $this->comment;
}
public function setComment(?string $comment): self
{
$this->comment = $comment;
return $this;
}
public function getStatus(): string
{
return $this->status;
}
public function setStatus(string $status): self
{
$this->status = $status;
return $this;
}
public function getEvidenceText(): ?string
{
return $this->evidenceText;
}
public function setEvidenceText(?string $evidenceText): self
{
$this->evidenceText = $evidenceText;
return $this;
}
/**
* @return Collection<int, ContentReportEvidence>
*/
public function getEvidences(): Collection
{
return $this->evidences;
}
public function addEvidence(ContentReportEvidence $evidence): self
{
if (!$this->evidences->contains($evidence)) {
$this->evidences[] = $evidence;
$evidence->setReport($this);
}
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
/**
* Date posée à la main (tests, données de démonstration) ; sinon remplie à la création.
*/
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function getHandledAt(): ?\DateTimeInterface
{
return $this->handledAt;
}
public function setHandledAt(?\DateTimeInterface $handledAt): self
{
$this->handledAt = $handledAt;
return $this;
}
}