PHP Class MetaModels\DcGeneral\Data\Driver

Inheritance: implements ContaoCommunityAlliance\DcGeneral\Data\MultiLanguageDataProviderInterface
Show file Open project: metamodels/core

Protected Properties

Property Type Description
$metaModel MetaModels\IMetaModel The MetaModel this DataContainer is working on.
$serviceContainer MetaModels\IMetaModelsServiceContainer The service container.
$strCurrentLanguage string The current active language.
$strTable string Name of current table.

Public Methods

Method Description
createVariant ( ContaoCommunityAlliance\DcGeneral\Data\ConfigInterface $objConfig ) : null | ContaoCommunityAlliance\DcGeneral\Data\ModelInterface Fetch a variant of a single record by id.
delete ( mixed $varItem ) : void Delete an item.
fetch ( ContaoCommunityAlliance\DcGeneral\Data\ConfigInterface $objConfig ) : null | ContaoCommunityAlliance\DcGeneral\Data\ModelInterface Fetch a single or first record by id or filter.
fetchAll ( ContaoCommunityAlliance\DcGeneral\Data\ConfigInterface $objConfig ) : ContaoCommunityAlliance\DcGeneral\Data\CollectionInterface Fetch all records (optional filtered, sorted and limited).
fieldExists ( string $strField ) : boolean Check if the attribute exists in the table and holds a value.
getActiveVersion ( mixed $mixID ) : void Return the active version from a record.
getCount ( ContaoCommunityAlliance\DcGeneral\Data\ConfigInterface $objConfig ) : integer Return the amount of total items (filtering may be used in the config).
getCurrentLanguage ( ) : string Get the current working language.
getEmptyCollection ( ) : ContaoCommunityAlliance\DcGeneral\Data\CollectionInterface Fetch an empty collection.
getEmptyConfig ( ) : ContaoCommunityAlliance\DcGeneral\Data\ConfigInterface Return empty config object.
getEmptyModel ( ) : ContaoCommunityAlliance\DcGeneral\Data\ModelInterface Fetch an empty single record (new item).
getFallbackLanguage ( $mixID )
getFilterOptions ( ContaoCommunityAlliance\DcGeneral\Data\ConfigInterface $objConfig ) : ContaoCommunityAlliance\DcGeneral\Data\FilterOptionCollectionInterface Retrieve all unique values for the given property.
getLanguages ( $mixID )
getVersion ( mixed $mixID, mixed $mixVersion ) : void Return a model based of the version information.
getVersions ( mixed $mixID, boolean $blnOnlyActive = false ) : ContaoCommunityAlliance\DcGeneral\Data\CollectionInterface Return a list with all versions for the model with the given Id.
isUniqueValue ( string $strField, mixed $varNew, integer $intId = null ) : boolean Determine if a given value is unique within the metamodel.
resetFallback ( string $strField ) : void Reset the fallback field.
sameModels ( ContaoCommunityAlliance\DcGeneral\Data\ModelInterface $objModel1, ContaoCommunityAlliance\DcGeneral\Data\ModelInterface $objModel2 ) : boolean Check if two models have the same values in all properties.
save ( ContaoCommunityAlliance\DcGeneral\Data\ModelInterface $objItem ) : ContaoCommunityAlliance\DcGeneral\Data\ModelInterface Save an item to the data provider.
saveEach ( ContaoCommunityAlliance\DcGeneral\Data\CollectionInterface $objItems ) : void Save a collection of items to the data provider.
saveVersion ( ContaoCommunityAlliance\DcGeneral\Data\ModelInterface $objModel, string $strUsername ) : void Save a new Version of a record.
setBaseConfig ( array $arrConfig ) : void Set base config with source and other necessary parameter.
setCurrentLanguage ( string $strLanguage ) : void Set the current working language for the whole data provider.
setVersionActive ( mixed $mixID, mixed $mixVersion ) : void Set a version as active.

Protected Methods

Method Description
extractSorting ( ContaoCommunityAlliance\DcGeneral\Data\ConfigInterface $config ) : array Extract the sorting from the given config.
getDatabase ( ) : Database Retrieve the Database.
getIdsFromFilter ( MetaModels\Filter\IFilter $filter, ContaoCommunityAlliance\DcGeneral\Data\ConfigInterface $config ) : string[] Fetch the ids via the given filter.
getItemsFromFilter ( MetaModels\Filter\IFilter $filter, ContaoCommunityAlliance\DcGeneral\Data\ConfigInterface $config ) : MetaModels\IItems | MetaModels\IItem[] Fetch the items via the given filter.
getMetaModel ( ) : MetaModels\IMetaModel Retrieve the MetaModel.
getServiceContainer ( ) : MetaModels\IMetaModelsServiceContainer Retrieve the service container.
prepareFilter ( ContaoCommunityAlliance\DcGeneral\Data\ConfigInterface $configuration ) : MetaModels\Filter\IFilter Prepare a filter and return it.
setLanguage ( string $language = '' ) : string Set a language as active language in Contao and return the previous language.

Method Details

createVariant() public method

Fetch a variant of a single record by id.
public createVariant ( ContaoCommunityAlliance\DcGeneral\Data\ConfigInterface $objConfig ) : null | ContaoCommunityAlliance\DcGeneral\Data\ModelInterface
$objConfig ContaoCommunityAlliance\DcGeneral\Data\ConfigInterface The config holding the id of the base model.
return null | ContaoCommunityAlliance\DcGeneral\Data\ModelInterface

delete() public method

The given value may be either integer, string or an instance of Model
public delete ( mixed $varItem ) : void
$varItem mixed Id or the model itself, to delete.
return void

extractSorting() protected method

Extract the sorting from the given config.
protected extractSorting ( ContaoCommunityAlliance\DcGeneral\Data\ConfigInterface $config ) : array
$config ContaoCommunityAlliance\DcGeneral\Data\ConfigInterface The configuration to be applied.
return array

fetch() public method

If the model shall be retrieved by id, use $objConfig->setId() to populate the config with an Id. If the model shall be retrieved by filter, use $objConfig->setFilter() to populate the config with a filter.
public fetch ( ContaoCommunityAlliance\DcGeneral\Data\ConfigInterface $objConfig ) : null | ContaoCommunityAlliance\DcGeneral\Data\ModelInterface
$objConfig ContaoCommunityAlliance\DcGeneral\Data\ConfigInterface The config to use.
return null | ContaoCommunityAlliance\DcGeneral\Data\ModelInterface

fetchAll() public method

Fetch all records (optional filtered, sorted and limited).
public fetchAll ( ContaoCommunityAlliance\DcGeneral\Data\ConfigInterface $objConfig ) : ContaoCommunityAlliance\DcGeneral\Data\CollectionInterface
$objConfig ContaoCommunityAlliance\DcGeneral\Data\ConfigInterface The configuration to be applied.
return ContaoCommunityAlliance\DcGeneral\Data\CollectionInterface

fieldExists() public method

Check if the attribute exists in the table and holds a value.
public fieldExists ( string $strField ) : boolean
$strField string The name of the attribute that shall be tested.
return boolean

getActiveVersion() public method

Return the active version from a record.
public getActiveVersion ( mixed $mixID ) : void
$mixID mixed The ID of the record.
return void

getCount() public method

Return the amount of total items (filtering may be used in the config).
public getCount ( ContaoCommunityAlliance\DcGeneral\Data\ConfigInterface $objConfig ) : integer
$objConfig ContaoCommunityAlliance\DcGeneral\Data\ConfigInterface The filter config options.
return integer

getCurrentLanguage() public method

Get the current working language.
public getCurrentLanguage ( ) : string
return string Short tag for the current working language like de or fr etc.

getDatabase() protected method

Retrieve the Database.
protected getDatabase ( ) : Database
return Contao\Database

getEmptyCollection() public method

Fetch an empty collection.
public getEmptyCollection ( ) : ContaoCommunityAlliance\DcGeneral\Data\CollectionInterface
return ContaoCommunityAlliance\DcGeneral\Data\CollectionInterface

getEmptyConfig() public method

Return empty config object.
public getEmptyConfig ( ) : ContaoCommunityAlliance\DcGeneral\Data\ConfigInterface
return ContaoCommunityAlliance\DcGeneral\Data\ConfigInterface

getEmptyModel() public method

Fetch an empty single record (new item).
public getEmptyModel ( ) : ContaoCommunityAlliance\DcGeneral\Data\ModelInterface
return ContaoCommunityAlliance\DcGeneral\Data\ModelInterface

getFallbackLanguage() public method

public getFallbackLanguage ( $mixID )

getFilterOptions() public method

The result set will be an array containing all unique values contained in the MetaModel for the defined attribute in the configuration. Note: this only re-ensembles really used values for at least one data set. The only information being interpreted from the passed config object is the first property to fetch and the filter definition.
public getFilterOptions ( ContaoCommunityAlliance\DcGeneral\Data\ConfigInterface $objConfig ) : ContaoCommunityAlliance\DcGeneral\Data\FilterOptionCollectionInterface
$objConfig ContaoCommunityAlliance\DcGeneral\Data\ConfigInterface The filter config options.
return ContaoCommunityAlliance\DcGeneral\Data\FilterOptionCollectionInterface

getIdsFromFilter() protected method

Fetch the ids via the given filter.
protected getIdsFromFilter ( MetaModels\Filter\IFilter $filter, ContaoCommunityAlliance\DcGeneral\Data\ConfigInterface $config ) : string[]
$filter MetaModels\Filter\IFilter The filter.
$config ContaoCommunityAlliance\DcGeneral\Data\ConfigInterface The configuration to be applied.
return string[]

getItemsFromFilter() protected method

Fetch the items via the given filter.
protected getItemsFromFilter ( MetaModels\Filter\IFilter $filter, ContaoCommunityAlliance\DcGeneral\Data\ConfigInterface $config ) : MetaModels\IItems | MetaModels\IItem[]
$filter MetaModels\Filter\IFilter The filter.
$config ContaoCommunityAlliance\DcGeneral\Data\ConfigInterface The configuration to be applied.
return MetaModels\IItems | MetaModels\IItem[] The collection of IItem instances that match the given filter.

getLanguages() public method

public getLanguages ( $mixID )

getMetaModel() protected method

Retrieve the MetaModel.
protected getMetaModel ( ) : MetaModels\IMetaModel
return MetaModels\IMetaModel

getServiceContainer() protected method

Retrieve the service container.
protected getServiceContainer ( ) : MetaModels\IMetaModelsServiceContainer
return MetaModels\IMetaModelsServiceContainer

getVersion() public method

Return a model based of the version information.
public getVersion ( mixed $mixID, mixed $mixVersion ) : void
$mixID mixed The ID of record.
$mixVersion mixed The ID of the version.
return void

getVersions() public method

Return a list with all versions for the model with the given Id.
public getVersions ( mixed $mixID, boolean $blnOnlyActive = false ) : ContaoCommunityAlliance\DcGeneral\Data\CollectionInterface
$mixID mixed The ID of the row.
$blnOnlyActive boolean If true, only active versions will get returned, if false all version will get returned.
return ContaoCommunityAlliance\DcGeneral\Data\CollectionInterface

isUniqueValue() public method

Determine if a given value is unique within the metamodel.
public isUniqueValue ( string $strField, mixed $varNew, integer $intId = null ) : boolean
$strField string The attribute name.
$varNew mixed The value that shall be checked.
$intId integer The (optional) id of the item currently in scope - pass null for new items.
return boolean True if the values is not yet contained within the table, false otherwise.

prepareFilter() protected method

Prepare a filter and return it.
protected prepareFilter ( ContaoCommunityAlliance\DcGeneral\Data\ConfigInterface $configuration ) : MetaModels\Filter\IFilter
$configuration ContaoCommunityAlliance\DcGeneral\Data\ConfigInterface The configuration.
return MetaModels\Filter\IFilter

resetFallback() public method

This clears the given property in all items in the data provider to an empty value.
public resetFallback ( string $strField ) : void
$strField string The field to reset.
return void

sameModels() public method

Check if two models have the same values in all properties.
public sameModels ( ContaoCommunityAlliance\DcGeneral\Data\ModelInterface $objModel1, ContaoCommunityAlliance\DcGeneral\Data\ModelInterface $objModel2 ) : boolean
$objModel1 ContaoCommunityAlliance\DcGeneral\Data\ModelInterface The first model to compare.
$objModel2 ContaoCommunityAlliance\DcGeneral\Data\ModelInterface The second model to compare.
return boolean True - If both models are same, false if not.

save() public method

If the item does not have an Id yet, the save operation will add it as a new row to the database and populate the Id of the model accordingly.
public save ( ContaoCommunityAlliance\DcGeneral\Data\ModelInterface $objItem ) : ContaoCommunityAlliance\DcGeneral\Data\ModelInterface
$objItem ContaoCommunityAlliance\DcGeneral\Data\ModelInterface The model to save back.
return ContaoCommunityAlliance\DcGeneral\Data\ModelInterface The passed model.

saveEach() public method

Save a collection of items to the data provider.
public saveEach ( ContaoCommunityAlliance\DcGeneral\Data\CollectionInterface $objItems ) : void
$objItems ContaoCommunityAlliance\DcGeneral\Data\CollectionInterface The collection containing all items to be saved.
return void

saveVersion() public method

Save a new Version of a record.
public saveVersion ( ContaoCommunityAlliance\DcGeneral\Data\ModelInterface $objModel, string $strUsername ) : void
$objModel ContaoCommunityAlliance\DcGeneral\Data\ModelInterface The model to be saved.
$strUsername string The username that creates the new version.
return void

setBaseConfig() public method

Set base config with source and other necessary parameter.
public setBaseConfig ( array $arrConfig ) : void
$arrConfig array The configuration to use.
return void

setCurrentLanguage() public method

Set the current working language for the whole data provider.
public setCurrentLanguage ( string $strLanguage ) : void
$strLanguage string The new language, use short tag "2 chars like de, fr etc.".
return void

setLanguage() protected method

Set a language as active language in Contao and return the previous language.
protected setLanguage ( string $language = '' ) : string
$language string The language to set (if any).
return string

setVersionActive() public method

Set a version as active.
public setVersionActive ( mixed $mixID, mixed $mixVersion ) : void
$mixID mixed The ID of record.
$mixVersion mixed The ID of the version.
return void

Property Details

$metaModel protected property

The MetaModel this DataContainer is working on.
protected IMetaModel,MetaModels $metaModel
return MetaModels\IMetaModel

$serviceContainer protected property

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

$strCurrentLanguage protected property

The current active language.
protected string $strCurrentLanguage
return string

$strTable protected property

Name of current table.
protected string $strTable
return string