\Dewdrop\Fields\Helper\CsvCellContent

The header helper allows you to render the content of the header for a given field in a CSV table. When defining a custom callback for this helper, use the following callback parameters:

$csvCell->getContentRenderer()->assign(
    'my_model:my_field',
    function ($helper, array $rowData, $rowIndex, $columnIndex) {
        // Param $helper is a reference to this instance of the Header helper
        // Param $rowData is an associative array representing all the data available to render this table row.
        // Param $rowIndex is a zero-based index of the current row being rendered
        // Param $columnIndex is a zero-based index of the current column being rendered

        return 'something';
    }
);

Summary

Methods
Properties
Constants
matchesName()
assign()
getFieldAssignment()
hasValidName()
detectCallableForField()
setNullContentPlaceholder()
setDateFormat()
setTimeFormat()
render()
assignCallbackByColumnPosition()
No public properties found
No constants found
wrapCallable()
renderDbText()
renderDbReference()
renderDbBoolean()
renderDbDate()
renderDbTimestamp()
$name
$callbacksByColumnPosition
$nullContentPlaceholder
$dateFormat
$timeFormat
N/A
No private methods found
$assignments
N/A

Properties

$name

$name : string

The name for this helper, used when you want to define a global custom callback for a given field

Type

string

$callbacksByColumnPosition

$callbacksByColumnPosition : array

It's possible to assign callbacks based upon column position/index. This can be useful if you want to automatically add some controls or other content to the first column, for example.

Type

array

$nullContentPlaceholder

$nullContentPlaceholder : string

This content will be returned if any field's callback generates no output.

Type

string

$dateFormat

$dateFormat : string

The default format for rendering dates. Uses PHP's date() syntax.

Type

string

$timeFormat

$timeFormat : string

The default format for rendering time. Uses PHP's date() syntax.

Type

string

$assignments

$assignments : array

Any per-instance callback assignments for this helper. This array will have field IDs as the keys and callables as the values.

Type

array

Methods

matchesName()

matchesName(string  $name) : boolean

Check to see if the supplied input matches this helper's name (case-insensitive).

Parameters

string $name

Returns

boolean

assign()

assign(mixed  $assignments, callable  $callable = null) : \Dewdrop\Fields\Helper\HelperAbstract

Assign one more custom per-instance callbacks for this helper. If the $arguments param is an array, this method expects that the keys will be field IDs and the values will be callables, assigning custom callbacks for multiple fields in one call. If, however, $assignments is a string or a FieldInterface object, a single custom callback assignment will be made.

Parameters

mixed $assignments
callable $callable

Returns

\Dewdrop\Fields\Helper\HelperAbstract

getFieldAssignment()

getFieldAssignment(\Dewdrop\Fields\FieldInterface  $field) : callable

Get the callback that will be used for the given FieldInterface object.

Parameters

\Dewdrop\Fields\FieldInterface $field

Throws

\Dewdrop\Fields\Exception\HelperCallableNotAvailableForField

Returns

callable

hasValidName()

hasValidName() : boolean

Ensure the helper has a valid $name value. If not, throw an exception.

All helpers must have a name defined so that global custom callbacks can be added to fields.

Throws

\Dewdrop\Fields\Exception\HelperMustHaveName

Returns

boolean

detectCallableForField()

detectCallableForField(\Dewdrop\Fields\FieldInterface  $field) : string|false

If no custom callback is defined for a field, it will fall back to this method to find a suitable callback. In the case of the Content helper, we only provide a fall back for DB-based fields. Custom fields will have to define a callback in order to function properly.

If no callback candidate is found, just return false from this method, which will be detected by getFieldAssignment(), causing execution to halt.

Parameters

\Dewdrop\Fields\FieldInterface $field

Returns

string|false

setNullContentPlaceholder()

setNullContentPlaceholder(string  $nullContentPlaceholder) : \Dewdrop\Fields\Helper\CsvCell\Content

Set the content that should be returned if a field's callback returns no output.

Parameters

string $nullContentPlaceholder

Returns

\Dewdrop\Fields\Helper\CsvCell\Content

setDateFormat()

setDateFormat(string  $dateFormat) : \Dewdrop\Fields\Helper\CsvCell\Content

Set an alternative format for date rendering. Uses PHP's date() syntax.

Parameters

string $dateFormat

Returns

\Dewdrop\Fields\Helper\CsvCell\Content

setTimeFormat()

setTimeFormat(string  $timeFormat) : \Dewdrop\Fields\Helper\TableCell\Content

Set an alternative format for time rendering. Uses PHP's date() syntax.

Parameters

string $timeFormat

Returns

\Dewdrop\Fields\Helper\TableCell\Content

render()

render(\Dewdrop\Fields\FieldInterface  $field, array  $rowData, integer  $rowIndex, integer  $columnIndex) : string

Render the cell's content for the supplied field.

Parameters

\Dewdrop\Fields\FieldInterface $field
array $rowData
integer $rowIndex
integer $columnIndex

Returns

string

assignCallbackByColumnPosition()

assignCallbackByColumnPosition(integer  $columnIndex, callable  $callback) : \Dewdrop\Fields\Helper\CsvCell\Content

Assign a callback based upon the column position currently being displayed. This can be useful, for example, if you'd like to display something specific in a particular column of your table automatically.

You can wrap the callback that would have been used by calling the getFieldAssignment() method with the appropriate field object.

Parameters

integer $columnIndex
callable $callback

Returns

\Dewdrop\Fields\Helper\CsvCell\Content

wrapCallable()

wrapCallable(callable  $callable, \Dewdrop\Fields\FieldInterface  $field = null) : callable

Wrap a field's callback to ensure that a reference to the helper is always supplied as the first argument to the callback.

Parameters

callable $callable
\Dewdrop\Fields\FieldInterface $field

Returns

callable

renderDbText()

renderDbText(\Dewdrop\Db\Field  $field, array  $rowData) : string

A fall back method for basic DB fields. Just returns the text for the field in your row's data.

Parameters

\Dewdrop\Db\Field $field
array $rowData

Returns

string

renderDbReference()

renderDbReference(\Dewdrop\Db\Field  $field, array  $rowData) : string

A fall back method for DB reference fields. For foreign keys, we trim the "_id" off the end and look for the resulting field in the result set.

For example, if you foreign key is "state_id", we look for a result set key of "state" and render that value for the field.

Parameters

\Dewdrop\Db\Field $field
array $rowData

Returns

string

renderDbBoolean()

renderDbBoolean(\Dewdrop\Db\Field  $field, array  $rowData) : string

Render cell content for a boolean database field.

Parameters

\Dewdrop\Db\Field $field
array $rowData

Returns

string

renderDbDate()

renderDbDate(\Dewdrop\Db\Field  $field, array  $rowData) : string

A fall back method for date fields. Will convert the DB value to a Unix timestamp and then format it with PHP's date() function. (How retro!) You can customize the format with setDateFormat().

Parameters

\Dewdrop\Db\Field $field
array $rowData

Returns

string

renderDbTimestamp()

renderDbTimestamp(\Dewdrop\Db\Field  $field, array  $rowData) : string

A fall back method for timestamp fields. Will convert the DB value to a Unix timestamp and then format it with PHP's date() function. (How retro!) You can customize the format with setDateFormat().

Parameters

\Dewdrop\Db\Field $field
array $rowData

Returns

string