Use class Url in mixedPagination.phtml

This commit is contained in:
Eric Lippmann 2013-07-12 13:40:21 +02:00
parent df1e595604
commit e66d17dbf8
3 changed files with 71 additions and 47 deletions

View File

@ -1,61 +1,58 @@
<? if ($this->pageCount > 1): ?>
<?php <?php
if (is_array($this->preserve)) {
$preserve = $this->preserve;
} else {
$preserve = array();
}
$fromto = t('%d to %d of %d'); if ($this->pageCount <= 1) return;
$fromto = $this->translate('%d to %d of %d');
$total = $this->totalItemCount; $total = $this->totalItemCount;
?> $limit = $this->itemCountPerPage;
<div class="pagination pagination-mini" style="margin:0px"> $title_prev = sprintf(
$fromto,
($this->current - 2) * $limit + 1,
($this->current - 1) * $limit,
$total
);
$title_next = sprintf(
$fromto,
($this->current) * $limit + 1,
($this->current + 1) * $limit,
$total
);
?><div class="pagination pagination-mini" style="margin:0px">
<ul> <ul>
<!-- Previous page link --> <!-- Previous page link -->
<? if (isset($this->previous)): ?> <?php if (isset($this->previous)): ?>
<li><a href="<?= $this->url($preserve + array('page' => $this->previous)); ?>" title="<?= <li><a href="<?= $this->url()->setParam('page', $this->previous) ?>" title="<?= $titleprev ?>">« <?= $this->translate('Back') ?></a></li>
sprintf($fromto, <?php else: ?>
($this->current - 2) * $this->itemCountPerPage + 1, <li class="disabled"><span>« <?= $this->translate('Back') ?></span></li>
($this->current - 1) * $this->itemCountPerPage, <?php endif ?>
$this->totalItemCount)
?>">« <?= t('Back') ?></a></li>
<? else: ?>
<li class="disabled"><span>« <?= t('Back') ?></span></li>
<?php
endif;
?>
<!-- Numbered page links --> <!-- Numbered page links -->
<? foreach ($this->pagesInRange as $page): ?>
<?php <?php
$start = ($page - 1) * $this->itemCountPerPage + 1; foreach ($this->pagesInRange as $page):
$end = $page * $this->itemCountPerPage;
if ($end > $total) {
$end = $total;
}
$title = sprintf($fromto, $start, $end, $total);
$active_class = $page === $this->current ? ' class="active"' : '';
?> $start = ($page - 1) * $limit + 1;
<?php if ($page === '...'): ?> $end = $page * $limit;
if ($end > $total) {
$end = $total;
}
$title = sprintf($fromto, $start, $end, $total);
$class = $page === $this->current ? ' class="active"' : '';
if ($page === '...'): ?>
<li class="disabled"><span>...</span></li> <li class="disabled"><span>...</span></li>
<?php else: ?> <?php else: ?>
<li<?= $active_class ?>><a href="<?= $this->url( <li<?= $class ?>><a href="<?= $this->url()->setParam('page', $page) ?>" title="<?= $title ?>"><?= $page ?></a></li>
$preserve + array('page' => $page) <?php
); ?>" title="<?= $title ?>"><?= $page; ?></a></li> endif;
<? endif ?> endforeach;
<? endforeach ?> ?>
<!-- Next page link --> <!-- Next page link -->
<? if (isset($this->next)): ?> <? if (isset($this->next)): ?>
<li><a href="<?= $this->url($preserve + array('page' => $this->next)); ?>" title="<?= <li><a href="<?= $this->url()->setParam('page', $this->next) ?>" title="<?= $title_next ?>"><?= t('Next') ?> »</a></li>
sprintf($fromto,
($this->current) * $this->itemCountPerPage + 1,
($this->current + 1) * $this->itemCountPerPage,
$total)
?>"><?= t('Next') ?> »</a></li>
<? else: ?> <? else: ?>
<li class="disabled"><span><?= t('Next') ?> »</span></li> <li class="disabled"><span><?= t('Next') ?> »</span></li>
<? endif ?> <? endif ?>
</ul> </ul>
</div> </div>
<? endif ?>

View File

@ -72,6 +72,11 @@ abstract class AbstractQuery
$this->init(); $this->init();
} }
public function getDatasource()
{
return $this->ds;
}
protected function getDefaultColumns() protected function getDefaultColumns()
{ {
return null; return null;
@ -89,6 +94,9 @@ abstract class AbstractQuery
$this->table = $table; $this->table = $table;
if ($columns !== null) { if ($columns !== null) {
$this->columns($columns); $this->columns($columns);
} else {
// TODO: Really?
$this->columns = $this->getDefaultColumns();
} }
return $this; return $this;
} }
@ -100,7 +108,6 @@ abstract class AbstractQuery
} else { } else {
$this->columns = array($columns); $this->columns = array($columns);
} }
return $this; return $this;
} }
@ -355,6 +362,7 @@ abstract class AbstractQuery
$limit = $request->getParam('limit', 20); $limit = $request->getParam('limit', 20);
} }
} }
$this->limit($limit, $page * $limit);
$paginator = new \Zend_Paginator( $paginator = new \Zend_Paginator(
new \Icinga\Web\Paginator\Adapter\QueryAdapter($this) new \Icinga\Web\Paginator\Adapter\QueryAdapter($this)

View File

@ -36,6 +36,22 @@ class ArrayDatasource implements DatasourceInterface
return $result; return $result;
} }
public function fetchPairs(ArrayQuery $query)
{
$result = array();
$keys = null;
foreach ($this->getResult($query) as $row) {
if ($keys === null) {
$keys = array_keys((array) $row);
if (count($keys) < 2) {
$keys[1] = $keys[0];
}
}
$result[$row->{$keys[0]}] = $row->{$keys[1]};
}
return $result;
}
public function fetchAll(ArrayQuery $query) public function fetchAll(ArrayQuery $query)
{ {
$result = $this->getResult($query); $result = $this->getResult($query);
@ -70,11 +86,14 @@ class ArrayDatasource implements DatasourceInterface
$result[] = $row; $result[] = $row;
} else { } else {
$c_row = (object) array(); $c_row = (object) array();
foreach ($columns as $key) { foreach ($columns as $alias => $key) {
if (is_int($alias)) {
$alias = $key;
}
if (isset($row->$key)) { if (isset($row->$key)) {
$c_row->$key = $row->$key; $c_row->$alias = $row->$key;
} else { } else {
$c_row->$key = null; $c_row->$alias = null;
} }
} }
$result[] = $c_row; $result[] = $c_row;