Use class Url in mixedPagination.phtml
This commit is contained in:
parent
df1e595604
commit
e66d17dbf8
|
@ -1,61 +1,58 @@
|
|||
<? if ($this->pageCount > 1): ?>
|
||||
<?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;
|
||||
?>
|
||||
<div class="pagination pagination-mini" style="margin:0px">
|
||||
$limit = $this->itemCountPerPage;
|
||||
$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>
|
||||
<!-- Previous page link -->
|
||||
<? if (isset($this->previous)): ?>
|
||||
<li><a href="<?= $this->url($preserve + array('page' => $this->previous)); ?>" title="<?=
|
||||
sprintf($fromto,
|
||||
($this->current - 2) * $this->itemCountPerPage + 1,
|
||||
($this->current - 1) * $this->itemCountPerPage,
|
||||
$this->totalItemCount)
|
||||
?>">« <?= t('Back') ?></a></li>
|
||||
<? else: ?>
|
||||
<li class="disabled"><span>« <?= t('Back') ?></span></li>
|
||||
<?php
|
||||
endif;
|
||||
?>
|
||||
<?php if (isset($this->previous)): ?>
|
||||
<li><a href="<?= $this->url()->setParam('page', $this->previous) ?>" title="<?= $titleprev ?>">« <?= $this->translate('Back') ?></a></li>
|
||||
<?php else: ?>
|
||||
<li class="disabled"><span>« <?= $this->translate('Back') ?></span></li>
|
||||
<?php endif ?>
|
||||
<!-- Numbered page links -->
|
||||
<? foreach ($this->pagesInRange as $page): ?>
|
||||
<?php
|
||||
|
||||
$start = ($page - 1) * $this->itemCountPerPage + 1;
|
||||
$end = $page * $this->itemCountPerPage;
|
||||
if ($end > $total) {
|
||||
$end = $total;
|
||||
}
|
||||
$title = sprintf($fromto, $start, $end, $total);
|
||||
$active_class = $page === $this->current ? ' class="active"' : '';
|
||||
foreach ($this->pagesInRange as $page):
|
||||
|
||||
?>
|
||||
<?php if ($page === '...'): ?>
|
||||
$start = ($page - 1) * $limit + 1;
|
||||
$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>
|
||||
<?php else: ?>
|
||||
<li<?= $active_class ?>><a href="<?= $this->url(
|
||||
$preserve + array('page' => $page)
|
||||
); ?>" title="<?= $title ?>"><?= $page; ?></a></li>
|
||||
<? endif ?>
|
||||
<? endforeach ?>
|
||||
<li<?= $class ?>><a href="<?= $this->url()->setParam('page', $page) ?>" title="<?= $title ?>"><?= $page ?></a></li>
|
||||
<?php
|
||||
endif;
|
||||
endforeach;
|
||||
?>
|
||||
<!-- Next page link -->
|
||||
<? if (isset($this->next)): ?>
|
||||
<li><a href="<?= $this->url($preserve + array('page' => $this->next)); ?>" title="<?=
|
||||
sprintf($fromto,
|
||||
($this->current) * $this->itemCountPerPage + 1,
|
||||
($this->current + 1) * $this->itemCountPerPage,
|
||||
$total)
|
||||
?>"><?= t('Next') ?> »</a></li>
|
||||
<li><a href="<?= $this->url()->setParam('page', $this->next) ?>" title="<?= $title_next ?>"><?= t('Next') ?> »</a></li>
|
||||
<? else: ?>
|
||||
<li class="disabled"><span><?= t('Next') ?> »</span></li>
|
||||
<? endif ?>
|
||||
</ul>
|
||||
</div>
|
||||
<? endif ?>
|
||||
|
|
|
@ -72,6 +72,11 @@ abstract class AbstractQuery
|
|||
$this->init();
|
||||
}
|
||||
|
||||
public function getDatasource()
|
||||
{
|
||||
return $this->ds;
|
||||
}
|
||||
|
||||
protected function getDefaultColumns()
|
||||
{
|
||||
return null;
|
||||
|
@ -89,6 +94,9 @@ abstract class AbstractQuery
|
|||
$this->table = $table;
|
||||
if ($columns !== null) {
|
||||
$this->columns($columns);
|
||||
} else {
|
||||
// TODO: Really?
|
||||
$this->columns = $this->getDefaultColumns();
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
@ -100,7 +108,6 @@ abstract class AbstractQuery
|
|||
} else {
|
||||
$this->columns = array($columns);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -355,6 +362,7 @@ abstract class AbstractQuery
|
|||
$limit = $request->getParam('limit', 20);
|
||||
}
|
||||
}
|
||||
$this->limit($limit, $page * $limit);
|
||||
|
||||
$paginator = new \Zend_Paginator(
|
||||
new \Icinga\Web\Paginator\Adapter\QueryAdapter($this)
|
||||
|
|
|
@ -36,6 +36,22 @@ class ArrayDatasource implements DatasourceInterface
|
|||
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)
|
||||
{
|
||||
$result = $this->getResult($query);
|
||||
|
@ -70,11 +86,14 @@ class ArrayDatasource implements DatasourceInterface
|
|||
$result[] = $row;
|
||||
} else {
|
||||
$c_row = (object) array();
|
||||
foreach ($columns as $key) {
|
||||
foreach ($columns as $alias => $key) {
|
||||
if (is_int($alias)) {
|
||||
$alias = $key;
|
||||
}
|
||||
if (isset($row->$key)) {
|
||||
$c_row->$key = $row->$key;
|
||||
$c_row->$alias = $row->$key;
|
||||
} else {
|
||||
$c_row->$key = null;
|
||||
$c_row->$alias = null;
|
||||
}
|
||||
}
|
||||
$result[] = $c_row;
|
||||
|
|
Loading…
Reference in New Issue