openvk/Web/Presenters/BlacklistPresenter.php
n1rwana 29f482419c
Перенос ветки blacklist (#900)
* Blacklist

* Config

* upd

* Added restrictions in the users.get method

* ok

* Update en.strings

* ok 2.0

---------

Co-authored-by: Vladimir Barinov <veselcraft@icloud.com>
2023-06-15 12:36:36 +03:00

43 lines
1.3 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 renderAddToBlacklist(): 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", tr("success"), tr("user_blacklisted", $target->getCanonicalName()));
}
function renderRemoveFromBlacklist(): void
{
$this->willExecuteWriteAction();
$this->assertUserLoggedIn();
$record = $this->blacklists->getByAuthorAndTarget($this->user->identity->getId(), $this->postParam("id"));
$name = $record->getTarget()->getCanonicalName();
$record->delete(false);
$this->flashFail("succ", tr("success"), tr("user_removed_from_the_blacklist", $name));
}
}