diff --git a/Web/Models/Entities/Club.php b/Web/Models/Entities/Club.php index 9d3e1d2c..65353fc7 100644 --- a/Web/Models/Entities/Club.php +++ b/Web/Models/Entities/Club.php @@ -89,6 +89,11 @@ class Club extends RowModel { return (new Users)->get($this->getRecord()->owner); } + + function getOwnerComment(): string + { + return is_null($this->getRecord()->owner_comment) ? "" : $this->getRecord()->owner_comment; + } function getDescription(): ?string { @@ -268,18 +273,6 @@ class Club extends RowModel { $rels = $this->getRecord()->related("group_coadmins.club")->page($page, 6); - foreach($rels as $rel) { - $rel = (new Users)->get($rel->user); - if(!$rel) continue; - - yield $rel; - } - } - - function getManagersWithComment(int $page = 1): \Traversable - { - $rels = $this->getRecord()->related("group_coadmins.club")->where("comment IS NOT NULL")->page($page, 10); - foreach($rels as $rel) { $rel = (new Managers)->get($rel->id); if(!$rel) continue; @@ -287,16 +280,16 @@ class Club extends RowModel yield $rel; } } + + function getManager(User $user): ?Manager + { + return (new Managers)->getByUserAndClub($user->getId(), $this->getId()); + } function getManagersCount(): int { return sizeof($this->getRecord()->related("group_coadmins.club")) + 1; } - - function getManagersCountWithComment(): int - { - return sizeof($this->getRecord()->related("group_coadmins.club")->where("comment IS NOT NULL")) + 1; - } function addManager(User $user, ?string $comment = NULL): void { diff --git a/Web/Models/Entities/Manager.php b/Web/Models/Entities/Manager.php index feefb69b..e58eef6e 100644 --- a/Web/Models/Entities/Manager.php +++ b/Web/Models/Entities/Manager.php @@ -17,7 +17,7 @@ class Manager extends RowModel return $this->getRecord()->id; } - function getUserId(): string + function getUserId(): int { return $this->getRecord()->user; } @@ -27,7 +27,7 @@ class Manager extends RowModel return (new Users)->get($this->getRecord()->user); } - function getClubId(): string + function getClubId(): int { return $this->getRecord()->club; } diff --git a/Web/Presenters/GroupPresenter.php b/Web/Presenters/GroupPresenter.php index 1042172d..16ac32ea 100644 --- a/Web/Presenters/GroupPresenter.php +++ b/Web/Presenters/GroupPresenter.php @@ -98,6 +98,7 @@ final class GroupPresenter extends OpenVKPresenter { $user = is_null($this->queryParam("user")) ? $this->postParam("user") : $this->queryParam("user"); $comment = $this->postParam("comment"); + $removeComment = $this->postParam("removeComment") === "1"; //$index = $this->queryParam("index"); if(!$user) $this->badRequest(); @@ -110,16 +111,34 @@ final class GroupPresenter extends OpenVKPresenter if(!$club->canBeModifiedBy($this->user->identity ?? NULL) && $club->getOwner()->getId() !== $user->getId()) $this->flashFail("err", "Ошибка доступа", "У вас недостаточно прав, чтобы изменять этот ресурс."); - /* if(!empty($index)){ - $manager = (new Managers)->get($index); - $manager->setComment($comment); + if($removeComment) { + if($club->getOwner()->getId() == $user->getId()) { + $club->setOwner_Comment(null); + $club->save(); + } else { + $manager = (new Managers)->getByUserAndClub($user->getId(), $club->getId()); + $manager->setComment(null); + $manager->save(); + } + + $this->flashFail("succ", "Операция успешна", "Комментарий к администратору удален"); + } elseif($comment) { + if(strlen($comment) > 36) { + $commentLength = (string) strlen($comment); + $this->flashFail("err", "Ошибка", "Комментарий слишком длинный ($commentLength символов вместо 36 символов)"); + return; + } + + if($club->getOwner()->getId() == $user->getId()) { + $club->setOwner_Comment($comment); + $club->save(); + } else { + $manager = (new Managers)->getByUserAndClub($user->getId(), $club->getId()); + $manager->setComment($comment); + $manager->save(); + } + $this->flashFail("succ", "Операция успешна", "Комментарий к администратору изменён"); - }else{ */ - if($comment) { - $manager = (new Managers)->getByUserAndClub($user->getId(), $club->getId()); - $manager->setComment($comment); - $manager->save(); - $this->flashFail("succ", "Операция успешна", "."); }else{ if($club->canBeModifiedBy($user)) { $club->removeManager($user); diff --git a/Web/Presenters/templates/Group/Followers.xml b/Web/Presenters/templates/Group/Followers.xml index c0eb8cca..f1d63a01 100644 --- a/Web/Presenters/templates/Group/Followers.xml +++ b/Web/Presenters/templates/Group/Followers.xml @@ -46,16 +46,36 @@ {$club->canBeModifiedBy($x) ? tr("administrator") : tr("follower")} -