src/Entity/ContentReport.php line 27

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use App\Repository\ContentReportRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Gedmo\Mapping\Annotation as Gedmo;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  11. /**
  12.  * Signalement d'un contenu (guideline Apple 1.2) : un message, un profil (photo, nom) ou une team (nom, photo).
  13.  * Une seule table : targetType dit quelle clé étrangère est renseignée (message, reportedTeam, ou reportedUser seul
  14.  * pour un profil). reportedUser est toujours l'auteur visé : auteur du message, profil signalé, dernier éditeur de la team.
  15.  * La preuve (texte, copies d'images) est figée à la création : le contenu d'origine peut disparaître.
  16.  *
  17.  * @ORM\Entity(repositoryClass=ContentReportRepository::class)
  18.  * @ORM\Table(indexes={
  19.  *     @ORM\Index(name="content_report_status_idx", columns={"status", "created_at"}),
  20.  *     @ORM\Index(name="content_report_reporter_idx", columns={"reporter_id", "target_type"})
  21.  * })
  22.  */
  23. class ContentReport
  24. {
  25.     public const TARGET_MESSAGE = 'message';
  26.     public const TARGET_USER = 'user';
  27.     public const TARGET_TEAM = 'team';
  28.     public const TARGETS = [self::TARGET_MESSAGE, self::TARGET_USER, self::TARGET_TEAM];
  29.     public const REASON_OFFENSIVE = 'offensive';
  30.     public const REASON_HARASSMENT = 'harassment';
  31.     public const REASON_SPAM = 'spam';
  32.     public const REASON_OTHER = 'other';
  33.     public const REASONS = [self::REASON_OFFENSIVE, self::REASON_HARASSMENT, self::REASON_SPAM, self::REASON_OTHER];
  34.     public const STATUS_PENDING = 'pending';
  35.     public const STATUS_REMOVED = 'removed';
  36.     public const STATUS_DISMISSED = 'dismissed';
  37.     public const STATUSES = [self::STATUS_PENDING, self::STATUS_REMOVED, self::STATUS_DISMISSED];
  38.     /**
  39.      * @ORM\Id
  40.      * @ORM\GeneratedValue
  41.      * @ORM\Column(type="integer")
  42.      */
  43.     private ?int $id = null;
  44.     /**
  45.      * @ORM\ManyToOne(targetEntity=User::class)
  46.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  47.      */
  48.     private ?User $reporter = null;
  49.     /**
  50.      * @ORM\ManyToOne(targetEntity=ChatMessage::class)
  51.      * @ORM\JoinColumn(onDelete="SET NULL")
  52.      */
  53.     private ?ChatMessage $message = null;
  54.     /**
  55.      * @ORM\ManyToOne(targetEntity=User::class)
  56.      * @ORM\JoinColumn(onDelete="SET NULL")
  57.      */
  58.     private ?User $reportedUser = null;
  59.     /**
  60.      * @ORM\ManyToOne(targetEntity=Team::class)
  61.      * @ORM\JoinColumn(onDelete="SET NULL")
  62.      */
  63.     private ?Team $reportedTeam = null;
  64.     /**
  65.      * @ORM\ManyToOne(targetEntity=User::class)
  66.      * @ORM\JoinColumn(onDelete="SET NULL")
  67.      */
  68.     private ?User $handledBy = null;
  69.     /**
  70.      * @ORM\Column(type="string", length=10)
  71.      * @Assert\Choice(choices=ContentReport::TARGETS)
  72.      */
  73.     private string $targetType = self::TARGET_MESSAGE;
  74.     /**
  75.      * @ORM\Column(type="string", length=20)
  76.      * @Assert\Choice(choices=ContentReport::REASONS)
  77.      */
  78.     private string $reason = self::REASON_OTHER;
  79.     /**
  80.      * @ORM\Column(type="text", nullable=true)
  81.      * @Assert\Length(max=1000)
  82.      */
  83.     private ?string $comment = null;
  84.     /**
  85.      * @ORM\Column(type="string", length=10, options={"default": "pending"})
  86.      * @Assert\Choice(choices=ContentReport::STATUSES)
  87.      */
  88.     private string $status = self::STATUS_PENDING;
  89.     /**
  90.      * Copie du texte signalé au moment du signalement (message, nom de team, prénom et nom).
  91.      *
  92.      * @ORM\Column(type="text", nullable=true)
  93.      */
  94.     private ?string $evidenceText = null;
  95.     /**
  96.      * Copies des images signalées, stockées en base (jamais publiques).
  97.      *
  98.      * @ORM\OneToMany(targetEntity=ContentReportEvidence::class, mappedBy="report", cascade={"persist"}, orphanRemoval=true)
  99.      */
  100.     private Collection $evidences;
  101.     /**
  102.      * @ORM\Column(type="datetime")
  103.      * @Gedmo\Timestampable(on="create")
  104.      */
  105.     private ?\DateTimeInterface $createdAt = null;
  106.     /**
  107.      * @ORM\Column(type="datetime")
  108.      * @Gedmo\Timestampable(on="update")
  109.      */
  110.     private ?\DateTimeInterface $updatedAt = null;
  111.     /**
  112.      * @ORM\Column(type="datetime", nullable=true)
  113.      */
  114.     private ?\DateTimeInterface $handledAt = null;
  115.     public function __construct()
  116.     {
  117.         $this->evidences = new ArrayCollection();
  118.     }
  119.     /**
  120.      * Exactement une cible, cohérente avec targetType.
  121.      *
  122.      * @Assert\Callback
  123.      */
  124.     public function validateTarget(ExecutionContextInterface $context): void
  125.     {
  126.         $valid = [
  127.             self::TARGET_MESSAGE => null !== $this->message && null === $this->reportedTeam,
  128.             self::TARGET_TEAM => null !== $this->reportedTeam && null === $this->message,
  129.             self::TARGET_USER => null !== $this->reportedUser && null === $this->message && null === $this->reportedTeam,
  130.         ][$this->targetType] ?? false;
  131.         if (!$valid) {
  132.             $context->buildViolation('La cible du signalement ne correspond pas à targetType.')->atPath('targetType')->addViolation();
  133.         }
  134.     }
  135.     public function getId(): ?int
  136.     {
  137.         return $this->id;
  138.     }
  139.     public function getReporter(): ?User
  140.     {
  141.         return $this->reporter;
  142.     }
  143.     public function setReporter(?User $reporter): self
  144.     {
  145.         $this->reporter = $reporter;
  146.         return $this;
  147.     }
  148.     public function getMessage(): ?ChatMessage
  149.     {
  150.         return $this->message;
  151.     }
  152.     public function setMessage(?ChatMessage $message): self
  153.     {
  154.         $this->message = $message;
  155.         return $this;
  156.     }
  157.     public function getReportedUser(): ?User
  158.     {
  159.         return $this->reportedUser;
  160.     }
  161.     public function setReportedUser(?User $reportedUser): self
  162.     {
  163.         $this->reportedUser = $reportedUser;
  164.         return $this;
  165.     }
  166.     public function getReportedTeam(): ?Team
  167.     {
  168.         return $this->reportedTeam;
  169.     }
  170.     public function setReportedTeam(?Team $reportedTeam): self
  171.     {
  172.         $this->reportedTeam = $reportedTeam;
  173.         return $this;
  174.     }
  175.     public function getHandledBy(): ?User
  176.     {
  177.         return $this->handledBy;
  178.     }
  179.     public function setHandledBy(?User $handledBy): self
  180.     {
  181.         $this->handledBy = $handledBy;
  182.         return $this;
  183.     }
  184.     public function getTargetType(): string
  185.     {
  186.         return $this->targetType;
  187.     }
  188.     public function setTargetType(string $targetType): self
  189.     {
  190.         $this->targetType = $targetType;
  191.         return $this;
  192.     }
  193.     public function getReason(): string
  194.     {
  195.         return $this->reason;
  196.     }
  197.     public function setReason(string $reason): self
  198.     {
  199.         $this->reason = $reason;
  200.         return $this;
  201.     }
  202.     public function getComment(): ?string
  203.     {
  204.         return $this->comment;
  205.     }
  206.     public function setComment(?string $comment): self
  207.     {
  208.         $this->comment = $comment;
  209.         return $this;
  210.     }
  211.     public function getStatus(): string
  212.     {
  213.         return $this->status;
  214.     }
  215.     public function setStatus(string $status): self
  216.     {
  217.         $this->status = $status;
  218.         return $this;
  219.     }
  220.     public function getEvidenceText(): ?string
  221.     {
  222.         return $this->evidenceText;
  223.     }
  224.     public function setEvidenceText(?string $evidenceText): self
  225.     {
  226.         $this->evidenceText = $evidenceText;
  227.         return $this;
  228.     }
  229.     /**
  230.      * @return Collection<int, ContentReportEvidence>
  231.      */
  232.     public function getEvidences(): Collection
  233.     {
  234.         return $this->evidences;
  235.     }
  236.     public function addEvidence(ContentReportEvidence $evidence): self
  237.     {
  238.         if (!$this->evidences->contains($evidence)) {
  239.             $this->evidences[] = $evidence;
  240.             $evidence->setReport($this);
  241.         }
  242.         return $this;
  243.     }
  244.     public function getCreatedAt(): ?\DateTimeInterface
  245.     {
  246.         return $this->createdAt;
  247.     }
  248.     /**
  249.      * Date posée à la main (tests, données de démonstration) ; sinon remplie à la création.
  250.      */
  251.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  252.     {
  253.         $this->createdAt = $createdAt;
  254.         return $this;
  255.     }
  256.     public function getUpdatedAt(): ?\DateTimeInterface
  257.     {
  258.         return $this->updatedAt;
  259.     }
  260.     public function getHandledAt(): ?\DateTimeInterface
  261.     {
  262.         return $this->handledAt;
  263.     }
  264.     public function setHandledAt(?\DateTimeInterface $handledAt): self
  265.     {
  266.         $this->handledAt = $handledAt;
  267.         return $this;
  268.     }
  269. }