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
Afficher le fichier Open project: metamodels/core Class Usage Examples

Protected Properties

Свойство Type Description
$arrAttributes array Association is $colName => object
$arrData array This is the data from tl_metamodel.
$serviceContainer metamodels\IMetaModelsServiceContainer The service container.

Méthodes publiques

Méthode 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.

Méthodes protégées

Méthode 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 méthode

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 méthode

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

buildDatabaseParameterList() protected méthode

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

convertRowsToResult() protected méthode

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.
Résultat array

copyFilter() protected méthode

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.
Résultat MetaModels\Filter\IFilter the cloned filter.

createNewItem() protected méthode

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

delete() public méthode

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

fetchAdditionalAttributes() protected méthode

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.
Résultat array an array of all matched items, sorted by the id list.

fetchRows() protected méthode

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.
Résultat array an array containing the database rows with each column "deserialized".

fetchTranslatedAttributeValues() protected méthode

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.
Résultat array an array of all matched items, sorted by the id list.

findByFilter() public méthode

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

findById() public méthode

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

findVariantBase() public méthode

public findVariantBase ( $objFilter )

findVariants() public méthode

public findVariants ( $arrIds, $objFilter )

findVariantsWithBase() public méthode

public findVariantsWithBase ( $arrIds, $objFilter )

get() public méthode

public get ( $strKey )

getActiveLanguage() public méthode

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

getAttribute() public méthode

public getAttribute ( $strAttributeName )

getAttributeById() public méthode

public getAttributeById ( $intId )

getAttributeByNames() protected méthode

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.
Résultat MetaModels\Attribute\IAttribute[]

getAttributeImplementing() protected méthode

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

getAttributeOptions() public méthode

public getAttributeOptions ( $strAttribute, $objFilter = null )

getAttributes() public méthode

public getAttributes ( )

getAvailableLanguages() public méthode

getComplexAttributes() protected méthode

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

getCount() public méthode

public getCount ( $objFilter )

getDatabase() protected méthode

Retrieve the database instance to use.
protected getDatabase ( ) : Database
Résultat Contao\Database

getEmptyFilter() public méthode

public getEmptyFilter ( )

getFallbackLanguage() public méthode

public getFallbackLanguage ( )

getIdsFromFilter() public méthode

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

getInVariantAttributes() public méthode

getItemsWithId() protected méthode

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.
Résultat MetaModels\IItems a collection of all matched items, sorted by the id list.

getMatchingIds() protected méthode

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.
Résultat array all matching Ids.

getName() public méthode

public getName ( )

getServiceContainer() public méthode

public getServiceContainer ( )

getSimpleAttributes() protected méthode

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

getTableName() public méthode

public getTableName ( )

getTranslatedAttributes() protected méthode

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

getView() public méthode

public getView ( $intViewId )

hasAttribute() public méthode

public hasAttribute ( $strAttributeName )

hasVariants() public méthode

public hasVariants ( )

isComplexAttribute() protected méthode

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

isSimpleAttribute() protected méthode

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

isTranslated() public méthode

public isTranslated ( )

isTranslatedAttribute() protected méthode

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

prepareFilter() public méthode

public prepareFilter ( $intFilterSettings, $arrFilterUrl )

saveAttribute() protected méthode

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.
Résultat void

saveItem() public méthode

public saveItem ( $objItem )

saveSimpleColumn() protected méthode

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.
Résultat void

setServiceContainer() public méthode

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

tryUnserialize() protected méthode

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

updateVariants() protected méthode

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.
Résultat void

Property Details

$arrAttributes protected_oe property

Association is $colName => object
protected array $arrAttributes
Résultat array

$arrData protected_oe property

This is the data from tl_metamodel.
protected array $arrData
Résultat array

$serviceContainer protected_oe property

The service container.
protected IMetaModelsServiceContainer,metamodels $serviceContainer
Résultat metamodels\IMetaModelsServiceContainer