openvk/Web/Models/Entities/Report.php

98 lines
3.3 KiB
PHP
Raw Normal View History

<?php declare(strict_types=1);
namespace openvk\Web\Models\Entities;
use openvk\Web\Util\DateTime;
use Nette\Database\Table\ActiveRow;
use openvk\Web\Models\RowModel;
use Chandler\Database\DatabaseConnection;
2023-07-27 20:36:56 +03:00
use openvk\Web\Models\Repositories\{Applications, Comments, Notes, Users, Posts, Photos, Videos, Clubs};
use Chandler\Database\DatabaseConnection as DB;
use Nette\InvalidStateException as ISE;
use Nette\Database\Table\Selection;
class Report extends RowModel
{
protected $tableName = "reports";
function getId(): int
{
return $this->getRecord()->id;
}
function getStatus(): int
{
return $this->getRecord()->status;
}
function getContentType(): string
{
return $this->getRecord()->type;
}
function getReason(): string
{
return $this->getRecord()->reason;
}
function getTime(): DateTime
{
return new DateTime($this->getRecord()->date);
}
function isDeleted(): bool
{
if ($this->getRecord()->deleted === 0)
{
return false;
} elseif ($this->getRecord()->deleted === 1) {
return true;
}
}
function authorId(): int
{
return $this->getRecord()->user_id;
}
2023-07-27 20:36:56 +03:00
function getUser(): User
{
2023-07-27 20:36:56 +03:00
return (new Users)->get((int) $this->getRecord()->user_id);
}
function getContentId(): int
{
2023-07-27 20:36:56 +03:00
return (int) $this->getRecord()->target_id;
}
function getContentObject()
{
2023-07-27 20:36:56 +03:00
if ($this->getContentType() == "post") return (new Posts)->get($this->getContentId());
else if ($this->getContentType() == "photo") return (new Photos)->get($this->getContentId());
else if ($this->getContentType() == "video") return (new Videos)->get($this->getContentId());
else if ($this->getContentType() == "group") return (new Clubs)->get($this->getContentId());
else if ($this->getContentType() == "comment") return (new Comments)->get($this->getContentId());
else if ($this->getContentType() == "note") return (new Notes)->get($this->getContentId());
else if ($this->getContentType() == "app") return (new Applications)->get($this->getContentId());
else return null;
}
2021-12-05 10:57:15 +03:00
function getAuthor(): RowModel
{
return (new Posts)->get($this->getContentId())->getOwner();
}
2023-07-27 20:36:56 +03:00
function banUser($initiator)
{
2023-07-27 20:36:56 +03:00
$this->getAuthor()->ban("**content-" . $this->getContentType() . "-" . $this->getContentId() . "**", false, time() + $this->getAuthor()->getNewBanTime(), $initiator);
}
function deleteContent()
{
2023-07-27 20:36:56 +03:00
$pubTime = $this->getContentObject()->getPublicationTime();
$name = $this->getContentObject()->getName();
$this->getAuthor()->adminNotify("Ваш контент, который вы опубликовали $pubTime ($name) был удалён модераторами инстанса. За повторные или серьёзные нарушения вас могут заблокировать.");
$this->getContentObject()->delete($this->getContentType() !== "app");
$this->setDeleted(1);
2021-09-21 01:02:53 +03:00
$this->save();
}
}