mirror of
https://github.com/openvk/openvk
synced 2024-11-15 19:49:14 +03:00
43 lines
1.4 KiB
PHP
43 lines
1.4 KiB
PHP
|
<?php declare(strict_types=1);
|
||
|
namespace openvk\Web\Presenters;
|
||
|
use openvk\Web\Models\Entities\{BlacklistItem};
|
||
|
use openvk\Web\Models\Repositories\{Blacklists, Users};
|
||
|
use Chandler\Database\DatabaseConnection as DB;
|
||
|
|
||
|
final class BlacklistPresenter extends OpenVKPresenter
|
||
|
{
|
||
|
private $blacklists;
|
||
|
|
||
|
function __construct(Blacklists $blacklists)
|
||
|
{
|
||
|
$this->blacklists = $blacklists;
|
||
|
}
|
||
|
|
||
|
function renderAddToBl(): void
|
||
|
{
|
||
|
$this->willExecuteWriteAction();
|
||
|
$this->assertUserLoggedIn();
|
||
|
|
||
|
$record = new BlacklistItem;
|
||
|
$target = (new Users)->get((int) $this->postParam("id"));
|
||
|
|
||
|
$record->setAuthor($this->user->identity->getId());
|
||
|
$record->setTarget($this->postParam("id"));
|
||
|
$record->setCreated(time());
|
||
|
$record->save();
|
||
|
|
||
|
$this->flashFail("succ", "Успех", $target->getCanonicalName() . " занесён в чёрный список.");
|
||
|
}
|
||
|
|
||
|
function renderRemoveFromBl(): void
|
||
|
{
|
||
|
$this->willExecuteWriteAction();
|
||
|
$this->assertUserLoggedIn();
|
||
|
|
||
|
$record = new BlacklistItem(DB::i()->getContext()->table("blacklists")->where([ "author" => $this->user->identity->getId(), "target" => $this->postParam("id") ])->fetch());
|
||
|
$name = $record->getTarget()->getCanonicalName();
|
||
|
$record->delete(FALSE);
|
||
|
|
||
|
$this->flashFail("succ", "Успех", "$name удалён из чёрного списка.");
|
||
|
}
|
||
|
}
|