2022-08-27 18:31:02 +03:00
|
|
|
<?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;
|
|
|
|
}
|
|
|
|
|
2022-09-04 00:30:01 +03:00
|
|
|
function renderAddToBlacklist(): void
|
2022-08-27 18:31:02 +03:00
|
|
|
{
|
|
|
|
$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();
|
|
|
|
|
2022-09-05 22:30:01 +03:00
|
|
|
$this->flashFail("succ", tr("success"), tr("user_blacklisted", $target->getCanonicalName()));
|
2022-08-27 18:31:02 +03:00
|
|
|
}
|
|
|
|
|
2022-09-04 00:30:01 +03:00
|
|
|
function renderRemoveFromBlacklist(): void
|
2022-08-27 18:31:02 +03:00
|
|
|
{
|
|
|
|
$this->willExecuteWriteAction();
|
|
|
|
$this->assertUserLoggedIn();
|
|
|
|
|
2022-08-28 15:04:10 +03:00
|
|
|
$record = $this->blacklists->getByAuthorAndTarget($this->user->identity->getId(), $this->postParam("id"));
|
2022-08-27 18:31:02 +03:00
|
|
|
$name = $record->getTarget()->getCanonicalName();
|
2022-08-28 15:04:10 +03:00
|
|
|
$record->delete(false);
|
2022-08-27 18:31:02 +03:00
|
|
|
|
2022-09-05 22:30:01 +03:00
|
|
|
$this->flashFail("succ", tr("success"), tr("user_removed_from_the_blacklist", $name));
|
2022-08-27 18:31:02 +03:00
|
|
|
}
|
2022-09-04 00:30:01 +03:00
|
|
|
}
|