Photos: Fix creating and deleting albums in groups

Closes #171
This commit is contained in:
Maxim Leshchenko 2022-01-02 17:15:49 +02:00
parent c10b8274a6
commit 413e2ac6f0
No known key found for this signature in database
GPG key ID: BB9C44A8733FBEEE
2 changed files with 10 additions and 6 deletions

View file

@ -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

View file

@ -39,6 +39,6 @@
</form>
<hr/>
<center>
{_"you_can_also"} <a href="/album{$album->getOwner()->getId()}_{$album->getId()}/delete?hash={rawurlencode($csrfToken)}">{_"delete_album"}</a>.
{_"you_can_also"} <a href="/album{$album->getOwner() instanceof openvk\Web\Models\Entities\Club ? '-' : ''}{$album->getOwner()->getId()}_{$album->getId()}/delete.pl?hash={rawurlencode($csrfToken)}">{_"delete_album"}</a>.
</center>
{/block}