src/App/Entity/ContentReport.php line 15

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace App\Entity;
  3. use App\Model\ContentReportData;
  4. use DateTime;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Gedmo\Mapping\Annotation as Gedmo;
  7. use RuntimeException;
  8. /**
  9.  * @ORM\Entity(repositoryClass="App\Repository\ContentReportRepository")
  10.  * @ORM\Table()
  11.  */
  12. class ContentReport
  13. {
  14.     /**
  15.      * @var string[]
  16.      */
  17.     public static array $typeOfInfringement = [
  18.         'type.personal_right' => 'personal right',
  19.         'type.copyright' => 'copyright',
  20.         'type.rules_law' => 'rules/law',
  21.     ];
  22.     /**
  23.      * @ORM\Id
  24.      * @ORM\GeneratedValue
  25.      * @ORM\Column(type="integer")
  26.      */
  27.     private ?int $id null;
  28.     /**
  29.      * @var array<mixed>
  30.      * @ORM\Column(type="json")
  31.      */
  32.     private array $data = [];
  33.     /**
  34.      * @ORM\Column(type="datetime")
  35.      * @Gedmo\Timestampable(on="update")
  36.      */
  37.     private DateTime $lastModified;
  38.     private ?string $url null;
  39.     private ?string $type null;
  40.     private ?string $text null;
  41.     private ?string $signature null;
  42.     private ?ContentReportData $reporter null;
  43.     private bool $reporterIsVictim false;
  44.     private bool $authorized false;
  45.     private ?ContentReportData $victim null;
  46.     /**
  47.      * @ORM\Column(type="string")
  48.      */
  49.     private ?string $hash null;
  50.     /**
  51.      * @ORM\Column(type="boolean")
  52.      */
  53.     private bool $verified false;
  54.     public function __construct()
  55.     {
  56.         $this->lastModified = new DateTime();
  57.     }
  58.     public function getId(): ?int
  59.     {
  60.         return $this->id;
  61.     }
  62.     public function setId(int $id): void
  63.     {
  64.         $this->id $id;
  65.     }
  66.     /**
  67.      * @return mixed[]
  68.      */
  69.     public function getData(): array
  70.     {
  71.         return $this->data;
  72.     }
  73.     /**
  74.      * @param array<mixed> $data
  75.      */
  76.     public function setData(array $data): void
  77.     {
  78.         $this->data $data;
  79.     }
  80.     public function getLastModified(): DateTime
  81.     {
  82.         return $this->lastModified;
  83.     }
  84.     public function setLastModified(DateTime $lastModified): void
  85.     {
  86.         $this->lastModified $lastModified;
  87.     }
  88.     public function getUrl(): ?string
  89.     {
  90.         if (null === $this->url && isset($this->data['url'])) {
  91.             if (!is_string($this->data['url'])) {
  92.                 throw new RuntimeException('Invalid data on key "url"');
  93.             }
  94.             $this->url $this->data['url'];
  95.         }
  96.         return $this->url;
  97.     }
  98.     public function setUrl(?string $url): void
  99.     {
  100.         $this->data['url'] = $url;
  101.         $this->url $url;
  102.     }
  103.     public function getType(): ?string
  104.     {
  105.         if (null === $this->type && isset($this->data['type'])) {
  106.             if (!is_string($this->data['type'])) {
  107.                 throw new RuntimeException('Invalid data on key "type"');
  108.             }
  109.             $this->type $this->data['type'];
  110.         }
  111.         return $this->type;
  112.     }
  113.     public function setType(string $type): void
  114.     {
  115.         $this->data['type'] = $type;
  116.         $this->type $type;
  117.     }
  118.     public function getText(): ?string
  119.     {
  120.         if (null === $this->text && isset($this->data['text'])) {
  121.             if (!is_string($this->data['text'])) {
  122.                 throw new RuntimeException('Invalid data on key "text"');
  123.             }
  124.             $this->text $this->data['text'];
  125.         }
  126.         return $this->text;
  127.     }
  128.     public function setText(string $text): void
  129.     {
  130.         $this->data['text'] = $text;
  131.         $this->text $text;
  132.     }
  133.     public function getSignature(): ?string
  134.     {
  135.         if (null === $this->signature && isset($this->data['signature'])) {
  136.             if (!is_string($this->data['signature'])) {
  137.                 throw new RuntimeException('Invalid data on key "signature"');
  138.             }
  139.             $this->signature $this->data['signature'];
  140.         }
  141.         return $this->signature;
  142.     }
  143.     public function setSignature(string $signature): void
  144.     {
  145.         $this->data['signature'] = $signature;
  146.         $this->signature $signature;
  147.     }
  148.     public function getTypeName(): string
  149.     {
  150.         return array_flip(self::$typeOfInfringement)[$this->getType()];
  151.     }
  152.     public function isReporterIsVictim(): bool
  153.     {
  154.         if (!$this->reporterIsVictim && isset($this->data['reporterIsVictim'])) {
  155.             if (!is_bool($this->data['reporterIsVictim'])) {
  156.                 throw new RuntimeException('Invalid data on key "reporterIsVictim"');
  157.             }
  158.             $this->reporterIsVictim $this->data['reporterIsVictim'];
  159.         }
  160.         return $this->reporterIsVictim;
  161.     }
  162.     public function setReporterIsVictim(bool $reporterIsVictim): void
  163.     {
  164.         $this->data['reporterIsVictim'] = $reporterIsVictim;
  165.         $this->reporterIsVictim $reporterIsVictim;
  166.     }
  167.     public function isAuthorized(): bool
  168.     {
  169.         if (!$this->authorized && isset($this->data['authorized'])) {
  170.             if (!is_bool($this->data['authorized'])) {
  171.                 throw new RuntimeException('Invalid data on key "authorized"');
  172.             }
  173.             $this->authorized $this->data['authorized'];
  174.         }
  175.         return $this->authorized;
  176.     }
  177.     public function setAuthorized(bool $authorized): void
  178.     {
  179.         $this->data['authorized'] = $authorized;
  180.         $this->authorized $authorized;
  181.     }
  182.     public function getReporter(): ContentReportData
  183.     {
  184.         if (null === $this->reporter) {
  185.             $reporter = [];
  186.             if (isset($this->data['victim']) && is_array($this->data['victim'])) {
  187.                 $reporter $this->data['victim'];
  188.             }
  189.             $this->reporter = new ContentReportData($reporter);
  190.         }
  191.         return $this->reporter;
  192.     }
  193.     public function setReporter(?ContentReportData $reporter): void
  194.     {
  195.         $this->reporter $reporter;
  196.         if (null === $reporter) {
  197.             return;
  198.         }
  199.         $this->data['reporter'] = $reporter->getData();
  200.     }
  201.     public function getVictim(): ?ContentReportData
  202.     {
  203.         if (null === $this->victim) {
  204.             if (true === $this->isReporterIsVictim()) {
  205.                 return null;
  206.             }
  207.             $victim = [];
  208.             if (isset($this->data['victim']) && is_array($this->data['victim'])) {
  209.                 $victim $this->data['victim'];
  210.             }
  211.             $this->victim = new ContentReportData($victim);
  212.         }
  213.         return $this->victim;
  214.     }
  215.     public function setVictim(?ContentReportData $victim): void
  216.     {
  217.         $this->victim $victim;
  218.         if (null === $victim) {
  219.             return;
  220.         }
  221.         $this->data['victim'] = $victim->getData();
  222.     }
  223.     public function getHash(): ?string
  224.     {
  225.         return $this->hash;
  226.     }
  227.     public function setHash(?string $hash): void
  228.     {
  229.         $this->hash $hash;
  230.     }
  231.     public function isVerified(): bool
  232.     {
  233.         return $this->verified;
  234.     }
  235.     public function setVerified(bool $verified): void
  236.     {
  237.         $this->verified $verified;
  238.     }
  239. }