fixes #1180: meeting/news pagination
This commit is contained in:
parent
e11b0db526
commit
df4f744f6d
|
@ -33,7 +33,7 @@
|
|||
<ul class="pagination justify-content-center">
|
||||
{% for p in range(1, pages) %}
|
||||
<li class="page-item{% if p == page %} active{% endif %}">
|
||||
<a class="page-link" href="{{ url('news', p == 1 ? {} : {'page': p}) }}">{{ p }}</a>
|
||||
<a class="page-link" href="{{ url( only_meetings ? 'meetings' : 'news', p == 1 ? {} : {'page': p}) }}">{{ p }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
|
|
@ -130,6 +130,10 @@ class NewsController extends BaseController
|
|||
$query = $query->where('is_meeting', true);
|
||||
}
|
||||
|
||||
$count = $query->count();
|
||||
$pagesCount = max(1, ceil($count / $perPage));
|
||||
$page = max(1, min($page, $pagesCount));
|
||||
|
||||
$news = $query
|
||||
->with('user')
|
||||
->withCount('comments')
|
||||
|
@ -140,14 +144,13 @@ class NewsController extends BaseController
|
|||
->limit($perPage)
|
||||
->offset(($page - 1) * $perPage)
|
||||
->get();
|
||||
$pagesCount = ceil($query->count() / $perPage);
|
||||
|
||||
return $this->renderView(
|
||||
'pages/news/overview.twig',
|
||||
[
|
||||
'news' => $news,
|
||||
'pages' => max(1, $pagesCount),
|
||||
'page' => max(1, min($page, $pagesCount)),
|
||||
'pages' => $pagesCount,
|
||||
'page' => $page,
|
||||
'only_meetings' => $onlyMeetings,
|
||||
'is_overview' => true,
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue