From 413e2ac6f0b198fa84f6e2e2681ee391825c4e3e Mon Sep 17 00:00:00 2001 From: Maxim Leshchenko Date: Sun, 2 Jan 2022 17:15:49 +0200 Subject: [PATCH] Photos: Fix creating and deleting albums in groups Closes #171 --- Web/Presenters/PhotosPresenter.php | 14 +++++++++----- Web/Presenters/templates/Photos/EditAlbum.xml | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Web/Presenters/PhotosPresenter.php b/Web/Presenters/PhotosPresenter.php index 56247bde..b79b7547 100644 --- a/Web/Presenters/PhotosPresenter.php +++ b/Web/Presenters/PhotosPresenter.php @@ -70,9 +70,9 @@ final class PhotosPresenter extends OpenVKPresenter } if($_SERVER["REQUEST_METHOD"] === "POST") { - if(empty($this->postParam("name"))) { + if(empty($this->postParam("name"))) $this->flashFail("err", tr("error"), tr("error_segmentation")); - } + $album = new Album; $album->setOwner(isset($club) ? $club->getId() * -1 : $this->user->id); $album->setName($this->postParam("name")); @@ -80,7 +80,10 @@ final class PhotosPresenter extends OpenVKPresenter $album->setCreated(time()); $album->save(); - $this->redirect("/album" . $album->getOwner()->getId() . "_" . $album->getId(), static::REDIRECT_TEMPORARY); + if(isset($club)) + $this->redirect("/album-" . $album->getOwner()->getId() . "_" . $album->getId(), static::REDIRECT_TEMPORARY); + else + $this->redirect("/album" . $album->getOwner()->getId() . "_" . $album->getId(), static::REDIRECT_TEMPORARY); } } @@ -118,10 +121,11 @@ final class PhotosPresenter extends OpenVKPresenter if(is_null($this->user) || !$album->canBeModifiedBy($this->user->identity)) $this->flashFail("err", "Ошибка доступа", "Недостаточно прав для модификации данного ресурса."); - $name = $album->getName(); + $name = $album->getName(); + $owner = $album->getOwner(); $album->delete(); $this->flash("succ", "Альбом удалён", "Альбом $name был успешно удалён."); - $this->redirect("/albums" . $this->user->id); + $this->redirect("/albums" . ($owner instanceof Club ? "-" : "") . $owner->getId()); } function renderAlbum(int $owner, int $id): void diff --git a/Web/Presenters/templates/Photos/EditAlbum.xml b/Web/Presenters/templates/Photos/EditAlbum.xml index 9b0d4bde..1d2d01ae 100644 --- a/Web/Presenters/templates/Photos/EditAlbum.xml +++ b/Web/Presenters/templates/Photos/EditAlbum.xml @@ -39,6 +39,6 @@
- {_"you_can_also"} {_"delete_album"}. + {_"you_can_also"} {_"delete_album"}.
{/block}