mirror of
https://github.com/openvk/openvk
synced 2024-12-22 16:42:32 +03:00
Compare commits
2 commits
1de1ebe719
...
237400df71
Author | SHA1 | Date | |
---|---|---|---|
|
237400df71 | ||
|
00f5b53ea8 |
2 changed files with 44 additions and 0 deletions
41
VKAPI/Handlers/Reports.php
Normal file
41
VKAPI/Handlers/Reports.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php declare(strict_types=1);
|
||||
namespace openvk\VKAPI\Handlers;
|
||||
use openvk\Web\Models\Entities\Report;
|
||||
use openvk\Web\Models\Repositories\Reports as ReportsRepo;
|
||||
|
||||
final class Reports extends VKAPIRequestHandler
|
||||
{
|
||||
function add(string $type, int $id, string $reason): object
|
||||
{
|
||||
$this->requireUser();
|
||||
$this->willExecuteWriteAction();
|
||||
|
||||
if ($id <= 0) {
|
||||
$this->fail(100, "ID must be a positive number");
|
||||
}
|
||||
|
||||
if(mb_strlen(trim($reason)) === 0) {
|
||||
$this->fail(100, "Reason can't be empty");
|
||||
}
|
||||
|
||||
if ($type === "user" && $id === $this->getUser()->getId()) {
|
||||
$this->fail(100, "You can't report yourself");
|
||||
}
|
||||
|
||||
if(in_array($type, ["post", "photo", "video", "group", "comment", "note", "app", "user"])) {
|
||||
if (count(iterator_to_array((new ReportsRepo)->getDuplicates($type, $id, NULL, $this->getUser()->getId()))) <= 0) {
|
||||
$report = new Report;
|
||||
$report->setUser_id($this->getUser()->getId());
|
||||
$report->setTarget_id($id);
|
||||
$report->setType($type);
|
||||
$report->setReason($reason);
|
||||
$report->setCreated(time());
|
||||
$report->save();
|
||||
}
|
||||
|
||||
return (object) [ "reason" => $reason ];
|
||||
} else {
|
||||
$this->fail(3, "Unable to submit a report on this content type");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -88,6 +88,9 @@ final class ReportPresenter extends OpenVKPresenter
|
|||
if(!$id)
|
||||
exit(json_encode([ "error" => tr("error_segmentation") ]));
|
||||
|
||||
if ($this->queryParam("type") === "user" && $id === $this->user->id)
|
||||
exit(json_encode(["reason" => "You can't report yourself"]));
|
||||
|
||||
if(in_array($this->queryParam("type"), ["post", "photo", "video", "group", "comment", "note", "app", "user"])) {
|
||||
if (count(iterator_to_array($this->reports->getDuplicates($this->queryParam("type"), $id, NULL, $this->user->id))) <= 0) {
|
||||
$report = new Report;
|
||||
|
|
Loading…
Reference in a new issue