<?php declare(strict_types=1);
namespace App\Entity;
use App\Model\ContentReportData;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use RuntimeException;
/**
* @ORM\Entity(repositoryClass="App\Repository\ContentReportRepository")
* @ORM\Table()
*/
class ContentReport
{
/**
* @var string[]
*/
public static array $typeOfInfringement = [
'type.personal_right' => 'personal right',
'type.copyright' => 'copyright',
'type.rules_law' => 'rules/law',
];
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private ?int $id = null;
/**
* @var array<mixed>
* @ORM\Column(type="json")
*/
private array $data = [];
/**
* @ORM\Column(type="datetime")
* @Gedmo\Timestampable(on="update")
*/
private DateTime $lastModified;
private ?string $url = null;
private ?string $type = null;
private ?string $text = null;
private ?string $signature = null;
private ?ContentReportData $reporter = null;
private bool $reporterIsVictim = false;
private bool $authorized = false;
private ?ContentReportData $victim = null;
/**
* @ORM\Column(type="string")
*/
private ?string $hash = null;
/**
* @ORM\Column(type="boolean")
*/
private bool $verified = false;
public function __construct()
{
$this->lastModified = new DateTime();
}
public function getId(): ?int
{
return $this->id;
}
public function setId(int $id): void
{
$this->id = $id;
}
/**
* @return mixed[]
*/
public function getData(): array
{
return $this->data;
}
/**
* @param array<mixed> $data
*/
public function setData(array $data): void
{
$this->data = $data;
}
public function getLastModified(): DateTime
{
return $this->lastModified;
}
public function setLastModified(DateTime $lastModified): void
{
$this->lastModified = $lastModified;
}
public function getUrl(): ?string
{
if (null === $this->url && isset($this->data['url'])) {
if (!is_string($this->data['url'])) {
throw new RuntimeException('Invalid data on key "url"');
}
$this->url = $this->data['url'];
}
return $this->url;
}
public function setUrl(?string $url): void
{
$this->data['url'] = $url;
$this->url = $url;
}
public function getType(): ?string
{
if (null === $this->type && isset($this->data['type'])) {
if (!is_string($this->data['type'])) {
throw new RuntimeException('Invalid data on key "type"');
}
$this->type = $this->data['type'];
}
return $this->type;
}
public function setType(string $type): void
{
$this->data['type'] = $type;
$this->type = $type;
}
public function getText(): ?string
{
if (null === $this->text && isset($this->data['text'])) {
if (!is_string($this->data['text'])) {
throw new RuntimeException('Invalid data on key "text"');
}
$this->text = $this->data['text'];
}
return $this->text;
}
public function setText(string $text): void
{
$this->data['text'] = $text;
$this->text = $text;
}
public function getSignature(): ?string
{
if (null === $this->signature && isset($this->data['signature'])) {
if (!is_string($this->data['signature'])) {
throw new RuntimeException('Invalid data on key "signature"');
}
$this->signature = $this->data['signature'];
}
return $this->signature;
}
public function setSignature(string $signature): void
{
$this->data['signature'] = $signature;
$this->signature = $signature;
}
public function getTypeName(): string
{
return array_flip(self::$typeOfInfringement)[$this->getType()];
}
public function isReporterIsVictim(): bool
{
if (!$this->reporterIsVictim && isset($this->data['reporterIsVictim'])) {
if (!is_bool($this->data['reporterIsVictim'])) {
throw new RuntimeException('Invalid data on key "reporterIsVictim"');
}
$this->reporterIsVictim = $this->data['reporterIsVictim'];
}
return $this->reporterIsVictim;
}
public function setReporterIsVictim(bool $reporterIsVictim): void
{
$this->data['reporterIsVictim'] = $reporterIsVictim;
$this->reporterIsVictim = $reporterIsVictim;
}
public function isAuthorized(): bool
{
if (!$this->authorized && isset($this->data['authorized'])) {
if (!is_bool($this->data['authorized'])) {
throw new RuntimeException('Invalid data on key "authorized"');
}
$this->authorized = $this->data['authorized'];
}
return $this->authorized;
}
public function setAuthorized(bool $authorized): void
{
$this->data['authorized'] = $authorized;
$this->authorized = $authorized;
}
public function getReporter(): ContentReportData
{
if (null === $this->reporter) {
$reporter = [];
if (isset($this->data['victim']) && is_array($this->data['victim'])) {
$reporter = $this->data['victim'];
}
$this->reporter = new ContentReportData($reporter);
}
return $this->reporter;
}
public function setReporter(?ContentReportData $reporter): void
{
$this->reporter = $reporter;
if (null === $reporter) {
return;
}
$this->data['reporter'] = $reporter->getData();
}
public function getVictim(): ?ContentReportData
{
if (null === $this->victim) {
if (true === $this->isReporterIsVictim()) {
return null;
}
$victim = [];
if (isset($this->data['victim']) && is_array($this->data['victim'])) {
$victim = $this->data['victim'];
}
$this->victim = new ContentReportData($victim);
}
return $this->victim;
}
public function setVictim(?ContentReportData $victim): void
{
$this->victim = $victim;
if (null === $victim) {
return;
}
$this->data['victim'] = $victim->getData();
}
public function getHash(): ?string
{
return $this->hash;
}
public function setHash(?string $hash): void
{
$this->hash = $hash;
}
public function isVerified(): bool
{
return $this->verified;
}
public function setVerified(bool $verified): void
{
$this->verified = $verified;
}
}