Drop interface Browsable

We're not required to handle objects of Zend_Paginator in any way, so
creating such as part of a query is not necessary since QueryAdapter
accepts any instance of QueryInterface. (gets enforced in the near future)

refs #8339
This commit is contained in:
Johannes Meyer 2015-05-15 14:32:58 +02:00
parent 5faebb4a88
commit fbf0ad4339
11 changed files with 21 additions and 77 deletions

View File

@ -128,8 +128,7 @@ class ConfigController extends Controller
$this->view->modules = Icinga::app()->getModuleManager()->select()
->from('modules')
->order('enabled', 'desc')
->order('name')
->paginate();
->order('name');
$this->setupLimitControl();
$this->setupPaginationControl($this->view->modules);
// TODO: Not working

View File

@ -51,7 +51,7 @@ class ListController extends Controller
. 'T[0-9]{2}(?::[0-9]{2}){2}(?:[\+\-][0-9]{2}:[0-9]{2})?)' // time
. ' - (?<loglevel>[A-Za-z]+) - (?<message>.*)(?!.)/msS' // loglevel, message
)));
$this->view->logData = $resource->select()->order('DESC')->paginate();
$this->view->logData = $resource->select()->order('DESC');
$this->setupLimitControl();
$this->setupPaginationControl($this->view->logData);

View File

@ -1,20 +0,0 @@
<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
namespace Icinga\Data;
/**
* Interface for browsing data
*/
interface Browsable
{
/**
* Paginate data
*
* @param int $itemsPerPage Number of items per page
* @param int $pageNumber Current page number
*
* @return Zend_Paginator
*/
public function paginate($itemsPerPage = null, $pageNumber = null);
}

View File

@ -5,4 +5,4 @@ namespace Icinga\Data;
use Countable;
interface QueryInterface extends Browsable, Fetchable, Filterable, Limitable, Sortable, Countable {};
interface QueryInterface extends Fetchable, Filterable, Limitable, Sortable, Countable {};

View File

@ -3,13 +3,9 @@
namespace Icinga\Data;
use Icinga\Application\Icinga;
use ArrayIterator;
use IteratorAggregate;
use Icinga\Data\Filter\Filter;
use Icinga\Web\Paginator\Adapter\QueryAdapter;
use Zend_Paginator;
use Exception;
use Icinga\Exception\IcingaException;
class SimpleQuery implements QueryInterface, Queryable, IteratorAggregate
@ -331,35 +327,6 @@ class SimpleQuery implements QueryInterface, Queryable, IteratorAggregate
return $this->limitOffset;
}
/**
* Paginate data
*
* Auto-detects pagination parameters from request when unset
*
* @param int $itemsPerPage Number of items per page
* @param int $pageNumber Current page number
*
* @return Zend_Paginator
*/
public function paginate($itemsPerPage = null, $pageNumber = null)
{
if ($itemsPerPage === null || $pageNumber === null) {
// Detect parameters from request
$request = Icinga::app()->getFrontController()->getRequest();
if ($itemsPerPage === null) {
$itemsPerPage = $request->getParam('limit', 25);
}
if ($pageNumber === null) {
$pageNumber = $request->getParam('page', 0);
}
}
$this->limit($itemsPerPage, $pageNumber * $itemsPerPage);
$paginator = new Zend_Paginator(new QueryAdapter($this));
$paginator->setItemCountPerPage($itemsPerPage);
$paginator->setCurrentPageNumber($pageNumber);
return $paginator;
}
/**
* Retrieve an array containing all rows of the result set
*

View File

@ -3,15 +3,13 @@
namespace Icinga\File;
use Icinga\Data\Browsable;
class Csv
{
protected $query;
protected function __construct() {}
public static function fromQuery(Browsable $query)
public static function fromQuery($query)
{
$csv = new Csv();
$csv->query = $query;

View File

@ -70,7 +70,7 @@ class Monitoring_AlertsummaryController extends Controller
'notification_state'
)
);
$this->view->notifications = $query->paginate();
$this->view->notifications = $query;
$this->setupLimitControl();
$this->setupPaginationControl($this->view->notifications);
@ -493,7 +493,7 @@ class Monitoring_AlertsummaryController extends Controller
$query->order('notification_start_time', 'desc');
return $query->paginate(5);
return $query->limit(5);
}
/**

View File

@ -97,7 +97,7 @@ class Monitoring_ListController extends Controller
), $this->extraColumns()));
$this->filterQuery($query);
$this->applyRestriction('monitoring/hosts/filter', $query);
$this->view->hosts = $query->paginate();
$this->view->hosts = $query;
$this->view->stats = $this->backend->select()->from('statusSummary', array(
'hosts_total',
@ -181,7 +181,7 @@ class Monitoring_ListController extends Controller
$query = $this->backend->select()->from('serviceStatus', $columns);
$this->filterQuery($query);
$this->applyRestriction('monitoring/services/filter', $query);
$this->view->services = $query->paginate();
$this->view->services = $query;
$this->setupLimitControl();
$this->setupPaginationControl($this->view->services);
@ -246,7 +246,7 @@ class Monitoring_ListController extends Controller
'service_display_name'
));
$this->filterQuery($query);
$this->view->downtimes = $query->paginate();
$this->view->downtimes = $query;
$this->setupLimitControl();
$this->setupPaginationControl($this->view->downtimes);
@ -292,7 +292,7 @@ class Monitoring_ListController extends Controller
'service_display_name'
));
$this->filterQuery($query);
$this->view->notifications = $query->paginate();
$this->view->notifications = $query;
$this->setupLimitControl();
$this->setupPaginationControl($this->view->notifications);
@ -326,7 +326,7 @@ class Monitoring_ListController extends Controller
'contact_notify_host_downtime',
));
$this->filterQuery($query);
$this->view->contacts = $query->paginate();
$this->view->contacts = $query;
$this->setupLimitControl();
$this->setupPaginationControl($this->view->contacts);
@ -438,7 +438,7 @@ class Monitoring_ListController extends Controller
'service_display_name'
));
$this->filterQuery($query);
$this->view->comments = $query->paginate();
$this->view->comments = $query;
$this->setupLimitControl();
$this->setupPaginationControl($this->view->comments);
@ -498,7 +498,7 @@ class Monitoring_ListController extends Controller
// TODO(el): Can't default to the sort rules of the data view because it's meant for both host groups and
// service groups. We should separate them.
$this->filterQuery($query);
$this->view->servicegroups = $query->paginate();
$this->view->servicegroups = $query;
$this->setupLimitControl();
$this->setupPaginationControl($this->view->servicegroups);
@ -555,7 +555,7 @@ class Monitoring_ListController extends Controller
// TODO(el): Can't default to the sort rules of the data view because it's meant for both host groups and
// service groups. We should separate them.
$this->filterQuery($query);
$this->view->hostgroups = $query->paginate();
$this->view->hostgroups = $query;
$this->setupLimitControl();
$this->setupPaginationControl($this->view->hostgroups);
@ -594,7 +594,7 @@ class Monitoring_ListController extends Controller
));
$this->filterQuery($query);
$this->view->history = $query->paginate();
$this->view->history = $query;
$this->setupLimitControl();
$this->setupPaginationControl($this->view->history);

View File

@ -70,12 +70,12 @@ class Monitoring_ShowController extends Controller
{
$this->getTabs()->activate('history');
$this->view->object->fetchEventHistory();
$this->view->history = $this->view->object->eventhistory->getQuery()->paginate($this->params->get('limit', 50));
$this->view->history = $this->view->object->eventhistory;
$this->handleFormatRequest($this->view->object->eventhistory);
$this->fetchHostStats();
$this->setupLimitControl();
$this->setupPaginationControl($this->view->history);
$this->setupPaginationControl($this->view->history, 50);
}
public function servicesAction()
@ -154,7 +154,7 @@ class Monitoring_ShowController extends Controller
'command_name'
))->where('contact_id', $contact->contact_id);
$this->view->commands = $commands->paginate();
$this->view->commands = $commands;
$notifications = $this->backend->select()->from('notification', array(
'host_name',
@ -168,7 +168,7 @@ class Monitoring_ShowController extends Controller
));
$notifications->where('contact_object_id', $contact->contact_object_id);
$this->view->notifications = $notifications->paginate();
$this->view->notifications = $notifications;
$this->setupLimitControl();
$this->setupPaginationControl($this->view->notifications);
}

View File

@ -5,7 +5,7 @@
<?= $this->render('list/components/selectioninfo.phtml'); ?>
</div>
<div class="tinystatesummary">
<?= $comments->getTotalItemCount() ?> <?= $this->translate('Comments') ?>:
<?= count($comments) ?> <?= $this->translate('Comments') ?>:
</div>
<?= $this->sortBox; ?>
<?= $this->limiter; ?>

View File

@ -9,7 +9,7 @@ if (! $this->compact): ?>
<?= $this->render('list/components/selectioninfo.phtml'); ?>
</div>
<div class="tinystatesummary">
<?= $downtimes->getTotalItemCount() ?> <?= $this->translate('Downtimes') ?>
<?= count($downtimes) ?> <?= $this->translate('Downtimes') ?>
</div>
<?= $this->sortBox; ?>
<?= $this->limiter; ?>