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