2014-11-13 15:42:25 +01:00
|
|
|
<?php
|
2015-02-04 10:46:36 +01:00
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
2014-11-13 15:42:25 +01:00
|
|
|
|
|
|
|
namespace Icinga\Web;
|
|
|
|
|
2015-04-17 16:08:41 +02:00
|
|
|
use Zend_Paginator;
|
2014-11-13 15:42:25 +01:00
|
|
|
use Icinga\Web\Controller\ModuleActionController;
|
2015-04-08 16:48:35 +02:00
|
|
|
use Icinga\Web\Widget\SortBox;
|
2015-04-17 16:08:41 +02:00
|
|
|
use Icinga\Web\Widget\Limiter;
|
2014-11-13 15:42:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This is the controller all modules should inherit from
|
|
|
|
* We will flip code with the ModuleActionController as soon as a couple
|
|
|
|
* of pending feature branches are merged back to the master.
|
|
|
|
*/
|
|
|
|
class Controller extends ModuleActionController
|
|
|
|
{
|
2015-05-11 13:36:58 +02:00
|
|
|
/**
|
|
|
|
* @see ActionController::init
|
|
|
|
*/
|
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
parent::init();
|
|
|
|
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$url = Url::fromRequest();
|
|
|
|
|
|
|
|
if ($request->isPost() && ($sort = $request->getPost('sort'))) {
|
|
|
|
$url->setParam('sort', $sort);
|
|
|
|
if ($dir = $request->getPost('dir')) {
|
|
|
|
$url->setParam('dir', $dir);
|
|
|
|
} else {
|
|
|
|
$url->removeParam('dir');
|
|
|
|
}
|
|
|
|
$this->redirectNow($url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-08 16:48:35 +02:00
|
|
|
/**
|
2015-04-15 14:20:36 +02:00
|
|
|
* Create a SortBox widget at the `sortBox' view property
|
2015-04-08 16:48:35 +02:00
|
|
|
*
|
2015-04-17 16:08:41 +02:00
|
|
|
* In case the current view has been requested as compact this method does nothing.
|
|
|
|
*
|
2015-04-15 14:20:36 +02:00
|
|
|
* @param array $columns An array containing the sort columns, with the
|
|
|
|
* submit value as the key and the label as the value
|
2015-04-17 16:08:41 +02:00
|
|
|
*
|
|
|
|
* @return $this
|
2015-04-08 16:48:35 +02:00
|
|
|
*/
|
|
|
|
protected function setupSortControl(array $columns)
|
|
|
|
{
|
2015-04-17 16:08:41 +02:00
|
|
|
if (! $this->view->compact) {
|
|
|
|
$req = $this->getRequest();
|
|
|
|
$this->view->sortBox = SortBox::create(
|
|
|
|
'sortbox-' . $req->getActionName(),
|
|
|
|
$columns
|
2015-05-11 14:07:57 +02:00
|
|
|
)->setRequest($req);
|
2015-04-17 16:08:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a Limiter widget at the `limiter' view property
|
|
|
|
*
|
|
|
|
* In case the current view has been requested as compact this method does nothing.
|
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
protected function setupLimitControl()
|
|
|
|
{
|
|
|
|
if (! $this->view->compact) {
|
|
|
|
$this->view->limiter = new Limiter();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the view property `paginator' to the given Zend_Paginator
|
|
|
|
*
|
|
|
|
* In case the current view has been requested as compact this method does nothing.
|
|
|
|
*
|
|
|
|
* @param Zend_Paginator $paginator The Zend_Paginator for which to show a pagination control
|
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
protected function setupPaginationControl(Zend_Paginator $paginator)
|
|
|
|
{
|
|
|
|
if (! $this->view->compact) {
|
|
|
|
$this->view->paginator = $paginator;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the view property `filterEditor' to the given FilterEditor
|
|
|
|
*
|
|
|
|
* In case the current view has been requested as compact this method does nothing.
|
|
|
|
*
|
|
|
|
* @param Form $editor The FilterEditor
|
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
protected function setupFilterControl($editor)
|
|
|
|
{
|
|
|
|
if (! $this->view->compact) {
|
|
|
|
$this->view->filterEditor = $editor;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
2015-04-08 16:48:35 +02:00
|
|
|
}
|
2014-11-13 15:42:25 +01:00
|
|
|
}
|