\Dewdrop\FieldsRowEditor

This class assists in the editing of one or more row objects. To achieve this, it first helps you associate row objects with all the DB fields in your \Dewdrop\Fields object. When you initially add fields to a \Dewdrop\Fields object, it is usually via a \Dewdrop\Db\Table model rather than a row. So, to edit those fields, you somehow have to call setRow() on each of those fields, giving them the ability to get and set values on that row.

Summary

Methods
Properties
Constants
__construct()
getFields()
getRequest()
setDefaults()
applyDefaultsToRow()
reset()
link()
linkRowsToFields()
setLinkCallback()
addLink()
linkByQueryString()
linkTableByQueryString()
linkByField()
isNew()
isValid()
getInputFilter()
getMessages()
setDeleteField()
hasDeleteField()
isDeleted()
delete()
restore()
setSaveCallback()
save()
saveRowsByLinks()
callEditableFieldSaveHandlers()
hasRow()
setRowByData()
setRow()
getRow()
getRows()
getModel()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
$rowsByName
$links
$linkCallback
$saveCallback
$inputFilter
$inputFilterHelper
$saveHandlerHelper
$deleteField
$fields
$request
$defaultsByModelName
N/A

Properties

$rowsByName

$rowsByName : array

An associative array containing all the row objects you've provided, with the model names from your \Dewdrop\Fields object as keys.

Type

array

$links

$links : array

In most cases, you can link all your rows simply by pointing RowEditor to a variable it can use to find() the row by primary key.

Type

array

$linkCallback

$linkCallback : callable

Set a custom link callback to use when linking rows to their fields.

Type

callable

$saveCallback

$saveCallback : callable

Set a custom callback to use when saving.

Type

callable

$inputFilter

$inputFilter : \Zend\InputFilter\InputFilter

A ZF2 \Zend\InputFilter\InputFilter object containing inputs for editable fields.

Type

\Zend\InputFilter\InputFilter

$inputFilterHelper

$inputFilterHelper : \Dewdrop\Fields\Helper\InputFilter

A helper that will generate \Zend\InpuFilter\Input objects for each editable field.

Type

\Dewdrop\Fields\Helper\InputFilter

$deleteField

$deleteField : \Dewdrop\Db\Field

A boolean field that can be used to flag a row as deleted.

Type

\Dewdrop\Db\Field

$fields

$fields : \Dewdrop\Fields

The fields from which we'll get input filter inputs and for which we'll set values.

Type

\Dewdrop\Fields

$request

$request : \Dewdrop\Request

The HTTP request where we'll get the input data.

Type

\Dewdrop\Request

$defaultsByModelName

$defaultsByModelName : array

Default values for rows by model name. Will set these automatically once the rows are linked.

Type

array

Methods

getFields()

getFields() : \Dewdrop\Fields

Get the Fields object associated with this RowEditor.

Returns

\Dewdrop\Fields

getRequest()

getRequest() : \Dewdrop\Request

Get the HTTP request associated wit this RowEditor.

Returns

\Dewdrop\Request

setDefaults()

setDefaults(string  $modelName, array  $defaults) : $this

Set some default values for the row matching the supplied model name.

Once the rows are linked, your defaults will be applied automatically.

Parameters

string $modelName
array $defaults

Throws

\Dewdrop\Fields\Exception

Returns

$this

applyDefaultsToRow()

applyDefaultsToRow(\Dewdrop\Db\Row  $row, array  $defaults) : $this

Apply the supplied default values to the row, skipping any fields that already have a value.

Parameters

\Dewdrop\Db\Row $row
array $defaults

Throws

\Dewdrop\Exception

Returns

$this

reset()

reset() : $this

Clear out the row objects on this editor. Useful if you're using the same editor

Returns

$this

link()

link() : \Dewdrop\Fields\RowEditor

Just a shortcut/alias for linkRowsToFields(). Easier to remember.

Returns

\Dewdrop\Fields\RowEditor

linkRowsToFields()

linkRowsToFields() : \Dewdrop\Fields\RowEditor

Create row objects and link them to the appropriate database fields. To create the row objects, you can either provide a number of \Dewdrop\Fields\RowEditor\Link\LinkInterface objects (typically by calling this class's linkByQueryString() and linkByField() methods), or you can provide your own custom linker by calling setLinkCallback().

Throws

\Dewdrop\Exception

Returns

\Dewdrop\Fields\RowEditor

setLinkCallback()

setLinkCallback(callable  $linkCallback) : \Dewdrop\Fields\RowEditor

Set a custom callback to be used when doing row linking. This can be useful if your case is not covered by the built-in linkers available via linkByQueryString() and linkByField().

Your callback will receive two arguments:

  1. The RowEditor instance.

  2. The HTTP request object.

Parameters

callable $linkCallback

Returns

\Dewdrop\Fields\RowEditor

linkByQueryString()

linkByQueryString(string  $modelName, string  $queryStringVariableName) : \Dewdrop\Fields\RowEditor

Link a row using a query string variable.

Parameters

string $modelName
string $queryStringVariableName

Returns

\Dewdrop\Fields\RowEditor

linkTableByQueryString()

linkTableByQueryString(\Dewdrop\Db\Table  $table) : \Dewdrop\Fields\RowEditor

A shortcut for linkByQueryString() that uses Table object get the model and query string param name.

Parameters

\Dewdrop\Db\Table $table

Throws

\Dewdrop\Fields\Exception

Returns

\Dewdrop\Fields\RowEditor

linkByField()

linkByField(string  $modelName, \Dewdrop\Db\Field  $field) : \Dewdrop\Fields\RowEditor

Link a row using a field object.

Parameters

string $modelName
\Dewdrop\Db\Field $field

Returns

\Dewdrop\Fields\RowEditor

isNew()

isNew() : boolean

Check to see if we're currently editing new rows or existing rows.

If any of the rows are not new, this will return false.

Throws

\Dewdrop\Exception

Returns

boolean

isValid()

isValid(array  $data) : boolean

Assign the supplied data to our field objects and check to see if it is valid using the internal input filter.

Parameters

array $data

Returns

boolean

getInputFilter()

getInputFilter() : \Zend\InputFilter\InputFilter

Get the \Zend\InputFilter\InputFilter object from the helper. At the time this method is first called, the helper will be asked to add \Zend\InputFilter\Input objects from each field to the filter.

Returns

\Zend\InputFilter\InputFilter

getMessages()

getMessages(\Dewdrop\Fields\FieldInterface  $field) : array

Get the validation messages associated with a specific field.

Parameters

\Dewdrop\Fields\FieldInterface $field

Returns

array

setDeleteField()

setDeleteField(\Dewdrop\Db\Field  $deleteField) : $this

Set the field that can be used to delete this item.

Parameters

\Dewdrop\Db\Field $deleteField

Returns

$this

hasDeleteField()

hasDeleteField() : boolean

Check to see if a delete field is assigned to this editor.

Returns

boolean

isDeleted()

isDeleted() 

delete()

delete() : void

Perform a delete using the RowEditor's delete field, if specified.

restore()

restore() 

Perform a restore using the RowEditor's delete field, if specified.

setSaveCallback()

setSaveCallback(callable  $callback) : \Dewdrop\Fields\RowEditor

Set a custom save callback. This can be useful if you need to do anything beyond calling the save methods on your rows. Your callback will receive this object as its only argument. You can call getRow() as needed to retrieve your rows for saving.

Parameters

callable $callback

Returns

\Dewdrop\Fields\RowEditor

save()

save() : \Dewdrop\Fields\RowEditor

Save the editor's rows. You can optionally provide your own save routine by calling setSaveCallback().

Returns

\Dewdrop\Fields\RowEditor

saveRowsByLinks()

saveRowsByLinks() : \Dewdrop\Fields\RowEditor

In most common cases, the rows handled by a RowEditor object are linked to one another by foreign key using the linkByField() method. When this is the case, we can traverse those links in reverse order, saving the rows at the end of the chain of links first so that they can populate the fields on the tables farther up the chain. Once the field links have been traversed, we can save the other rows safely.

If you are not using linkByField(), you may need to provide a custom save callback that takes your situation into account.

Returns

\Dewdrop\Fields\RowEditor

callEditableFieldSaveHandlers()

callEditableFieldSaveHandlers() : $this

Call the save handlers on any editable fields. You'll typically only need to call this if you're doing a custom save callback and are leveraging save handlers (e.g.

via a RowCollectionEditor).

Returns

$this

hasRow()

hasRow(string  $modelName) : boolean

Check to see if the row editor has a row with the given model name.

Parameters

string $modelName

Returns

boolean

setRowByData()

setRowByData(  $modelName, array  $data) 

Parameters

$modelName
array $data

setRow()

setRow(string  $modelName, \Dewdrop\Db\Row  $row) : \Dewdrop\Fields\RowEditor

Assign the provided row object to the named model. This will iterate over all the fields and call setRow() on each one associated with the named model so that their values can be set and retrieved for editing.

Parameters

string $modelName
\Dewdrop\Db\Row $row

Throws

\Dewdrop\Fields\Exception

Returns

\Dewdrop\Fields\RowEditor

getRow()

getRow(string  $modelName) : \Dewdrop\Db\Row

Get a row by its model name.

Parameters

string $modelName

Throws

\Dewdrop\Exception

Returns

\Dewdrop\Db\Row

getRows()

getRows() : array

Get all the row objects from this editor.

Returns

array

getModel()

getModel(string  $modelName) : \Dewdrop\Db\Table

Get a model from the fields object by its model name.

Parameters

string $modelName

Throws

\Dewdrop\Fields\Exception

Returns

\Dewdrop\Db\Table