diff --git a/Web/Models/Entities/Postable.php b/Web/Models/Entities/Postable.php index 75d774b5..b9309c45 100644 --- a/Web/Models/Entities/Postable.php +++ b/Web/Models/Entities/Postable.php @@ -75,9 +75,9 @@ abstract class Postable extends Attachable return new DateTime($edited); } - public function getComments(int $page, ?int $perPage = null): \Traversable + public function getComments(int $page, ?int $perPage = null, string $sort = "ASC"): \Traversable { - return (new Comments())->getCommentsByTarget($this, $page, $perPage); + return (new Comments())->getCommentsByTarget($this, $page, $perPage, $sort); } public function getCommentsCount(): int diff --git a/Web/Presenters/WallPresenter.php b/Web/Presenters/WallPresenter.php index 89b1915d..dbdfdde0 100644 --- a/Web/Presenters/WallPresenter.php +++ b/Web/Presenters/WallPresenter.php @@ -469,7 +469,11 @@ final class WallPresenter extends OpenVKPresenter } $this->template->cCount = $post->getCommentsCount(); $this->template->cPage = (int) ($_GET["p"] ?? 1); - $this->template->comments = iterator_to_array($post->getComments($this->template->cPage)); + $this->template->sort = $this->queryParam("sort") ?? "asc"; + + $input_sort = $this->template->sort == "asc" ? "ASC" : "DESC"; + + $this->template->comments = iterator_to_array($post->getComments($this->template->cPage, null, $input_sort)); } public function renderLike(int $wall, int $post_id): void diff --git a/Web/Presenters/templates/Wall/Post.xml b/Web/Presenters/templates/Wall/Post.xml index 126d12b1..be8b391c 100644 --- a/Web/Presenters/templates/Wall/Post.xml +++ b/Web/Presenters/templates/Wall/Post.xml @@ -36,7 +36,8 @@ count => $cCount, page => $cPage, model => "posts", - parent => $post } + parent => $post, + sort => $sort} </div> <div style="float: left; min-height: 100px; width: 32%;padding-left: 10px;width: 30%;"> <h4>{_actions}</h4> diff --git a/Web/Presenters/templates/components/comments.xml b/Web/Presenters/templates/components/comments.xml index 53253b5f..3c9a858e 100644 --- a/Web/Presenters/templates/components/comments.xml +++ b/Web/Presenters/templates/components/comments.xml @@ -1,5 +1,18 @@ -<h4 n:if="$showTitle ?? true">{_comments} ({$count})</h4> +<div> + <h4 n:if="$showTitle ?? true">{_comments} ({$count})</h4> + {if !is_null($sort) && $count > 5} + <a class="sort_link" n:attr="href => $sort == 'desc' ? '?sort=asc' : '?sort=desc'"> + {if $sort == 'desc'} + {_new_first} + {else} + {_old_first} + {/if} + + <div n:class="sort_link_icon, $sort == 'desc' ? sort_link_icon_desc : sort_link_icon_asc"></div> + </a> + {/if} +</div> <div n:ifset="$thisUser" id="standaloneCommentBox"> {var $commentsURL = "/al_comments/create/$model/" . $parent->getId()} {var $club = $parent instanceof \openvk\Web\Models\Entities\Post && $parent->getTargetWall() < 0 ? (new openvk\Web\Models\Repositories\Clubs)->get(abs($parent->getTargetWall())) : $club} diff --git a/Web/static/css/main.css b/Web/static/css/main.css index 389134a1..8dd47fd7 100644 --- a/Web/static/css/main.css +++ b/Web/static/css/main.css @@ -4314,3 +4314,23 @@ hr { .deleted_mark_average { padding: 5px 61px; } + +.sort_link { + padding: 5px 2px; + display: inline-block; +} + +.sort_link_icon { + background: url(/assets/packages/static/openvk/img/wall.png?v=3) no-repeat; + display: inline-block; + height: 11px; + width: 9px; +} + +.sort_link_icon_desc { + background-position: 0px -15px; +} + +.sort_link_icon_asc { + background-position: -11px -15px; +} diff --git a/Web/static/img/wall.png b/Web/static/img/wall.png index 197dca8d..e8577b9c 100644 Binary files a/Web/static/img/wall.png and b/Web/static/img/wall.png differ diff --git a/locales/en.strings b/locales/en.strings index 1f3df4b7..74915a50 100644 --- a/locales/en.strings +++ b/locales/en.strings @@ -868,6 +868,9 @@ "sort_up" = "Sort by ID up"; "sort_down" = "Sort by ID down"; +"new_first" = "New frist"; +"old_first" = "Old first"; + /* Videos */ "videos" = "Videos"; diff --git a/locales/ru.strings b/locales/ru.strings index 4327ee06..4d2751d2 100644 --- a/locales/ru.strings +++ b/locales/ru.strings @@ -826,6 +826,9 @@ "sort_up" = "Сортировать по дате создания вверх"; "sort_down" = "Сортировать по дате создания вниз"; +"new_first" = "Сначала новые"; +"old_first" = "Сначала старые"; + /* Videos */ "videos" = "Видеозаписи";