2021-09-20 23:08:35 +03:00
|
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
namespace openvk\Web\Presenters;
|
|
|
|
|
use openvk\Web\Models\Repositories\Users;
|
|
|
|
|
use openvk\Web\Models\Repositories\Reports;
|
2021-09-21 01:02:53 +03:00
|
|
|
|
use openvk\Web\Models\Repositories\Posts;
|
2021-09-20 23:08:35 +03:00
|
|
|
|
use openvk\Web\Models\Entities\Report;
|
|
|
|
|
|
|
|
|
|
final class ReportPresenter extends OpenVKPresenter
|
|
|
|
|
{
|
|
|
|
|
private $reports;
|
|
|
|
|
|
|
|
|
|
function __construct(Reports $reports)
|
|
|
|
|
{
|
|
|
|
|
$this->reports = $reports;
|
|
|
|
|
|
|
|
|
|
parent::__construct();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function renderList(): void
|
|
|
|
|
{
|
2021-12-05 10:57:15 +03:00
|
|
|
|
$this->assertUserLoggedIn();
|
2021-09-21 01:02:53 +03:00
|
|
|
|
$this->assertPermission('openvk\Web\Models\Entities\TicketReply', 'write', 0);
|
|
|
|
|
|
2021-09-20 23:08:35 +03:00
|
|
|
|
$this->template->reports = $this->reports->getReports(0, (int)($this->queryParam("p") ?? 1));
|
2021-09-25 16:59:18 +03:00
|
|
|
|
$this->template->count = $this->reports->getReportsCount();
|
2021-09-20 23:08:35 +03:00
|
|
|
|
$this->template->paginatorConf = (object) [
|
|
|
|
|
"count" => $this->template->count,
|
|
|
|
|
"page" => $this->queryParam("p") ?? 1,
|
|
|
|
|
"amount" => NULL,
|
|
|
|
|
"perPage" => 15,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function renderView(int $id): void
|
|
|
|
|
{
|
2021-12-05 10:57:15 +03:00
|
|
|
|
$this->assertUserLoggedIn();
|
2021-09-21 01:02:53 +03:00
|
|
|
|
$this->assertPermission('openvk\Web\Models\Entities\TicketReply', 'write', 0);
|
|
|
|
|
|
2021-09-20 23:08:35 +03:00
|
|
|
|
$report = $this->reports->get($id);
|
2021-09-25 16:59:18 +03:00
|
|
|
|
if(!$report || $report->isDeleted())
|
2021-09-20 23:08:35 +03:00
|
|
|
|
$this->notFound();
|
|
|
|
|
|
|
|
|
|
$this->template->report = $report;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-26 08:34:22 +03:00
|
|
|
|
function renderCreate(int $id): void
|
2021-09-20 23:08:35 +03:00
|
|
|
|
{
|
|
|
|
|
$this->assertUserLoggedIn();
|
|
|
|
|
$this->willExecuteWriteAction();
|
|
|
|
|
|
|
|
|
|
if(!$id)
|
2021-09-26 08:34:22 +03:00
|
|
|
|
exit(json_encode([ "error" => tr("error_segmentation") ]));
|
2021-09-20 23:08:35 +03:00
|
|
|
|
|
2021-09-26 08:34:22 +03:00
|
|
|
|
// At this moment, only Posts will be implemented
|
2021-09-26 08:42:41 +03:00
|
|
|
|
if($this->queryParam("type") == 'post') {
|
2021-09-26 08:34:22 +03:00
|
|
|
|
$post = (new Posts)->get(intval($id));
|
|
|
|
|
if(!$post)
|
|
|
|
|
exit(json_encode([ "error" => "Unable to report nonexistent content" ]));
|
2021-09-21 01:02:53 +03:00
|
|
|
|
|
2021-09-26 08:34:22 +03:00
|
|
|
|
$report = new Report;
|
|
|
|
|
$report->setUser_id($this->user->id);
|
|
|
|
|
$report->setTarget_id($id);
|
|
|
|
|
$report->setType($this->queryParam("type"));
|
|
|
|
|
$report->setReason($this->queryParam("reason"));
|
|
|
|
|
$report->setCreated(time());
|
|
|
|
|
$report->save();
|
|
|
|
|
|
|
|
|
|
exit(json_encode([ "reason" => $this->queryParam("reason") ]));
|
|
|
|
|
} else {
|
|
|
|
|
exit(json_encode([ "error" => "Unable to submit a report on this content type" ]));
|
2021-09-20 23:08:35 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-25 16:59:18 +03:00
|
|
|
|
function renderAction(int $id): void
|
2021-09-21 01:02:53 +03:00
|
|
|
|
{
|
|
|
|
|
$this->assertUserLoggedIn();
|
|
|
|
|
$this->willExecuteWriteAction();
|
|
|
|
|
$this->assertPermission('openvk\Web\Models\Entities\TicketReply', 'write', 0);
|
|
|
|
|
|
2021-09-25 16:59:18 +03:00
|
|
|
|
if($this->postParam("ban")) {
|
2021-09-28 18:52:04 +03:00
|
|
|
|
$report = $this->reports->get($id);
|
2021-09-25 16:59:18 +03:00
|
|
|
|
if(!$report) $this->notFound();
|
2021-09-26 08:34:22 +03:00
|
|
|
|
if($report->isDeleted()) $this->notFound();
|
2021-09-25 16:59:18 +03:00
|
|
|
|
if(is_null($this->user))
|
|
|
|
|
$this->flashFail("err", "Ошибка доступа", "Недостаточно прав для модификации данного ресурса.");
|
|
|
|
|
|
|
|
|
|
$report->banUser();
|
|
|
|
|
$report->deleteContent();
|
|
|
|
|
$this->flash("suc", "Смэрть...", "Пользователь успешно забанен.");
|
|
|
|
|
}else if($this->postParam("delete")){
|
2021-09-28 18:52:04 +03:00
|
|
|
|
$report = $this->reports->get($id);
|
2021-09-25 16:59:18 +03:00
|
|
|
|
if(!$report) $this->notFound();
|
2021-09-26 08:34:22 +03:00
|
|
|
|
if($report->isDeleted()) $this->notFound();
|
2021-09-25 16:59:18 +03:00
|
|
|
|
if(is_null($this->user))
|
|
|
|
|
$this->flashFail("err", "Ошибка доступа", "Недостаточно прав для модификации данного ресурса.");
|
|
|
|
|
|
|
|
|
|
$report->deleteContent();
|
|
|
|
|
$this->flash("suc", "Нехай живе!", "Контент удалён, а пользователю прилетело предупреждение.");
|
|
|
|
|
}else if($this->postParam("ignore")){
|
2021-09-28 18:52:04 +03:00
|
|
|
|
$report = $this->reports->get($id);
|
2021-09-25 16:59:18 +03:00
|
|
|
|
if(!$report) $this->notFound();
|
|
|
|
|
if($report->isDeleted()) $this->notFound();
|
|
|
|
|
if(is_null($this->user))
|
|
|
|
|
$this->flashFail("err", "Ошибка доступа", "Недостаточно прав для модификации данного ресурса.");
|
|
|
|
|
|
|
|
|
|
$report->setDeleted();
|
|
|
|
|
$this->flash("suc", "Нехай живе!", "Жалоба проигнорирована.");
|
|
|
|
|
}
|
2021-09-28 18:52:04 +03:00
|
|
|
|
$this->redirect("/admin/reports");
|
2021-09-20 23:08:35 +03:00
|
|
|
|
}
|
|
|
|
|
}
|