Commit c5e21165 authored by Tino Goratsch's avatar Tino Goratsch

refactored the data grid column renderers once more

parent 3c121809
......@@ -83,7 +83,7 @@ class DataGrid
*/
public function registerColumnRenderer(ColumnRendererInterface $columnRenderer)
{
$this->columnRenderer[$columnRenderer->getType()] = $columnRenderer;
$this->columnRenderer[$columnRenderer->getName()] = $columnRenderer;
return $this;
}
......
......@@ -16,6 +16,14 @@ abstract class AbstractColumnRenderer implements ColumnRendererInterface
*/
protected $primaryKey = '';
/**
* @return string
*/
public function getName()
{
return static::NAME;
}
/**
* @param string $identifier
*
......@@ -51,12 +59,12 @@ abstract class AbstractColumnRenderer implements ColumnRendererInterface
/**
* @param array $column
* @param string $value
* @param string $type
*
* @return string
*/
protected function render(array $column, $value = '', $type = self::TYPE_TD)
protected function render(array $column, $value = '')
{
$type = static::CELL_TYPE;
$attribute = $this->addHtmlAttribute($column['attribute']);
$class = $this->addHtmlAttribute('class', $column['class']);
$style = $this->addHtmlAttribute('style', $column['style']);
......
......@@ -7,8 +7,8 @@ namespace ACP3\Core\Helpers\DataGrid\ColumnRenderer;
*/
interface ColumnRendererInterface
{
const TYPE_TH = 'th';
const TYPE_TD = 'td';
const CELL_TYPE = 'td';
const NAME = '';
/**
* @param array $column
......@@ -21,5 +21,5 @@ interface ColumnRendererInterface
/**
* @return string
*/
public function getType();
public function getName();
}
\ No newline at end of file
<?php
namespace ACP3\Core\Helpers\DataGrid\ColumnRenderer;
use ACP3\Core\Date;
use ACP3\Core\Helpers\Formatter\DateRange;
......@@ -9,6 +10,7 @@ use ACP3\Core\Helpers\Formatter\DateRange;
*/
class DateColumnRenderer extends AbstractColumnRenderer
{
const NAME = 'date';
/**
* @var \ACP3\Core\Date
*/
......@@ -46,8 +48,7 @@ class DateColumnRenderer extends AbstractColumnRenderer
}
return $this->render(
$column,
$value
$column, $value
);
}
......@@ -68,12 +69,4 @@ class DateColumnRenderer extends AbstractColumnRenderer
return $value;
}
/**
* @return string
*/
public function getType()
{
return 'date';
}
}
\ No newline at end of file
......@@ -8,6 +8,9 @@ use ACP3\Core\Helpers\Formatter\MarkEntries;
*/
class HeaderColumnRenderer extends AbstractColumnRenderer
{
const NAME = 'table_header';
const CELL_TYPE = 'th';
/**
* @var \ACP3\Core\Helpers\Formatter\MarkEntries
*/
......@@ -35,14 +38,6 @@ class HeaderColumnRenderer extends AbstractColumnRenderer
$value = $column['label'];
}
return $this->render($column, $value, self::TYPE_TH);
}
/**
* @return string
*/
public function getType()
{
return 'table_header';
return $this->render($column, $value);
}
}
\ No newline at end of file
......@@ -7,6 +7,8 @@ namespace ACP3\Core\Helpers\DataGrid\ColumnRenderer;
*/
class IntegerColumnRenderer extends AbstractColumnRenderer
{
const NAME = 'integer';
/**
* @param array $dbResultRow
* @param string $field
......@@ -17,12 +19,4 @@ class IntegerColumnRenderer extends AbstractColumnRenderer
{
return isset($dbResultRow[$field]) ? (int)$dbResultRow[$field] : null;
}
/**
* @return string
*/
public function getType()
{
return 'integer';
}
}
\ No newline at end of file
......@@ -7,6 +7,8 @@ namespace ACP3\Core\Helpers\DataGrid\ColumnRenderer;
*/
class MassActionColumnRenderer extends AbstractColumnRenderer
{
const NAME = 'mass_action';
/**
* @inheritdoc
*/
......@@ -23,12 +25,4 @@ class MassActionColumnRenderer extends AbstractColumnRenderer
return $value;
}
/**
* @return string
*/
public function getType()
{
return 'mass_action';
}
}
\ No newline at end of file
......@@ -8,6 +8,8 @@ use ACP3\Core\Helpers\StringFormatter;
*/
class Nl2pColumnRenderer extends AbstractColumnRenderer
{
const NAME = 'nl2p';
/**
* @var \ACP3\Core\Helpers\StringFormatter
*/
......@@ -30,12 +32,4 @@ class Nl2pColumnRenderer extends AbstractColumnRenderer
{
return isset($dbResultRow[$field]) ? $this->stringFormatter->nl2p($dbResultRow[$field]) : null;
}
/**
* @return string
*/
public function getType()
{
return 'nl2p';
}
}
\ No newline at end of file
......@@ -13,6 +13,8 @@ use Symfony\Component\EventDispatcher\EventDispatcher;
*/
class OptionsColumnRenderer extends AbstractColumnRenderer
{
const NAME = 'options';
/**
* @var \ACP3\Core\Lang
*/
......@@ -102,12 +104,4 @@ class OptionsColumnRenderer extends AbstractColumnRenderer
return $value;
}
/**
* @return string
*/
public function getType()
{
return 'options';
}
}
\ No newline at end of file
......@@ -9,6 +9,8 @@ use ACP3\Core\Router;
*/
class PictureColumnRenderer extends AbstractColumnRenderer
{
const NAME = 'picture';
/**
* @var \ACP3\Core\Router
*/
......@@ -27,17 +29,18 @@ class PictureColumnRenderer extends AbstractColumnRenderer
/**
* @inheritdoc
*/
public function fetchDataAndRenderColumn(array $column, array $dbResultRow)
protected function getValue(array $column, array $dbResultRow)
{
$value = $this->getValue($column, $dbResultRow);
$field = $this->getFirstDbField($column);
$value = $this->getDbValueIfExists($dbResultRow, $field);
if (isset($column['custom']['pattern']) &&
$value !== null && $value !== $this->getDefaultValue($column)
) {
if ($value === null) {
$value = $this->getDefaultValue($column);
} elseif (isset($column['custom']['pattern'])) {
$value = '<img src="' . $this->getUrl($column['custom'], $value) . '" alt="">';
}
return $this->render($column, $value);
return $value;
}
/**
......@@ -55,12 +58,4 @@ class PictureColumnRenderer extends AbstractColumnRenderer
return $url;
}
/**
* @return string
*/
public function getType()
{
return 'picture';
}
}
\ No newline at end of file
......@@ -7,6 +7,8 @@ namespace ACP3\Core\Helpers\DataGrid\ColumnRenderer;
*/
class ReplaceValueColumnRenderer extends AbstractColumnRenderer
{
const NAME = 'replace_value';
/**
* @var array
*/
......@@ -34,12 +36,4 @@ class ReplaceValueColumnRenderer extends AbstractColumnRenderer
{
return isset($dbResultRow[$field]) ? str_replace($this->search, $this->replace, $dbResultRow[$field]) : null;
}
/**
* @return string
*/
public function getType()
{
return 'replace_value';
}
}
\ No newline at end of file
......@@ -7,11 +7,5 @@ namespace ACP3\Core\Helpers\DataGrid\ColumnRenderer;
*/
class TextColumnRenderer extends AbstractColumnRenderer
{
/**
* @return string
*/
public function getType()
{
return 'text';
}
const NAME = 'text';
}
\ No newline at end of file
......@@ -8,6 +8,8 @@ use ACP3\Core\Lang;
*/
class TranslateColumnRenderer extends AbstractColumnRenderer
{
const NAME = 'translate';
/**
* @var
*/
......@@ -36,12 +38,4 @@ class TranslateColumnRenderer extends AbstractColumnRenderer
return null;
}
/**
* @return string
*/
public function getType()
{
return 'translate';
}
}
\ No newline at end of file
......@@ -68,7 +68,7 @@ class PictureSortColumnRenderer extends AbstractColumnRenderer
/**
* @return string
*/
public function getType()
public function getName()
{
return 'picture_sort';
}
......
......@@ -11,6 +11,8 @@ use ACP3\Core\Router;
*/
class AccountStatusColumnRenderer extends AbstractColumnRenderer
{
const NAME = 'account_status';
/**
* @var \ACP3\Core\Lang
*/
......@@ -56,12 +58,4 @@ class AccountStatusColumnRenderer extends AbstractColumnRenderer
return null;
}
/**
* @return string
*/
public function getType()
{
return 'account_status';
}
}
\ No newline at end of file
......@@ -11,6 +11,8 @@ use ACP3\Core\Helpers\DataGrid\ColumnRenderer\AbstractColumnRenderer;
*/
class UserRolesColumnRenderer extends AbstractColumnRenderer
{
const NAME = 'user_roles';
/**
* @var \ACP3\Core\ACL
*/
......@@ -33,12 +35,4 @@ class UserRolesColumnRenderer extends AbstractColumnRenderer
{
return isset($dbResultRow[$field]) ? implode(', ', $this->acl->getUserRoleNames($dbResultRow[$field])) : null;
}
/**
* @return string
*/
public function getType()
{
return 'user_roles';
}
}
\ No newline at end of file
......@@ -151,6 +151,13 @@ abstract class AbstractColumnRendererTest extends PHPUnit_Framework_TestCase
$this->compareResults($expected);
}
public function testGetType()
{
/** @var \ACP3\Core\Helpers\DataGrid\ColumnRenderer\AbstractColumnRenderer $className */
$className = get_class($this->columnRenderer);
$this->assertEquals($className::NAME, $this->columnRenderer->getName());
}
/**
* @param string $expected
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment