feat: add comments sort

This commit is contained in:
mrilyew 2025-05-24 21:47:11 +03:00 committed by Alexander Minkin
parent dce143a48e
commit 626770ef0c
8 changed files with 49 additions and 5 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

View file

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

View file

@ -826,6 +826,9 @@
"sort_up" = "Сортировать по дате создания вверх";
"sort_down" = "Сортировать по дате создания вниз";
"new_first" = "Сначала новые";
"old_first" = "Сначала старые";
/* Videos */
"videos" = "Видеозаписи";