From ccf618a5ab6d7f5bb5230a89962d76f74b443ab0 Mon Sep 17 00:00:00 2001 From: lalka2016 <99399973+lalka2016@users.noreply.github.com> Date: Wed, 9 Aug 2023 12:53:36 +0300 Subject: [PATCH] Remove repeated code, fix loaded buttons on chr... ...ome and fix getting suggested posts via API.Wall.getPost --- ServiceAPI/Wall.php | 7 ++- Web/Presenters/GroupPresenter.php | 53 ++++--------------- Web/Presenters/templates/@layout.xml | 2 +- Web/Presenters/templates/Group/View.xml | 2 +- .../components/notifications/7/_18_5_.xml | 2 +- Web/routes.yml | 4 +- Web/static/css/main.css | 9 +++- 7 files changed, 28 insertions(+), 51 deletions(-) diff --git a/ServiceAPI/Wall.php b/ServiceAPI/Wall.php index 1b9bcabb..69397e2d 100644 --- a/ServiceAPI/Wall.php +++ b/ServiceAPI/Wall.php @@ -2,7 +2,7 @@ namespace openvk\ServiceAPI; use openvk\Web\Models\Entities\Post; use openvk\Web\Models\Entities\User; -use openvk\Web\Models\Entities\Notifications\{PostAcceptedNotification}; +use openvk\Web\Models\Entities\Notifications\PostAcceptedNotification; use openvk\Web\Models\Repositories\{Posts, Notes}; class Wall implements Handler @@ -22,7 +22,10 @@ class Wall implements Handler { $post = $this->posts->get($id); if(!$post || $post->isDeleted()) - $reject("No post with id=$id"); + $reject(53, "No post with id=$id"); + + if($post->getSuggestionType() != 0) + $reject(25, "Can't get suggested post"); $res = (object) []; $res->id = $post->getId(); diff --git a/Web/Presenters/GroupPresenter.php b/Web/Presenters/GroupPresenter.php index e1ad1ca0..07c73c18 100644 --- a/Web/Presenters/GroupPresenter.php +++ b/Web/Presenters/GroupPresenter.php @@ -410,7 +410,7 @@ final class GroupPresenter extends OpenVKPresenter $this->flashFail("succ", tr("information_-1"), tr("group_owner_setted", $newOwner->getCanonicalName(), $club->getName())); } - function renderSuggestedThisUser(int $id) + function renderSuggested(int $id): void { $this->assertUserLoggedIn(); @@ -420,57 +420,26 @@ final class GroupPresenter extends OpenVKPresenter else $this->template->club = $club; - if($club->getWallType() == 1) { + if($club->getWallType() == 0) { $this->flash("err", tr("error_suggestions"), tr("error_suggestions_closed")); $this->redirect("/club".$club->getId()); } - - if($club->getWallType() == 0) { - $this->flash("err", tr("error_suggestions"), tr("error_suggestions_open")); - $this->redirect("/club".$club->getId()); - } - - if($club->canBeModifiedBy($this->user->identity)) { - $this->flash("err", tr("error_suggestions"), "No sense"); - $this->redirect("/club".$club->getId()); - } - - $this->template->posts = (new Posts)->getSuggestedPostsByUser($club->getId(), $this->user->id, (int) ($this->queryParam("p") ?? 1)); - $this->template->count = (new Posts)->getSuggestedPostsCountByUser($club->getId(), $this->user->id); - $this->template->type = "my"; - $this->template->page = (int) ($this->queryParam("p") ?? 1); - $this->template->_template = "Group/Suggested.xml"; - } - - function renderSuggestedAll(int $id) - { - $this->assertUserLoggedIn(); - - $club = $this->clubs->get($id); - if(!$club) - $this->notFound(); - else - $this->template->club = $club; - + if($club->getWallType() == 1) { - $this->flash("err", tr("error_suggestions"), tr("error_suggestions_closed")); - $this->redirect("/club".$club->getId()); - } - - if($club->getWallType() == 0) { $this->flash("err", tr("error_suggestions"), tr("error_suggestions_open")); $this->redirect("/club".$club->getId()); } - + if(!$club->canBeModifiedBy($this->user->identity)) { - $this->flash("err", tr("error_suggestions"), tr("error_suggestions_access")); - $this->redirect("/club".$club->getId()); + $this->template->posts = (new Posts)->getSuggestedPostsByUser($club->getId(), $this->user->id, (int) ($this->queryParam("p") ?? 1)); + $this->template->count = (new Posts)->getSuggestedPostsCountByUser($club->getId(), $this->user->id); + $this->template->type = "my"; + } else { + $this->template->posts = (new Posts)->getSuggestedPosts($club->getId(), (int) ($this->queryParam("p") ?? 1)); + $this->template->count = (new Posts)->getSuggestedPostsCount($club->getId()); + $this->template->type = "everyone"; } - $this->template->posts = (new Posts)->getSuggestedPosts($club->getId(), (int) ($this->queryParam("p") ?? 1)); - $this->template->count = (new Posts)->getSuggestedPostsCount($club->getId()); - $this->template->type = "everyone"; $this->template->page = (int) ($this->queryParam("p") ?? 1); - $this->template->_template = "Group/Suggested.xml"; } } diff --git a/Web/Presenters/templates/@layout.xml b/Web/Presenters/templates/@layout.xml index 5c006ea5..e9aecafb 100644 --- a/Web/Presenters/templates/@layout.xml +++ b/Web/Presenters/templates/@layout.xml @@ -219,7 +219,7 @@ {$club->getName()} diff --git a/Web/Presenters/templates/Group/View.xml b/Web/Presenters/templates/Group/View.xml index 5d89b1bf..8abfc5ef 100644 --- a/Web/Presenters/templates/Group/View.xml +++ b/Web/Presenters/templates/Group/View.xml @@ -96,7 +96,7 @@
{presenter "openvk!Wall->wallEmbedded", -$club->getId()} diff --git a/Web/Presenters/templates/components/notifications/7/_18_5_.xml b/Web/Presenters/templates/components/notifications/7/_18_5_.xml index 4eee6670..6f1591f0 100644 --- a/Web/Presenters/templates/components/notifications/7/_18_5_.xml +++ b/Web/Presenters/templates/components/notifications/7/_18_5_.xml @@ -1,5 +1,5 @@ {var $club = $notification->getModel(1)} {_nt_in_club} -{$club->getName()} +{$club->getName()} {_nt_new_suggested_posts} diff --git a/Web/routes.yml b/Web/routes.yml index 2dbc8a2b..6b1c1be4 100644 --- a/Web/routes.yml +++ b/Web/routes.yml @@ -202,9 +202,7 @@ routes: - url: "/club{num}/setAdmin" handler: "Group->modifyAdmin" - url: "/club{num}/suggested" - handler: "Group->suggestedThisUser" - - url: "/club{num}/suggested/all" - handler: "Group->suggestedAll" + handler: "Group->suggested" - url: "/groups{num}" handler: "User->groups" - url: "/groups_pin" diff --git a/Web/static/css/main.css b/Web/static/css/main.css index b1fad4f0..66fb432a 100644 --- a/Web/static/css/main.css +++ b/Web/static/css/main.css @@ -2717,5 +2717,12 @@ body.article .floating_sidebar, body.article .page_content { .button.loaded { background: #595959 url("/assets/packages/static/openvk/img/loading_mini.gif") no-repeat 50% 50%; - padding: 16px 40px 6px 4px; + padding: 2px 9px 7px 39px; + margin-bottom: -6px; +} + +@-moz-document url-prefix() { + .button.loaded { + padding: 16px 40px 6px 4px !important; + } }