diff --git a/Web/Models/Entities/Video.php b/Web/Models/Entities/Video.php index 39797966..f4b42934 100644 --- a/Web/Models/Entities/Video.php +++ b/Web/Models/Entities/Video.php @@ -69,6 +69,11 @@ class Video extends Media return $this->getVideoDriver()->getThumbnailURL(); } } + + function getOwnerVideo(): int + { + return $this->getRecord()->owner; + } function setLink(string $link): string { @@ -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(); + } } diff --git a/Web/Presenters/VideosPresenter.php b/Web/Presenters/VideosPresenter.php index 00a721df..5732987f 100644 --- a/Web/Presenters/VideosPresenter.php +++ b/Web/Presenters/VideosPresenter.php @@ -38,6 +38,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); @@ -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; + } }