mirror of
https://github.com/openvk/openvk
synced 2024-12-23 00:51:03 +03:00
Add video deletion
Co-authored-by: vovocka <22993408+veselcraft@users.noreply.github.com>
This commit is contained in:
parent
6d603d2f5c
commit
94cd52ccf5
2 changed files with 43 additions and 0 deletions
|
@ -70,6 +70,11 @@ class Video extends Media
|
|||
}
|
||||
}
|
||||
|
||||
function getOwnerVideo(): int
|
||||
{
|
||||
return $this->getRecord()->owner;
|
||||
}
|
||||
|
||||
function setLink(string $link): string
|
||||
{
|
||||
if(preg_match(file_get_contents(__DIR__ . "/../VideoDrivers/regex/youtube.txt"), $link, $matches)) {
|
||||
|
@ -84,4 +89,19 @@ class Video extends Media
|
|||
|
||||
return $pointer;
|
||||
}
|
||||
|
||||
function isDeleted(): bool
|
||||
{
|
||||
if ($this->getRecord()->deleted == 1)
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
function deleteVideo(): void
|
||||
{
|
||||
$this->setDeleted(1);
|
||||
$this->unwire();
|
||||
$this->save();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,8 @@ final class VideosPresenter extends OpenVKPresenter
|
|||
$user = $this->users->get($owner);
|
||||
if(!$user) $this->notFound();
|
||||
|
||||
if($this->videos->getByOwnerAndVID($owner, $vId)->isDeleted()) $this->notFound();
|
||||
|
||||
$this->template->user = $user;
|
||||
$this->template->video = $this->videos->getByOwnerAndVID($owner, $vId);
|
||||
$this->template->cCount = $this->template->video->getCommentsCount();
|
||||
|
@ -99,4 +101,25 @@ final class VideosPresenter extends OpenVKPresenter
|
|||
|
||||
$this->template->video = $video;
|
||||
}
|
||||
|
||||
function renderRemove(int $owner, int $vid): void
|
||||
{
|
||||
$this->assertUserLoggedIn();
|
||||
|
||||
$video = $this->videos->getByOwnerAndVID($owner, $vid);
|
||||
if(!$video)
|
||||
$this->notFound();
|
||||
$user = $this->user->id;
|
||||
|
||||
if(!is_null($user)) {
|
||||
if($video->getOwnerVideo() == $user) {
|
||||
$video->deleteVideo($owner, $vid);
|
||||
}
|
||||
} else {
|
||||
$this->flashFail("err", "Не удалось удалить пост", "Вы не вошли в аккаунт.");
|
||||
}
|
||||
|
||||
$this->redirect("/videos".$owner, static::REDIRECT_TEMPORARY);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue