Compare commits
3 Commits
d1c926541a
...
1aad23b650
Author | SHA1 | Date | |
---|---|---|---|
1aad23b650 | |||
8dbc45a6d6 | |||
822cb4a8c2 |
@ -68,16 +68,17 @@ class EventController implements IAuthenticationRequired, ISecured
|
|||||||
{
|
{
|
||||||
$itemsPerPage = 10;
|
$itemsPerPage = 10;
|
||||||
$numberOfEvents = $this->eventRepository->countAllByCommunity($this->community);
|
$numberOfEvents = $this->eventRepository->countAllByCommunity($this->community);
|
||||||
$currentPage = Container::$request->query('page') ?: 1;
|
$pages = ceil($numberOfEvents / $itemsPerPage);
|
||||||
|
$currentPage = Container::$request->query('page') ?: 0;
|
||||||
$events = $this->eventRepository->getPagedByCommunity(
|
$events = $this->eventRepository->getPagedByCommunity(
|
||||||
$this->community,
|
$this->community,
|
||||||
$currentPage,
|
$currentPage * $itemsPerPage,
|
||||||
$itemsPerPage
|
$itemsPerPage
|
||||||
);
|
);
|
||||||
|
|
||||||
return new HtmlContent('events/events', [
|
return new HtmlContent('events/events', [
|
||||||
'community' => $this->community,
|
'community' => $this->community,
|
||||||
'pages' => ceil($numberOfEvents / $itemsPerPage),
|
'pages' => $pages,
|
||||||
'currentPage' => $currentPage,
|
'currentPage' => $currentPage,
|
||||||
'numberOfEvents' => $numberOfEvents,
|
'numberOfEvents' => $numberOfEvents,
|
||||||
'events' => $events
|
'events' => $events
|
||||||
|
@ -84,18 +84,19 @@ class TransactionController implements IAuthenticationRequired, ISecured
|
|||||||
$numberOfTransactions = $event ?
|
$numberOfTransactions = $event ?
|
||||||
$this->transactionRepository->countAllByEvent($event) :
|
$this->transactionRepository->countAllByEvent($event) :
|
||||||
$this->transactionRepository->countAllByCommunity($this->community);
|
$this->transactionRepository->countAllByCommunity($this->community);
|
||||||
$currentPage = Container::$request->query('page') ?: 1;
|
$pages = ceil($numberOfTransactions / $itemsPerPage);
|
||||||
|
$currentPage = Container::$request->query('page') ?: 0;
|
||||||
$transactions = $event ?
|
$transactions = $event ?
|
||||||
$this->transactionRepository->getPagedByEvent(
|
$this->transactionRepository->getPagedByEvent(
|
||||||
$event,
|
$event,
|
||||||
$currentPage,
|
$currentPage * $itemsPerPage,
|
||||||
$itemsPerPage,
|
$itemsPerPage,
|
||||||
true,
|
true,
|
||||||
['currency', 'payer_user', 'payee_user']
|
['currency', 'payer_user', 'payee_user']
|
||||||
) :
|
) :
|
||||||
$this->transactionRepository->getPagedByCommunity(
|
$this->transactionRepository->getPagedByCommunity(
|
||||||
$this->community,
|
$this->community,
|
||||||
$currentPage,
|
$currentPage * $itemsPerPage,
|
||||||
$itemsPerPage,
|
$itemsPerPage,
|
||||||
true,
|
true,
|
||||||
['event', 'currency', 'payer_user', 'payee_user']
|
['event', 'currency', 'payer_user', 'payee_user']
|
||||||
@ -105,7 +106,7 @@ class TransactionController implements IAuthenticationRequired, ISecured
|
|||||||
'community' => $this->community,
|
'community' => $this->community,
|
||||||
'event' => $event,
|
'event' => $event,
|
||||||
'exchangeRateCalculator' => $exchangeRateCalculator,
|
'exchangeRateCalculator' => $exchangeRateCalculator,
|
||||||
'pages' => ceil($numberOfTransactions / $itemsPerPage),
|
'pages' => $pages,
|
||||||
'currentPage' => $currentPage,
|
'currentPage' => $currentPage,
|
||||||
'numberOfTransactions' => $numberOfTransactions,
|
'numberOfTransactions' => $numberOfTransactions,
|
||||||
'transactions' => $transactions
|
'transactions' => $transactions
|
||||||
|
@ -52,11 +52,11 @@ class EventRepository
|
|||||||
yield from Container::$persistentDataManager->selectMultipleFromDb($select, Event::class, $useRelations, $withRelations);
|
yield from Container::$persistentDataManager->selectMultipleFromDb($select, Event::class, $useRelations, $withRelations);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPagedByCommunity(Community $community, int $page, int $itemsPerPage, bool $useRelations = false, array $withRelations = []): Generator
|
public function getPagedByCommunity(Community $community, int $start, int $limit, bool $useRelations = false, array $withRelations = []): Generator
|
||||||
{
|
{
|
||||||
$select = $this->selectAllByCommunity($community);
|
$select = $this->selectAllByCommunity($community);
|
||||||
$select->orderBy('start', 'DESC');
|
$select->orderBy('start', 'DESC');
|
||||||
$select->paginate($page, $itemsPerPage);
|
$select->limit($limit, $start);
|
||||||
|
|
||||||
yield from Container::$persistentDataManager->selectMultipleFromDb($select, Event::class, $useRelations, $withRelations);
|
yield from Container::$persistentDataManager->selectMultipleFromDb($select, Event::class, $useRelations, $withRelations);
|
||||||
}
|
}
|
||||||
|
@ -66,20 +66,20 @@ class TransactionRepository
|
|||||||
return $select->count() > 0;
|
return $select->count() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPagedByCommunity(Community $community, int $page, int $itemsPerPage, bool $useRelations = false, array $withRelations = []): Generator
|
public function getPagedByCommunity(Community $community, int $start, int $limit, bool $useRelations = false, array $withRelations = []): Generator
|
||||||
{
|
{
|
||||||
$select = $this->selectAllByCommunity($community);
|
$select = $this->selectAllByCommunity($community);
|
||||||
$select->orderBy('time', 'DESC');
|
$select->orderBy('time', 'DESC');
|
||||||
$select->paginate($page, $itemsPerPage);
|
$select->limit($limit, $start);
|
||||||
|
|
||||||
yield from Container::$persistentDataManager->selectMultipleFromDb($select, Transaction::class, $useRelations, $withRelations);
|
yield from Container::$persistentDataManager->selectMultipleFromDb($select, Transaction::class, $useRelations, $withRelations);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPagedByEvent(Event $event, int $page, int $itemsPerPage, bool $useRelations = false, array $withRelations = []): Generator
|
public function getPagedByEvent(Event $event, int $start, int $limit, bool $useRelations = false, array $withRelations = []): Generator
|
||||||
{
|
{
|
||||||
$select = $this->selectAllByEvent($event);
|
$select = $this->selectAllByEvent($event);
|
||||||
$select->orderBy('time', 'DESC');
|
$select->orderBy('time', 'DESC');
|
||||||
$select->paginate($page, $itemsPerPage);
|
$select->limit($limit, $start);
|
||||||
|
|
||||||
yield from Container::$persistentDataManager->selectMultipleFromDb($select, Transaction::class, $useRelations, $withRelations);
|
yield from Container::$persistentDataManager->selectMultipleFromDb($select, Transaction::class, $useRelations, $withRelations);
|
||||||
}
|
}
|
||||||
|
@ -1,31 +1,13 @@
|
|||||||
<p class="paginateContainer marginTop">
|
<p class="paginateContainer marginTop">
|
||||||
<a href="<?= Container::$routeCollection->getRoute($paginationRouteId)->generateLink(array_merge($paginationRouteParams, ['page' => 1])) ?>">«</a>
|
<a href="<?= Container::$routeCollection->getRoute($paginationRouteId)->generateLink(array_merge($paginationRouteParams, ['page' => 0])) ?>">«</a>
|
||||||
<a href="<?= Container::$routeCollection->getRoute($paginationRouteId)->generateLink(array_merge($paginationRouteParams, ['page' => max(1, $currentPage - 1)])) ?>">‹</a>
|
<a href="<?= Container::$routeCollection->getRoute($paginationRouteId)->generateLink(array_merge($paginationRouteParams, ['page' => max(0, $currentPage - 1)])) ?>">‹</a>
|
||||||
<?php
|
<?php for ($i = 0; $i < $pages; $i++): ?>
|
||||||
$maxPages = 7;
|
|
||||||
if ($pages <= $maxPages) {
|
|
||||||
$start = 1;
|
|
||||||
$end = $pages;
|
|
||||||
} else {
|
|
||||||
$maxAdditionalPages = $maxPages - 1;
|
|
||||||
$maxAdditionalPagesHalf = ceil($maxAdditionalPages / 2);
|
|
||||||
$start = $currentPage - $maxAdditionalPagesHalf > 1 ?
|
|
||||||
($currentPage - $maxAdditionalPagesHalf < $pages - $maxAdditionalPages ?
|
|
||||||
$currentPage - $maxAdditionalPagesHalf :
|
|
||||||
$pages - $maxAdditionalPages) :
|
|
||||||
1;
|
|
||||||
$end = $start + $maxAdditionalPages < $pages ?
|
|
||||||
$start + $maxAdditionalPages :
|
|
||||||
$pages;
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
<?php for ($i = $start; $i <= $end; $i++): ?>
|
|
||||||
<?php if ($currentPage == $i): ?>
|
<?php if ($currentPage == $i): ?>
|
||||||
<span class="selected"><?= $i ?></span>
|
<span class="selected"><?= $i + 1 ?></span>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<a href="<?= Container::$routeCollection->getRoute($paginationRouteId)->generateLink(array_merge($paginationRouteParams, ['page' => $i])) ?>"><?= $i ?></a>
|
<a href="<?= Container::$routeCollection->getRoute($paginationRouteId)->generateLink(array_merge($paginationRouteParams, ['page' => $i])) ?>"><?= $i + 1 ?></a>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<?php endfor; ?>
|
<?php endfor; ?>
|
||||||
<a href="<?= Container::$routeCollection->getRoute($paginationRouteId)->generateLink(array_merge($paginationRouteParams, ['page' => min($pages, $currentPage + 1)])) ?>">›</a>
|
<a href="<?= Container::$routeCollection->getRoute($paginationRouteId)->generateLink(array_merge($paginationRouteParams, ['page' => min($pages - 1, $currentPage + 1)])) ?>">›</a>
|
||||||
<a href="<?= Container::$routeCollection->getRoute($paginationRouteId)->generateLink(array_merge($paginationRouteParams, ['page' => $pages])) ?>">»</a>
|
<a href="<?= Container::$routeCollection->getRoute($paginationRouteId)->generateLink(array_merge($paginationRouteParams, ['page' => $pages - 1])) ?>">»</a>
|
||||||
</p>
|
</p>
|
||||||
|
Loading…
Reference in New Issue
Block a user