diff --git a/Web/Models/Entities/Report.php b/Web/Models/Entities/Report.php new file mode 100644 index 00000000..726b0ede --- /dev/null +++ b/Web/Models/Entities/Report.php @@ -0,0 +1,87 @@ +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; + } + + function getUser(): user + { + return (new Users)->get($this->getRecord()->user_id); + } + + function getContentId(): int + { + return $this->getRecord()->target_id; + } + + function getContentObject() + { + if ($this->getContentType() == "post") return (new Posts)->get($this->getContentId()); + else return null; + } + + // TODO: Localize that + function banUser() + { + $this->getUser()->ban("Banned by report. Ask Technical support for ban reason"); + } + + function deleteContent() + { + $this->getUser()->adminNotify("Ваш контент, который вы опубликовали " . $this->getContentObject()->getPublicationTime() . " был удалён модераторами инстанса. За повторные или серьёзные нарушения вас могут заблокировать."); + $this->getContentObject()->delete(); + $this->setDeleted(1); + $this->unwire(); + $this->save(); + } +} diff --git a/Web/Models/Repositories/Reports.php b/Web/Models/Repositories/Reports.php new file mode 100644 index 00000000..b0fdb90f --- /dev/null +++ b/Web/Models/Repositories/Reports.php @@ -0,0 +1,40 @@ +context = DatabaseConnection::i()->getContext(); + $this->reports = $this->context->table("reports"); + } + + private function toReport(?ActiveRow $ar): ?Report + { + return is_null($ar) ? NULL : new Report($ar); + } + + function getReports(int $state = 0, int $page = 1): \Traversable + { + foreach($this->reports->where(["deleted" => 0])->page($page, 15) as $t) + yield new Ticket($t); + } + + function getReportsCount(int $state = 0): int + { + return sizeof($this->tickets->where(["deleted" => 0, "type" => $state])); + } + + function get(int $id): ?Ticket + { + return $this->toTicket($this->tickets->get($id)); + } + + use \Nette\SmartObject; +} diff --git a/Web/Presenters/ReportPresenter.php b/Web/Presenters/ReportPresenter.php new file mode 100644 index 00000000..d7cc7fd3 --- /dev/null +++ b/Web/Presenters/ReportPresenter.php @@ -0,0 +1,81 @@ +reports = $reports; + + parent::__construct(); + } + + function renderList(): void + { + $this->template->reports = $this->reports->getReports(0, (int)($this->queryParam("p") ?? 1)); + $this->template->count = $this->notes->getReportsCount(); + $this->template->paginatorConf = (object) [ + "count" => $this->template->count, + "page" => $this->queryParam("p") ?? 1, + "amount" => NULL, + "perPage" => 15, + ]; + } + + function renderView(int $id): void + { + $report = $this->reports->get($id); + if(!$report || $note->isDeleted()) + $this->notFound(); + + $this->template->report = $report; + } + + function renderCreate(): void + { + $this->assertUserLoggedIn(); + $this->willExecuteWriteAction(); + + // ЛАПСКИЙ Я НЕ ДО КОНЦА ДОДЕЛАЛ Я ПРОСТО МЫТЬСЯ ПОШЁЛ + if(!$id) + $this->notFound(); + + if($_SERVER["REQUEST_METHOD"] === "POST") { + if(empty($this->postParam("name"))) { + $this->flashFail("err", tr("error"), tr("error_segmentation")); + } + + $note = new Note; + $note->setOwner($this->user->id); + $note->setCreated(time()); + $note->setName($this->postParam("name")); + $note->setSource($this->postParam("html")); + $note->save(); + + $this->redirect("/note" . $this->user->id . "_" . $note->getId()); + } + } + + function renderDelete(int $owner, int $id): void + { + $this->assertUserLoggedIn(); + $this->willExecuteWriteAction(); + $this->assertNoCSRF(); + + $note = $this->notes->get($id); + if(!$note) $this->notFound(); + if($note->getOwner()->getId() . "_" . $note->getId() !== $owner . "_" . $id || $note->isDeleted()) $this->notFound(); + if(is_null($this->user) || !$note->canBeModifiedBy($this->user->identity)) + $this->flashFail("err", "Ошибка доступа", "Недостаточно прав для модификации данного ресурса."); + + $name = $note->getName(); + $note->delete(); + $this->flash("succ", "Заметка удалена", "Заметка \"$name\" была успешно удалена."); + $this->redirect("/notes" . $this->user->id); + } +}