Skip to content

Commit

Permalink
Drop interface Browsable
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Johannes Meyer committed May 15, 2015
1 parent 5faebb4 commit fbf0ad4
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 77 deletions.
3 changes: 1 addition & 2 deletions application/controllers/ConfigController.php
Expand Up @@ -128,8 +128,7 @@ public function modulesAction()
$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
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/ListController.php
Expand Up @@ -51,7 +51,7 @@ public function applicationlogAction()
. '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);
Expand Down
20 changes: 0 additions & 20 deletions library/Icinga/Data/Browsable.php

This file was deleted.

2 changes: 1 addition & 1 deletion library/Icinga/Data/QueryInterface.php
Expand Up @@ -5,4 +5,4 @@

use Countable;

interface QueryInterface extends Browsable, Fetchable, Filterable, Limitable, Sortable, Countable {};
interface QueryInterface extends Fetchable, Filterable, Limitable, Sortable, Countable {};
33 changes: 0 additions & 33 deletions library/Icinga/Data/SimpleQuery.php
Expand Up @@ -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
Expand Down Expand Up @@ -331,35 +327,6 @@ public function getOffset()
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
*
Expand Down
4 changes: 1 addition & 3 deletions library/Icinga/File/Csv.php
Expand Up @@ -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;
Expand Down
Expand Up @@ -70,7 +70,7 @@ public function indexAction()
'notification_state'
)
);
$this->view->notifications = $query->paginate();
$this->view->notifications = $query;

$this->setupLimitControl();
$this->setupPaginationControl($this->view->notifications);
Expand Down Expand Up @@ -493,7 +493,7 @@ private function createRecentAlerts()

$query->order('notification_start_time', 'desc');

return $query->paginate(5);
return $query->limit(5);
}

/**
Expand Down
18 changes: 9 additions & 9 deletions modules/monitoring/application/controllers/ListController.php
Expand Up @@ -97,7 +97,7 @@ public function hostsAction()
), $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',
Expand Down Expand Up @@ -181,7 +181,7 @@ public function servicesAction()
$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);
Expand Down Expand Up @@ -246,7 +246,7 @@ public function downtimesAction()
'service_display_name'
));
$this->filterQuery($query);
$this->view->downtimes = $query->paginate();
$this->view->downtimes = $query;

$this->setupLimitControl();
$this->setupPaginationControl($this->view->downtimes);
Expand Down Expand Up @@ -292,7 +292,7 @@ public function notificationsAction()
'service_display_name'
));
$this->filterQuery($query);
$this->view->notifications = $query->paginate();
$this->view->notifications = $query;

$this->setupLimitControl();
$this->setupPaginationControl($this->view->notifications);
Expand Down Expand Up @@ -326,7 +326,7 @@ public function contactsAction()
'contact_notify_host_downtime',
));
$this->filterQuery($query);
$this->view->contacts = $query->paginate();
$this->view->contacts = $query;

$this->setupLimitControl();
$this->setupPaginationControl($this->view->contacts);
Expand Down Expand Up @@ -438,7 +438,7 @@ public function commentsAction()
'service_display_name'
));
$this->filterQuery($query);
$this->view->comments = $query->paginate();
$this->view->comments = $query;

$this->setupLimitControl();
$this->setupPaginationControl($this->view->comments);
Expand Down Expand Up @@ -498,7 +498,7 @@ public function servicegroupsAction()
// 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);
Expand Down Expand Up @@ -555,7 +555,7 @@ public function hostgroupsAction()
// 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);
Expand Down Expand Up @@ -594,7 +594,7 @@ public function eventhistoryAction()
));

$this->filterQuery($query);
$this->view->history = $query->paginate();
$this->view->history = $query;

$this->setupLimitControl();
$this->setupPaginationControl($this->view->history);
Expand Down
8 changes: 4 additions & 4 deletions modules/monitoring/application/controllers/ShowController.php
Expand Up @@ -70,12 +70,12 @@ public function historyAction()
{
$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()
Expand Down Expand Up @@ -154,7 +154,7 @@ public function contactAction()
'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',
Expand All @@ -168,7 +168,7 @@ public function contactAction()
));

$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);
}
Expand Down
Expand Up @@ -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; ?>
Expand Down
Expand Up @@ -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; ?>
Expand Down

0 comments on commit fbf0ad4

Please sign in to comment.