Formagic Container Item class

Changes on following flag will be applied recursively to all items added to the container object: - _isHidden - _isReadonly - _isDisabled

Changes on the flag _isPostItem will only be applied to the container item itself (and defaults to false as there is no use posting a container item).

category Formagic
package Item
author Florian Sonnenburg
copyright Copyright (c) 2011 Florian Sonnenburg
version $Id: Container.php 169 2012-05-06 20:16:16Z meweasle $

 Methods

Constructor

__construct(string $name, array $arguments) : void
Inherited

inherited_from \Formagic_Item_Abstract::__construct()

Parameters

$name

string

Name of item

$arguments

array

Additional arguments

Exceptions

\Formagic_Exception

Returns the HTML string representation of the form item.

__toString() : string
Inherited

inherited_from \Formagic_Item_Abstract::__toString()

Returns

stringThe HTML string representation.

Adds an HTML attribute to the attributes stack.

addAttribute(string $name, string $value) : \Formagic_Item_Abstract
Inherited

Implements a fluent interface pattern.

inherited_from \Formagic_Item_Abstract::addAttribute()

Parameters

$name

string

Attribute name

$value

string

Attribute value

Returns

Adds a filter to this container and all contained items.

addFilter(mixed $filter, array $args) : \Formagic_Item_Container

Formagic items can have multiple filters which will be applied in the order they are passed to the object.

First parameter $filter can either be a string or an object of a class that extends Formagic_Filter_Interface. A string value is assumed to be the type of filter to be added.

This method throws an exception if no valid role object can be identified.

Implements a fluent interface pattern.

see \Formagic_Item_Abstract::addFilter()

Parameters

$filter

mixed

Filter type string or Formatic_Filter_Interface object.

$args

array

Optional array of arguments. Will be passed to the filter constructor as array.

Exceptions

\Formagic_Exception if $filter argument is invalid

Returns

Adds formagic item object to array of items.

addItem(\Formagic_Item_Abstract | String $item, string $name, array $args) : \Formagic_Item_Container

Creates new item object and adds this, or adds passed formagicItem object

Parameters

$item

\Formagic_Item_AbstractString

String with item type or Formagic_Item_Abstract object

$name

string

String with item name. NULL if $type is Formagic_Item_Abstract object

$args

array

Array with additional item information. NULL if $type is Formagic_Item_Abstract object

Returns

\Formagic_Item_ContainerFluent interface

Adds a rule to this container and all contained items.

addRule(mixed $rule, array $args) : \Formagic_Item_Container

Formagic items can have multiple rules which will be applied in the order they are passed to the object.

First parameter $rule can either be a string or an instance of a class that extends Formagic_Rule_Abstract. A string value is assumed to be the type of rule to be added.

Implements a fluent interface pattern.

see \Formagic_Item_Abstract::addRule()

Parameters

$rule

mixed

Rule type string or Formagic_Rule_Abstract object.

$args

array

Optional array of arguments. Will be passed to the rule constructor as array.

Exceptions

\Formagic_Exception if $rule argument is invalid

Returns

Counts items added to self and all sub-containers.

count() : integer

Returns

integerThe number of items in this container

Returns value of an attribute for this item.

getAttribute(string $name) : string
Inherited

see \Formagic_Item_Abstract::setAttributes()
see \Formagic_Item_Abstract::addAttribute()
inherited_from \Formagic_Item_Abstract::getAttribute()

Parameters

$name

string

Name of the attribute value to fetch

Returns

stringAttribute value

Returns attribute string for HTML tag.

getAttributeStr() : string
Inherited

Takes the attributes array and transforms it into a string that can be directly inserted into a HTML tag. The string will be built with a trailing space character.

Two default attributes are added to the attributes string: "name" and "id". If you want to skip these, add them to your attributes on item generation or via setAttributes() or addAttribute() with NULL as value.

$item->setAttributes(array('class' => 'myclass', 'onclick' => 'alert('Formagic');'));
$string = $item->getAttributeStr();
echo '';
// output will be:
// 

see \Formagic_Item_Abstract::setAttributes()
see \Formagic_Item_Abstract::addAttribute()
inherited_from \Formagic_Item_Abstract::getAttributeStr()

Returns

stringThe attributes string.

Returns the attributes array for this item.

getAttributes() : array
Inherited

see \Formagic_Item_Abstract::setAttributes()
see \Formagic_Item_Abstract::addAttribute()
inherited_from \Formagic_Item_Abstract::getAttributes()

Returns

arrayThe attributes array.

HTML template for renderers that use HTML-Code.

getHtml() : string
Inherited

Should be overwritten by subclasses.

inherited_from \Formagic_Item_Abstract::getHtml()

Returns

stringThe HTML string representation of this item.

Returns added item $name.

getItem(string $name, boolean $throwException) : \Formagic_Item_Abstract

Throws Formagic_Exception by default if item does not exist. This can be altered by setting $throwException to FALSE; the result value will be NULL then.

Parameters

$name

string

Item identifier string.

$throwException

boolean

Returns NULL if set to FALSE.

Exceptions

\Formagic_Exception

Returns

\Formagic_Item_AbstractReturns the Formagic item identified by $name or throws exception if not found.

Returns items array

getItems() : array

Returns

array

Completes the IteratorAggregate interface.

getIterator() : \ArrayObject

Returns

\ArrayObjectArrayObject with container items.

Returns label for this item.

getLabel() : string
Inherited

inherited_from \Formagic_Item_Abstract::getLabel()

Returns

stringThe label string.

Returns the item name.

getName() : string
Inherited

inherited_from \Formagic_Item_Abstract::getName()

Returns

stringThe item name

Returns current unfiltered value for this item.

getUnfilteredValue() : mixed
Inherited

inherited_from \Formagic_Item_Abstract::getUnfilteredValue()

Returns

mixedThe unfiltered item value

Returns values of all stored items.

getValue() : array

The return value will be an associative array, the keys beeing the name of the item, the value beeing the filtered item value.

Returns

arrayArray of item values.

Returns array of violated rules.

getViolatedRules() : array
Inherited

If no rules were violated or if no validation has been performed yet, an empty array will be returned.

inherited_from \Formagic_Item_Abstract::getViolatedRules()

Returns

arrayThe violated rules.

Checks if a specific filter is defined for a Formagic item.

hasFilter(string $filterName) : boolean
Inherited

inherited_from \Formagic_Item_Abstract::hasFilter()

Parameters

$filterName

string

Filter name

Returns

booleanCheck value

Tells if a rule exists for this item.

hasRule(string $ruleName) : boolean
Inherited

The $ruleName parameter has to be a string with the name of rule that is looked for. If you want to know for example if the item has the mandatory rule added, $ruleName would have to be 'mandatory'.

The search string is case insensitive.

addRule($mandatory);

// look for the rule
$ruleExists = $item->hasRule('mandatory'); // would return TRUE
$ruleExists = $item->hasRule('Mandatory'); // would return TRUE
$ruleExists = $item->hasRule('Formagic_Rule_Mandatory'); // would return FALSE
?>

inherited_from \Formagic_Item_Abstract::hasRule()

Parameters

$ruleName

string

Rule name, eg. 'Mandatory'

Returns

boolean

Returns disabled status of item

isDisabled() : boolean
Inherited

inherited_from \Formagic_Item_Abstract::isDisabled()

Returns

booleanThe disabled status.

Returns hidden status of item

isHidden() : boolean
Inherited

inherited_from \Formagic_Item_Abstract::isHidden()

Returns

booleanThe hidden status.

Returns ignore status of item

isIgnored() : boolean
Inherited

inherited_from \Formagic_Item_Abstract::isIgnored()

Returns

booleanThe ignored status.

Prints item infos.

printInfo() : string
Inherited

inherited_from \Formagic_Item_Abstract::printInfo()

Returns

stringThe item information string

Sets additional attributes for this item.

setAttributes(array $attArray) : \Formagic_Item_Abstract
Inherited

Mainly used for additional HTML attributes other than "name", "id" or "value", such as "style", "class", javascript-handlers etc. Attributes are added corresponding to key->value-pairs in $attArray.

setAttributes() will overwrite any previously added item attributes.

Implements a fluent interface pattern.

see \Formagic_Item_Abstract::addAttribute()
inherited_from \Formagic_Item_Abstract::setAttributes()

Parameters

$attArray

array

The new

Returns

Disables container item and all its descendants and thus removes all involved items from form.

setDisabled(boolean $flag) : \Formagic_Item_Container

Implements a fluent interface pattern.

see \Formagic_Item_Abstract::setDisabled()

Parameters

$flag

boolean

Disabled status flag.

Returns

Sets isFixed flag.

setFixed(boolean $flag) : \Formagic_Item_Abstract
Inherited

If set to true, all following calls to setValue() will be ignored.

Implements a fluent interface pattern.

inherited_from \Formagic_Item_Abstract::setFixed()

Parameters

$flag

boolean

IsFixed flag value.

Returns

Sets hidden flag on container item and all its descendants.

setHidden(boolean $flag) : \Formagic_Item_Container

Implements a fluent interface pattern.

see \Formagic_Item_Abstract::setHidden()

Parameters

$flag

boolean

Hidden status flag.

Returns

Defines if the item will be ignored in form submit.

setIgnore(boolean $flag) : \Formagic_Item_Abstract
Inherited

Implements a fluent interface pattern.

inherited_from \Formagic_Item_Abstract::setIgnore()

Parameters

$flag

boolean

Ignored status flag.

Returns

Sets readonly flag to container item and all its descendants.

setReadonly(boolean $flag) : \Formagic_Item_Container

Implements a fluent interface pattern.

see \Formagic_Item_Abstract::setReadonly()

Parameters

$flag

boolean

Readonly status flag.

Returns

Defines which attributes are always to be added to this input element.

setRequiredAttributes(array $requiredAttributes) : \Formagic_Item_Abstract
Inherited

Default required attributes are "id" and "name".

inherited_from \Formagic_Item_Abstract::setRequiredAttributes()

Parameters

$requiredAttributes

array

Numeric array of required attributes.

Returns

\Formagic_Item_AbstractFluent interface.

Sets new values for all items assigned to this container.

setValue(array $value) : \Formagic_Item_Container

Other than in Formagic_Item_Abstract defined, $value has to be an associative array, the key beeing the name of the item the value belongs to.

Implements a fluent interface pattern.

Parameters

$value

array

Set of new values for contained items.

Returns

Validates contained items.

validate() : boolean

Iterates through all contained items. If any rule is violated, sub-item will return violated Formagic_Rule item and the container will pass it on.

If all items pass violation, validate() calls onValidate-handler and returns its result.

Returns

boolean

Assembles attribute string in HTML-conform style

_buildAttributeStr(array $attributes) : string
Inherited

inherited_from \Formagic_Item_Abstract::_buildAttributeStr()

Parameters

$attributes

array

array of attributes

Returns

stringAttributes string

Filters a value

_filterValue(Formagic_Filter_Interface $filter, mixed $subject) : mixed
Inherited

inherited_from \Formagic_Item_Abstract::_filterValue()

Parameters

$filter

\Formagic_Filter_Interface

Filter object

$subject

mixed

Scalar or array

Returns

mixedFiltered scalar or array

Allow subclass initialization.

_init(array $additionalArgs) : void
Inherited

inherited_from \Formagic_Item_Abstract::_init()

Parameters

$additionalArgs

array

Array of arguments that are not processed by superclass.

Perform validation on item value.

_validateItemValue(Formagic_Rule_Abstract $rule, string | array $subject) : boolean
Inherited

inherited_from \Formagic_Item_Abstract::_validateItemValue()

Parameters

$rule

\Formagic_Rule_Abstract

Validation rule object

$subject

stringarray

Validation subject

Returns

booleanValidation result

Takes a string and returns a valid DOM ID.

_makeDomId(string $str) : string
Inherited

inherited_from \Formagic_Item_Abstract::_makeDomId()

Parameters

$str

string

String to convert to a DOM ID

Returns

stringValid DOM ID

 Properties

 

Container headline

$headline : string

 

Additional attributes for item HTML tag

$_attributes : array
Inherited

inherited_from \Formagic_Item_Abstract::$$_attributes
 

Array of input filters for this item

$_filters : array
Inherited

inherited_from \Formagic_Item_Abstract::$$_filters
 

Determines if item is removed from Formagic form.

$_isDisabled : boolean
Inherited

inherited_from \Formagic_Item_Abstract::$$_isDisabled
 

Determines if value can be changed.

$_isFixed : boolean
Inherited

inherited_from \Formagic_Item_Abstract::$$_isFixed
 

Determines if item will be displayed

$_isHidden : boolean
Inherited

inherited_from \Formagic_Item_Abstract::$$_isHidden
 

Determines if item content should be interpreted after submit.

$_isIgnored : boolean
Inherited

inherited_from \Formagic_Item_Abstract::$$_isIgnored
 

Determines if item content can be edited.

$_isReadonly : boolean
Inherited

inherited_from \Formagic_Item_Abstract::$$_isReadonly
 

Pointer to items array section of formagic object

$_items : string

 

Form item label

$_label : boolean
Inherited

inherited_from \Formagic_Item_Abstract::$$_label
 

Form item name

$_name : string
Inherited

inherited_from \Formagic_Item_Abstract::$$_name
 

Define what attributes are required for default container item

$_requiredAttributes : array

 

Array of rule object that are applied for this item

$_rules : array
Inherited

inherited_from \Formagic_Item_Abstract::$$_rules
 

Item value

$_value : mixed
Inherited

inherited_from \Formagic_Item_Abstract::$$_value
 

Filtered item value cache

$_filteredValue : mixed
Inherited

inherited_from \Formagic_Item_Abstract::$$_filteredValue
 

Violated rule after validation

$_violatedRules : \Form_Rule_Abstract
Inherited

inherited_from \Formagic_Item_Abstract::$$_violatedRules