PHP Class MetaModels\Item

Inheritance: implements metamodels\IItem
Show file Open project: metamodels/core Class Usage Examples

Protected Properties

Property Type Description
$arrData array The data array containing the raw values obtained from the attributes.
$metaModel metamodels\IMetaModel Get's populated with the first call to getMetaModel() (lazy initialization).

Public Methods

Method Description
__construct ( metamodels\IMetaModel $objMetaModel, array $arrData ) Create a new instance.
buildJumpToLink ( MetaModels\Render\Setting\ICollection $objSettings ) : array Build the jumpTo link for use in templates.
copy ( ) : metamodels\IItem Returns a new item containing the same values as this item but no id.
get ( string $strAttributeName ) : mixed Return the native value of an attribute.
getAttribute ( string $strAttributeName ) : MetaModels\Attribute\IAttribute Fetch the MetaModel attribute instance with the given name.
getMetaModel ( ) : metamodels\IMetaModel Fetch the MetaModel that this item is originating from.
getServiceContainer ( ) : metamodels\IMetaModelsServiceContainer Retrieve the service container.
getSetAttributes ( ) : array Return a list of the col names from the attributes which are set.
getSiblings ( MetaModels\Filter\IFilter $objFilter ) : null | metamodels\IItems Find all Variants including the variant base.
getVariants ( MetaModels\Filter\IFilter $objFilter ) : metamodels\IItems Fetch the meta model variants for this item.
internalParseAttribute ( MetaModels\Attribute\IAttribute $objAttribute, string $strOutputFormat, MetaModels\Render\Setting\ICollection | null $objSettings ) : array Helper function for {@see MetaModelItem::parseValue()} and {@see MetaModelItem::parseAttribute()}.
isAttributeSet ( string $strAttributeName ) : boolean Check if the given attribute is set. This mean if in the data array is the filed set or not. If the attribute is not loaded the function will return false.
isVariant ( ) : boolean Determines if this item is a variant of another item.
isVariantBase ( ) : boolean Determines if this item is variant base of other items.
parseAttribute ( string $strAttributeName, string $strOutputFormat = 'text', MetaModels\Render\Setting\ICollection $objSettings = null ) : array Renders a single attribute in the given output format.
parseValue ( string $strOutputFormat = 'text', MetaModels\Render\Setting\ICollection $objSettings = null ) : array Renders the item in the given output format.
save ( ) : void Save the current data for every attribute to the data sink.
set ( string $strAttributeName, mixed $varValue ) : metamodels\IItem Set the native value of an Attribute.
varCopy ( ) : MetaModels\IItem Returns a new item containing the same values as this item but no id.

Protected Methods

Method Description
getEventDispatcher ( ) : Symfony\Component\EventDispatcher\EventDispatcherInterface Retrieve the event dispatcher.
isArrayEmpty ( array $arrArray ) : boolean Run through each level of an array and check if we have at least one empty value.
isEmptyValue ( array $mixValue ) : boolean Check if a value is empty.
registerAssets ( MetaModels\Render\Setting\ICollection | null $objSettings ) : void Register the assets in Contao.

Method Details

__construct() public method

Create a new instance.
public __construct ( metamodels\IMetaModel $objMetaModel, array $arrData )
$objMetaModel metamodels\IMetaModel The model this item is represented by.
$arrData array The initial data that shall be injected into the new instance.

copy() public method

This is useful when creating new items that shall be based upon another item.
public copy ( ) : metamodels\IItem
return metamodels\IItem the new copy.

get() public method

Return the native value of an attribute.
public get ( string $strAttributeName ) : mixed
$strAttributeName string The name of the attribute.
return mixed

getAttribute() public method

Fetch the MetaModel attribute instance with the given name.
public getAttribute ( string $strAttributeName ) : MetaModels\Attribute\IAttribute
$strAttributeName string The name of the attribute.
return MetaModels\Attribute\IAttribute The instance.

getEventDispatcher() protected method

Retrieve the event dispatcher.
protected getEventDispatcher ( ) : Symfony\Component\EventDispatcher\EventDispatcherInterface
return Symfony\Component\EventDispatcher\EventDispatcherInterface

getMetaModel() public method

Fetch the MetaModel that this item is originating from.
public getMetaModel ( ) : metamodels\IMetaModel
return metamodels\IMetaModel the instance.

getServiceContainer() public method

Retrieve the service container.
public getServiceContainer ( ) : metamodels\IMetaModelsServiceContainer
return metamodels\IMetaModelsServiceContainer

getSetAttributes() public method

Including all meta field as well.
public getSetAttributes ( ) : array
return array

getSiblings() public method

The item itself is excluded from the return list.
public getSiblings ( MetaModels\Filter\IFilter $objFilter ) : null | metamodels\IItems
$objFilter MetaModels\Filter\IFilter The additional filter settings to apply.
return null | metamodels\IItems

getVariants() public method

Fetch the meta model variants for this item.
public getVariants ( MetaModels\Filter\IFilter $objFilter ) : metamodels\IItems
$objFilter MetaModels\Filter\IFilter The filter settings to be applied.
return metamodels\IItems A list of all variants for this item.

internalParseAttribute() public method

Helper function for {@see MetaModelItem::parseValue()} and {@see MetaModelItem::parseAttribute()}.
public internalParseAttribute ( MetaModels\Attribute\IAttribute $objAttribute, string $strOutputFormat, MetaModels\Render\Setting\ICollection | null $objSettings ) : array
$objAttribute MetaModels\Attribute\IAttribute The attribute to parse.
$strOutputFormat string The desired output format.
$objSettings MetaModels\Render\Setting\ICollection | null The settings object to be applied.
return array The parsed information for the given attribute.

isArrayEmpty() protected method

Run through each level of an array and check if we have at least one empty value.
protected isArrayEmpty ( array $arrArray ) : boolean
$arrArray array The array to check.
return boolean True => empty, False => some values found.

isAttributeSet() public method

Check if the given attribute is set. This mean if in the data array is the filed set or not. If the attribute is not loaded the function will return false.
public isAttributeSet ( string $strAttributeName ) : boolean
$strAttributeName string The desired attribute.
return boolean True means the data is set, on load of the item or at any time. False means the attribute is not set.

isEmptyValue() protected method

Check if a value is empty.
protected isEmptyValue ( array $mixValue ) : boolean
$mixValue array The value.
return boolean True => empty, false => found a valid values

isVariant() public method

Determines if this item is a variant of another item.
public isVariant ( ) : boolean
return boolean True if it is an variant, false otherwise.

isVariantBase() public method

Note: this does not mean that there actually exist variants of this item. It merely simply states, that this item is able to function as variant base for other items.
public isVariantBase ( ) : boolean
return boolean True if it is an variant base, false otherwise.

parseAttribute() public method

Renders a single attribute in the given output format.
public parseAttribute ( string $strAttributeName, string $strOutputFormat = 'text', MetaModels\Render\Setting\ICollection $objSettings = null ) : array
$strAttributeName string The desired attribute.
$strOutputFormat string The desired output format (optional - default: text).
$objSettings MetaModels\Render\Setting\ICollection The render settings to use (optional - default: null).
return array format=>value

parseValue() public method

Renders the item in the given output format.
public parseValue ( string $strOutputFormat = 'text', MetaModels\Render\Setting\ICollection $objSettings = null ) : array
$strOutputFormat string The desired output format (optional - default: text).
$objSettings MetaModels\Render\Setting\ICollection The render settings to use (optional - default: null).
return array attribute name => format => value

registerAssets() protected method

Register the assets in Contao.
protected registerAssets ( MetaModels\Render\Setting\ICollection | null $objSettings ) : void
$objSettings MetaModels\Render\Setting\ICollection | null The render settings to use.
return void

save() public method

Save the current data for every attribute to the data sink.
public save ( ) : void
return void

set() public method

Set the native value of an Attribute.
public set ( string $strAttributeName, mixed $varValue ) : metamodels\IItem
$strAttributeName string The name of the attribute.
$varValue mixed The value of the attribute.
return metamodels\IItem

varCopy() public method

Additionally, the item will be a variant child of this item. NOTE: if this item is not a variant base itself, this item will return a item that is a child of this items variant base. i.e. exact clone.
public varCopy ( ) : MetaModels\IItem
return MetaModels\IItem the new copy.

Property Details

$arrData protected property

The data array containing the raw values obtained from the attributes.
protected array $arrData
return array

$metaModel protected property

Get's populated with the first call to getMetaModel() (lazy initialization).
protected IMetaModel,metamodels $metaModel
return metamodels\IMetaModel