diff --git a/Web/Presenters/GroupPresenter.php b/Web/Presenters/GroupPresenter.php index a0b83a59..2933ecda 100644 --- a/Web/Presenters/GroupPresenter.php +++ b/Web/Presenters/GroupPresenter.php @@ -250,7 +250,40 @@ final class GroupPresenter extends OpenVKPresenter $this->flash("succ", "Изменения сохранены", "Новые данные появятся в вашей группе."); } } - + function renderEditAvatar(int $id) + { + $this->assertUserLoggedIn(); + $this->willExecuteWriteAction(); + $club = $this->clubs->get($id); + if(!$club ||!$club->canBeModifiedBy($this->user->identity)) + { + $this->flashFail("err", "Неизвестная ошибка", "Не удалось сохранить фотографию."); + } + if($_FILES["ava"]["error"] === UPLOAD_ERR_OK) { + $photo = new Photo; + try { + $anon = OPENVK_ROOT_CONF["openvk"]["preferences"]["wall"]["anonymousPosting"]["enable"]; + if($anon && $this->user->id === $club->getOwner()->getId()) + $anon = $club->isOwnerHidden(); + else if($anon) + $anon = $club->getManager($this->user->identity)->isHidden(); + + $photo->setOwner($this->user->id); + $photo->setDescription("Group image"); + $photo->setFile($_FILES["ava"]); + $photo->setCreated(time()); + $photo->setAnonymous($anon); + $photo->save(); + + (new Albums)->getClubAvatarAlbum($club)->addPhoto($photo); + } catch(ISE $ex) { + $name = $album->getName(); + $this->flashFail("err", "Неизвестная ошибка", "Не удалось сохранить фотографию."); + } + } + $this->flash("succ", "Фотография сохранена", "Новые данные появятся в вашей группе."); + $this->redirect("/club$id"); + } function renderEditBackdrop(int $id): void { $this->assertUserLoggedIn(); diff --git a/Web/Presenters/templates/Group/View.xml b/Web/Presenters/templates/Group/View.xml index bc10caba..219b751e 100644 --- a/Web/Presenters/templates/Group/View.xml +++ b/Web/Presenters/templates/Group/View.xml @@ -118,8 +118,8 @@ diff --git a/Web/routes.yml b/Web/routes.yml index 0dffb7bf..5a8c4f27 100644 --- a/Web/routes.yml +++ b/Web/routes.yml @@ -199,6 +199,8 @@ routes: handler: "Group->admin" - url: "/club{num}/setAdmin" handler: "Group->modifyAdmin" + - url: "/club{num}/al_avatars" + handler: "Group->editAvatar" - url: "/groups{num}" handler: "User->groups" - url: "/groups_pin" diff --git a/Web/static/img/upload.png b/Web/static/img/upload.png index e6280bc4..033009d2 100644 Binary files a/Web/static/img/upload.png and b/Web/static/img/upload.png differ