CoolCMS API

PriceRenderer extends CellRenderer
in package

Renders a monetary amount.

The column value is a numeric price that the template formats with the priceFormat:$currency filter (separators, precision, currency symbol position, see PriceHelper::convertByLocalization()). The currency is picked from the list passed to setCurrencies() by the currencyId of the record; the property is set via setCurrencyProperty() (defaults to currencyId, i.e. getCurrencyId()). When the currency is missing from the list, the bare number is printed. The whole-unit suffix is a currency property (show_suffix) handled by priceFormat; credits have it off.

Usage:

Column::create('totalPrice')
    ->setRenderer(
        PriceRenderer::create()
            ->setCurrencies($this->currencyManager->findAll()->execute())
            ->setCurrencyProperty('currencyId')
    );

Table of Contents

Properties

$currenciesById  : array<int, object>
$currencyProperty  : string
Property or getter path on the row entity returning the currency id.

Methods

__construct()  : mixed
create()  : static
getTemplateName()  : string
Cell template name (`Cells/<type>.latte`).
prepare()  : array<string, mixed>
Variables for the cell template.
setCurrencies()  : static
Sets the currencies the right one is picked from by `currencyId`.
setCurrencyProperty()  : static
Property or getter path on the entity returning the currency id (defaults to `currencyId`).
toCsvValue()  : string
Plain text value of the cell for the CSV export (no HTML/JS); does not change the normal render. The default implementation looks for a text in the vars from {@see prepare()} (key `text`; true for {@see TextRenderer}, {@see ComputedRenderer}, {@see OptionRenderer}, {@see BadgeRenderer}, `Date*Renderer`) and falls back to {@see toString()}. Renderers without a text representation (bool, select, toggle) override it.
toScalarValue()  : mixed
Column value to a scalar comparable with the keys of `options` maps: a `BackedEnum` becomes its `value`, a pure enum its `name`, a bool 0/1. Other values pass unchanged.
toString()  : string
Column value (mixed) to text; non-stringable values give an empty string.

Properties

$currenciesById

protected array<int, object> $currenciesById = []

currencies indexed by id (Currency::getId())

$currencyProperty

Property or getter path on the row entity returning the currency id.

protected string $currencyProperty = 'currencyId'

Methods

create()

public static create() : static
Return values
static

getTemplateName()

Cell template name (`Cells/<type>.latte`).

public getTemplateName() : string
Return values
string

prepare()

Variables for the cell template.

public prepare(mixed $value, object $entity, DataGrid $grid, BaseColumn $column) : array<string, mixed>
Parameters
$value : mixed
$entity : object
$grid : DataGrid
$column : BaseColumn
Return values
array<string, mixed>

setCurrencies()

Sets the currencies the right one is picked from by `currencyId`.

public setCurrencies(iterable<string|int, object> $currencies) : static

Currencies must have getId(); those without it are skipped.

Parameters
$currencies : iterable<string|int, object>
Return values
static

setCurrencyProperty()

Property or getter path on the entity returning the currency id (defaults to `currencyId`).

public setCurrencyProperty(string $currencyProperty) : static
Parameters
$currencyProperty : string
Return values
static

toCsvValue()

Plain text value of the cell for the CSV export (no HTML/JS); does not change the normal render. The default implementation looks for a text in the vars from {@see prepare()} (key `text`; true for {@see TextRenderer}, {@see ComputedRenderer}, {@see OptionRenderer}, {@see BadgeRenderer}, `Date*Renderer`) and falls back to {@see toString()}. Renderers without a text representation (bool, select, toggle) override it.

public toCsvValue(mixed $value, object $entity, DataGrid $grid, BaseColumn $column) : string
Parameters
$value : mixed
$entity : object
$grid : DataGrid
$column : BaseColumn
Return values
string

toScalarValue()

Column value to a scalar comparable with the keys of `options` maps: a `BackedEnum` becomes its `value`, a pure enum its `name`, a bool 0/1. Other values pass unchanged.

protected toScalarValue(mixed $value) : mixed

IMPORTANT: entities return an enum object for enum columns (typed property), so without this normalization the cell template receives an object and (string) $enum is a fatal error, not an empty output.

Parameters
$value : mixed

toString()

Column value (mixed) to text; non-stringable values give an empty string.

protected toString(mixed $value) : string

An enum prints its value/name; a bool keeps the (string) semantics (false is empty, not "0"), as the admin always printed it.

Parameters
$value : mixed
Return values
string
On this page

Search results