QuickTable: Implement Paginatable

refs #9691
This commit is contained in:
Alexander Fuhr 2015-07-23 16:18:32 +02:00
parent ecb3d71760
commit 08ec28345e
1 changed files with 64 additions and 2 deletions

View File

@ -4,15 +4,20 @@ namespace Icinga\Module\Director\Web\Table;
use Icinga\Application\Icinga;
use Icinga\Data\Selectable;
use Icinga\Web\Request;
use Icinga\Data\Paginatable;
use Icinga\Web\Url;
use Icinga\Web\Widget\Paginator;
abstract class QuickTable
abstract class QuickTable implements Paginatable
{
protected $view;
protected $connection;
protected $limit;
protected $offset;
protected function renderRow($row)
{
$htm = " <tr>\n";
@ -56,6 +61,63 @@ abstract class QuickTable
return $this;
}
abstract protected function getBaseQuery();
public function fetchData()
{
$db = $this->connection()->getConnection();
$query = $this->getBaseQuery()->columns($this->getColumns());
if ($this->hasLimit() || $this->hasOffset()) {
$query->limit($this->getLimit(), $this->getOffset());
}
return $db->fetchAll($query);
}
public function getPaginator()
{
$paginator = new Paginator();
$paginator->setQuery($this);
return $paginator;
}
public function count()
{
$db = $this->connection()->getConnection();
return $db->fetchOne($this->getBaseQuery()->columns(array('COUNT(*)')));
}
public function limit($count = null, $offset = null)
{
$this->limit = $count;
$this->offset = $offset;
return $this;
}
public function hasLimit()
{
return $this->limit !== null;
}
public function getLimit()
{
return $this->limit;
}
public function hasOffset()
{
return $this->offset !== null;
}
public function getOffset()
{
return $this->offset;
}
public function hasAdditionalActions()
{
return method_exists($this, 'renderAdditionalActions');