Commit d966815d authored by Tino Goratsch's avatar Tino Goratsch

Added a new column renderer for rounding numbers to a given precision

parent 915fa55f
<?php
/**
* Copyright (c) by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Core\Helpers\DataGrid\ColumnRenderer;
class RoundNumberColumnRenderer extends AbstractColumnRenderer
{
/**
* @var int
*/
protected $precision = 0;
/**
* {@inheritdoc}
*/
public function fetchDataAndRenderColumn(array $column, array $dbResultRow)
{
$this->precision = $column['custom']['precision'];
return $this->render($column, $this->getValue($column, $dbResultRow));
}
/**
* {@inheritdoc}
*/
protected function getDbValueIfExists(array $dbResultRow, $field)
{
return isset($dbResultRow[$field]) ? \round($dbResultRow[$field], $this->precision) : null;
}
}
......@@ -73,6 +73,12 @@ services:
- { name: core.helpers.data_grid.column_renderer }
public: false
core.helpers.data_grid.column_renderer.round_number_column_renderer:
class: ACP3\Core\Helpers\DataGrid\ColumnRenderer\RoundNumberColumnRenderer
tags:
- { name: core.helpers.data_grid.column_renderer }
public: false
core.helpers.data_grid.column_renderer.route_column_renderer:
class: ACP3\Core\Helpers\DataGrid\ColumnRenderer\RouteColumnRenderer
arguments:
......
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