PHP Class MetaModels\MetaModel

See also: MetaModelFactory::byId() to instantiate a MetaModel by its ID.
See also: MetaModelFactory::byTableName() to instantiate a MetaModel by its table name. This class handles all attribute definition instantiation and can be queried for a view instance to certain entries.
Inheritance: implements metamodels\IMetaModel
Show file Open project: metamodels/core Class Usage Examples

Protected Properties

Property Type Description
$arrAttributes array Association is $colName => object
$arrData array This is the data from tl_metamodel.
$serviceContainer metamodels\IMetaModelsServiceContainer The service container.

Public Methods

Method Description
__construct ( array $arrData ) Instantiate a MetaModel.
addAttribute ( MetaModels\Attribute\IAttribute $objAttribute )
delete ( metamodels\IItem $objItem )
findByFilter ( $objFilter, $strSortBy = '', $intOffset, $intLimit, $strSortOrder = 'ASC', $arrAttrOnly = [] )
findById ( $intId, $arrAttrOnly = [] )
findVariantBase ( $objFilter )
findVariants ( $arrIds, $objFilter )
findVariantsWithBase ( $arrIds, $objFilter )
get ( $strKey )
getActiveLanguage ( )
getAttribute ( $strAttributeName )
getAttributeById ( $intId )
getAttributeOptions ( $strAttribute, $objFilter = null )
getAttributes ( )
getAvailableLanguages ( )
getCount ( $objFilter )
getEmptyFilter ( )
getFallbackLanguage ( )
getIdsFromFilter ( $objFilter, $strSortBy = '', $intOffset, $intLimit, $strSortOrder = 'ASC' )
getInVariantAttributes ( )
getName ( )
getServiceContainer ( )
getTableName ( )
getView ( $intViewId )
hasAttribute ( $strAttributeName )
hasVariants ( )
isTranslated ( )
prepareFilter ( $intFilterSettings, $arrFilterUrl )
saveItem ( $objItem )
setServiceContainer ( metamodels\IMetaModelsServiceContainer $serviceContainer ) : MetaModel Set the service container.

Protected Methods

Method Description
buildDatabaseParameterList ( array $parameters ) : string Build a list of the correct amount of "?" for use in a db query.
convertRowsToResult ( Database\Result $objRow, string[] $arrAttrOnly = [] ) : array Convert a database result to a result array.
copyFilter ( MetaModels\Filter\IFilter | null $objFilter ) : MetaModels\Filter\IFilter Clone the given filter or create an empty one if no filter has been passed.
createNewItem ( metamodels\IItem $item ) : void Create a new item in the database.
fetchAdditionalAttributes ( string[] $ids, array $result, string[] $attrOnly = [] ) : array This method is called to retrieve the data for certain items from the database.
fetchRows ( string[] $arrIds, string[] $arrAttrOnly = [] ) : array Fetch the "native" database rows with the given ids.
fetchTranslatedAttributeValues ( MetaModels\Attribute\ITranslated $attribute, string[] $ids ) : array This method is called to retrieve the data for certain items from the database.
getAttributeByNames ( string[] $attrNames = [] ) : MetaModels\Attribute\IAttribute[] Retrieve all attributes with the given names.
getAttributeImplementing ( string $interface ) : array Retrieve all attributes implementing the given interface.
getComplexAttributes ( ) : MetaModels\Attribute\IComplex[] This method retrieves all complex attributes from the current MetaModel.
getDatabase ( ) : Database Retrieve the database instance to use.
getItemsWithId ( int[] $arrIds, string[] $arrAttrOnly = [] ) : MetaModels\IItems This method is called to retrieve the data for certain items from the database.
getMatchingIds ( MetaModels\Filter\IFilter | null $objFilter ) : array Narrow down the list of Ids that match the given filter.
getSimpleAttributes ( ) : MetaModels\Attribute\ISimple[] This method retrieves all simple attributes from the current MetaModel.
getTranslatedAttributes ( ) : MetaModels\Attribute\ITranslated[] This method retrieves all translated attributes from the current MetaModel.
isComplexAttribute ( MetaModels\Attribute\IAttribute $objAttribute ) : boolean Determine if the given attribute is a complex one.
isSimpleAttribute ( MetaModels\Attribute\IAttribute $objAttribute ) : boolean Determine if the given attribute is a simple one.
isTranslatedAttribute ( MetaModels\Attribute\IAttribute $objAttribute ) : boolean Determine if the given attribute is a translated one.
saveAttribute ( MetaModels\Attribute\IAttribute $objAttribute, array $arrIds, mixed $varData, string $strLangCode ) : void Update an attribute for the given ids with the given data.
saveSimpleColumn ( string $strColumn, array $arrIds, mixed $varData ) : void Update the value of a native column for the given ids with the given data.
tryUnserialize ( string $value ) : mixed Try to unserialize a value.
updateVariants ( metamodels\IItem $item, string $activeLanguage, int[] $allIds, boolean $baseAttributes = false ) : void Update the variants with the value if needed.

Method Details

__construct() public method

Instantiate a MetaModel.
public __construct ( array $arrData )
$arrData array The information array, for information on the available columns, refer to documentation of table tl_metamodel.

addAttribute() public method

public addAttribute ( MetaModels\Attribute\IAttribute $objAttribute )
$objAttribute MetaModels\Attribute\IAttribute

buildDatabaseParameterList() protected method

Build a list of the correct amount of "?" for use in a db query.
protected buildDatabaseParameterList ( array $parameters ) : string
$parameters array The parameters.
return string

convertRowsToResult() protected method

Convert a database result to a result array.
protected convertRowsToResult ( Database\Result $objRow, string[] $arrAttrOnly = [] ) : array
$objRow Database\Result The database result.
$arrAttrOnly string[] The list of attributes to return, if any.
return array

copyFilter() protected method

Clone the given filter or create an empty one if no filter has been passed.
protected copyFilter ( MetaModels\Filter\IFilter | null $objFilter ) : MetaModels\Filter\IFilter
$objFilter MetaModels\Filter\IFilter | null The filter to clone.
return MetaModels\Filter\IFilter the cloned filter.

createNewItem() protected method

Create a new item in the database.
protected createNewItem ( metamodels\IItem $item ) : void
$item metamodels\IItem The item to be created.
return void

delete() public method

public delete ( metamodels\IItem $objItem )
$objItem metamodels\IItem

fetchAdditionalAttributes() protected method

This method is called to retrieve the data for certain items from the database.
protected fetchAdditionalAttributes ( string[] $ids, array $result, string[] $attrOnly = [] ) : array
$ids string[] The ids of the items to retrieve the order of ids is used for sorting of the return values.
$result array The current values.
$attrOnly string[] Names of the attributes that shall be contained in the result, defaults to array() which means all attributes.
return array an array of all matched items, sorted by the id list.

fetchRows() protected method

Fetch the "native" database rows with the given ids.
protected fetchRows ( string[] $arrIds, string[] $arrAttrOnly = [] ) : array
$arrIds string[] The ids of the items to retrieve the order of ids is used for sorting of the return values.
$arrAttrOnly string[] Names of the attributes that shall be contained in the result, defaults to array() which means all attributes.
return array an array containing the database rows with each column "deserialized".

fetchTranslatedAttributeValues() protected method

This method is called to retrieve the data for certain items from the database.
protected fetchTranslatedAttributeValues ( MetaModels\Attribute\ITranslated $attribute, string[] $ids ) : array
$attribute MetaModels\Attribute\ITranslated The attribute to fetch the values for.
$ids string[] The ids of the items to retrieve the order of ids is used for sorting of the return values.
return array an array of all matched items, sorted by the id list.

findByFilter() public method

public findByFilter ( $objFilter, $strSortBy = '', $intOffset, $intLimit, $strSortOrder = 'ASC', $arrAttrOnly = [] )

findById() public method

public findById ( $intId, $arrAttrOnly = [] )

findVariantBase() public method

public findVariantBase ( $objFilter )

findVariants() public method

public findVariants ( $arrIds, $objFilter )

findVariantsWithBase() public method

public findVariantsWithBase ( $arrIds, $objFilter )

get() public method

public get ( $strKey )

getActiveLanguage() public method

The value is taken from $GLOBALS['TL_LANGUAGE']
public getActiveLanguage ( )

getAttribute() public method

public getAttribute ( $strAttributeName )

getAttributeById() public method

public getAttributeById ( $intId )

getAttributeByNames() protected method

Retrieve all attributes with the given names.
protected getAttributeByNames ( string[] $attrNames = [] ) : MetaModels\Attribute\IAttribute[]
$attrNames string[] The attribute names, if empty all attributes will be returned.
return MetaModels\Attribute\IAttribute[]

getAttributeImplementing() protected method

Retrieve all attributes implementing the given interface.
protected getAttributeImplementing ( string $interface ) : array
$interface string The interface name.
return array

getAttributeOptions() public method

public getAttributeOptions ( $strAttribute, $objFilter = null )

getAttributes() public method

public getAttributes ( )

getAvailableLanguages() public method

getComplexAttributes() protected method

This method retrieves all complex attributes from the current MetaModel.
protected getComplexAttributes ( ) : MetaModels\Attribute\IComplex[]
return MetaModels\Attribute\IComplex[] all complex attributes defined for this instance.

getCount() public method

public getCount ( $objFilter )

getDatabase() protected method

Retrieve the database instance to use.
protected getDatabase ( ) : Database
return Contao\Database

getEmptyFilter() public method

public getEmptyFilter ( )

getFallbackLanguage() public method

public getFallbackLanguage ( )

getIdsFromFilter() public method

public getIdsFromFilter ( $objFilter, $strSortBy = '', $intOffset, $intLimit, $strSortOrder = 'ASC' )

getInVariantAttributes() public method

getItemsWithId() protected method

This method is called to retrieve the data for certain items from the database.
protected getItemsWithId ( int[] $arrIds, string[] $arrAttrOnly = [] ) : MetaModels\IItems
$arrIds int[] The ids of the items to retrieve the order of ids is used for sorting of the return values.
$arrAttrOnly string[] Names of the attributes that shall be contained in the result, defaults to array() which means all attributes.
return MetaModels\IItems a collection of all matched items, sorted by the id list.

getMatchingIds() protected method

Narrow down the list of Ids that match the given filter.
protected getMatchingIds ( MetaModels\Filter\IFilter | null $objFilter ) : array
$objFilter MetaModels\Filter\IFilter | null The filter to search the matching ids for.
return array all matching Ids.

getName() public method

public getName ( )

getServiceContainer() public method

public getServiceContainer ( )

getSimpleAttributes() protected method

This method retrieves all simple attributes from the current MetaModel.
protected getSimpleAttributes ( ) : MetaModels\Attribute\ISimple[]
return MetaModels\Attribute\ISimple[] all simple attributes defined for this instance.

getTableName() public method

public getTableName ( )

getTranslatedAttributes() protected method

This method retrieves all translated attributes from the current MetaModel.
protected getTranslatedAttributes ( ) : MetaModels\Attribute\ITranslated[]
return MetaModels\Attribute\ITranslated[] all translated attributes defined for this instance.

getView() public method

public getView ( $intViewId )

hasAttribute() public method

public hasAttribute ( $strAttributeName )

hasVariants() public method

public hasVariants ( )

isComplexAttribute() protected method

Determine if the given attribute is a complex one.
protected isComplexAttribute ( MetaModels\Attribute\IAttribute $objAttribute ) : boolean
$objAttribute MetaModels\Attribute\IAttribute The attribute to test.
return boolean true if it is complex, false otherwise.

isSimpleAttribute() protected method

Determine if the given attribute is a simple one.
protected isSimpleAttribute ( MetaModels\Attribute\IAttribute $objAttribute ) : boolean
$objAttribute MetaModels\Attribute\IAttribute The attribute to test.
return boolean true if it is simple, false otherwise.

isTranslated() public method

public isTranslated ( )

isTranslatedAttribute() protected method

Determine if the given attribute is a translated one.
protected isTranslatedAttribute ( MetaModels\Attribute\IAttribute $objAttribute ) : boolean
$objAttribute MetaModels\Attribute\IAttribute The attribute to test.
return boolean true if it is translated, false otherwise.

prepareFilter() public method

public prepareFilter ( $intFilterSettings, $arrFilterUrl )

saveAttribute() protected method

Update an attribute for the given ids with the given data.
protected saveAttribute ( MetaModels\Attribute\IAttribute $objAttribute, array $arrIds, mixed $varData, string $strLangCode ) : void
$objAttribute MetaModels\Attribute\IAttribute The attribute to save.
$arrIds array The ids of the rows that shall be updated.
$varData mixed The data to save in raw data.
$strLangCode string The language code to save.
return void

saveItem() public method

public saveItem ( $objItem )

saveSimpleColumn() protected method

Update the value of a native column for the given ids with the given data.
protected saveSimpleColumn ( string $strColumn, array $arrIds, mixed $varData ) : void
$strColumn string The column name to update (i.e. tstamp).
$arrIds array The ids of the rows that shall be updated.
$varData mixed The data to save. If this is an array, it is automatically serialized.
return void

setServiceContainer() public method

Set the service container.
public setServiceContainer ( metamodels\IMetaModelsServiceContainer $serviceContainer ) : MetaModel
$serviceContainer metamodels\IMetaModelsServiceContainer The service container.
return MetaModel

tryUnserialize() protected method

Try to unserialize a value.
protected tryUnserialize ( string $value ) : mixed
$value string The string to process.
return mixed

updateVariants() protected method

Update the variants with the value if needed.
protected updateVariants ( metamodels\IItem $item, string $activeLanguage, int[] $allIds, boolean $baseAttributes = false ) : void
$item metamodels\IItem The item to save.
$activeLanguage string The language the values are in.
$allIds int[] The ids of all variants.
$baseAttributes boolean If also the base attributes get updated as well.
return void

Property Details

$arrAttributes protected property

Association is $colName => object
protected array $arrAttributes
return array

$arrData protected property

This is the data from tl_metamodel.
protected array $arrData
return array

$serviceContainer protected property

The service container.
protected IMetaModelsServiceContainer,metamodels $serviceContainer
return metamodels\IMetaModelsServiceContainer