PHP Class FOF30\Model\DataModel\RelationManager

Afficher le fichier Open project: akeeba/fof Class Usage Examples

Protected Properties

Свойство Type Description
$eager A list of the names of eager loaded relations
$parentModel The data model we are attached to
$relationTypes The known relation types
$relations The relations known to us

Méthodes publiques

Méthode Description
__call ( string $name, array $arguments ) : DataModel A magic method which allows us to define relations using shorthand notation, e.g. $manager->hasOne('phone') instead of $manager->addRelation('phone', 'hasOne')
__clone ( ) Implements deep cloning of the relation object
__construct ( DataModel $parentModel ) Creates a new relation manager for the defined parent model
__get ( $name ) : Collection Magic method to get the data of a relation using shorthand notation, e.g. $manager->phone instead of $manager->getData('phone')
addRelation ( string $name, string $type, string $foreignModelName = null, string $localKey = null, string $foreignKey = null, string $pivotTable = null, string $pivotLocalKey = null, string $pivotForeignKey = null ) : DataModel Adds a relation to the relation manager
getCountSubquery ( string $name, string $tableAlias = null ) : JDatabaseQuery Returns the count sub-query for a relation, used for relation filters (whereHas in the DataModel).
getData ( string $name, callable $callback = null, Collection $dataCollection = null ) : Collection | DataModel Gets the related items of a relation
getForeignKeyMap ( string $name ) : array Gets the foreign key map of a many-to-many relation
getNew ( string $name ) : DataModel Get a new related item which satisfies relation $name and adds it to this relation's data list.
getRelation ( string $name ) : Relation Gets the related items of a relation
getRelationNames ( ) : array Returns a list of all known relations' names
getRelationTypes ( ) : array Populates the static map of relation type methods and relation handling classes
isMagicMethod ( string $name ) : boolean Is $name a magic-callable method?
isMagicProperty ( string $name ) : boolean Is $name a magic property? Corollary: returns true if a relation of this name is known to the relation manager.
rebase ( DataModel $parentModel ) Rebase a relation manager
removeRelation ( string $name ) : DataModel Removes a known relation
resetRelationData ( array $relationsToReset = [] ) Resets the data of all relations in this manager. This doesn't remove relations, just their data so that they get loaded again.
resetRelations ( ) Removes all known relations
save ( null | string $name = null ) : DataModel Saves all related items belonging to the specified relation or, if $name is null, all known relations which support saving.
setDataFromCollection ( string $name, Collection &$data, mixed $keyMap = null ) : void Populates the internal $this->data collection of a relation from the contents of the provided collection. This is used by DataModel to push the eager loaded data into each item's relation.

Method Details

__call() public méthode

You can also use it to get data of a relation using shorthand notation, e.g. $manager->getPhone($callback) instead of $manager->getData('phone', $callback);
public __call ( string $name, array $arguments ) : DataModel
$name string The magic method to call
$arguments array The arguments to the magic method
Résultat FOF30\Model\DataModel The parent model, for chaining

__clone() public méthode

Implements deep cloning of the relation object
public __clone ( )

__construct() public méthode

Creates a new relation manager for the defined parent model
public __construct ( DataModel $parentModel )
$parentModel FOF30\Model\DataModel The model we are attached to

__get() public méthode

Magic method to get the data of a relation using shorthand notation, e.g. $manager->phone instead of $manager->getData('phone')
public __get ( $name ) : Collection
$name
Résultat Collection

addRelation() public méthode

Adds a relation to the relation manager
public addRelation ( string $name, string $type, string $foreignModelName = null, string $localKey = null, string $foreignKey = null, string $pivotTable = null, string $pivotLocalKey = null, string $pivotForeignKey = null ) : DataModel
$name string The name of the relation as known to this relation manager, e.g. 'phone'
$type string The relation type, e.g. 'hasOne'
$foreignModelName string The name of the foreign key's model in the format "modelName@com_something"
$localKey string The local table key for this relation
$foreignKey string The foreign key for this relation
$pivotTable string For many-to-many relations, the pivot (glue) table
$pivotLocalKey string For many-to-many relations, the pivot table's column storing the local key
$pivotForeignKey string For many-to-many relations, the pivot table's column storing the foreign key
Résultat FOF30\Model\DataModel The parent model, for chaining

getCountSubquery() public méthode

Returns the count sub-query for a relation, used for relation filters (whereHas in the DataModel).
public getCountSubquery ( string $name, string $tableAlias = null ) : JDatabaseQuery
$name string The relation to get the sub-query for
$tableAlias string The alias to use for the local table
Résultat JDatabaseQuery

getData() public méthode

Gets the related items of a relation
See also: Relation::getData()
public getData ( string $name, callable $callback = null, Collection $dataCollection = null ) : Collection | DataModel
$name string The name of the relation to return data for
$callback callable A callback to customise the returned data
$dataCollection FOF30\Utils\Collection Used when fetching the data of an eager loaded relation
Résultat Collection | DataModel

getForeignKeyMap() public méthode

Gets the foreign key map of a many-to-many relation
public getForeignKeyMap ( string $name ) : array
$name string The name of the relation to return data for
Résultat array

getNew() public méthode

Get a new related item which satisfies relation $name and adds it to this relation's data list.
public getNew ( string $name ) : DataModel
$name string The relation based on which a new item is returned
Résultat FOF30\Model\DataModel

getRelation() public méthode

Gets the related items of a relation
public getRelation ( string $name ) : Relation
$name string The name of the relation to return data for
Résultat Relation

getRelationNames() public méthode

Returns a list of all known relations' names
public getRelationNames ( ) : array
Résultat array

getRelationTypes() public static méthode

Populates the static map of relation type methods and relation handling classes
public static getRelationTypes ( ) : array
Résultat array Key = method name, Value = relation handling class

isMagicMethod() public méthode

Is $name a magic-callable method?
public isMagicMethod ( string $name ) : boolean
$name string The name of a potential magic-callable method
Résultat boolean

isMagicProperty() public méthode

Is $name a magic property? Corollary: returns true if a relation of this name is known to the relation manager.
public isMagicProperty ( string $name ) : boolean
$name string The name of a potential magic property
Résultat boolean

rebase() public méthode

Rebase a relation manager
public rebase ( DataModel $parentModel )
$parentModel FOF30\Model\DataModel

removeRelation() public méthode

Removes a known relation
public removeRelation ( string $name ) : DataModel
$name string The name of the relation to remove
Résultat FOF30\Model\DataModel The parent model, for chaining

resetRelationData() public méthode

Resets the data of all relations in this manager. This doesn't remove relations, just their data so that they get loaded again.
public resetRelationData ( array $relationsToReset = [] )
$relationsToReset array The names of the relations to reset. Pass an empty array (default) to reset all relations.

resetRelations() public méthode

Removes all known relations
public resetRelations ( )

save() public méthode

Saves all related items belonging to the specified relation or, if $name is null, all known relations which support saving.
public save ( null | string $name = null ) : DataModel
$name null | string The relation to save, or null to save all known relations
Résultat FOF30\Model\DataModel The parent model, for chaining

setDataFromCollection() public méthode

Populates the internal $this->data collection of a relation from the contents of the provided collection. This is used by DataModel to push the eager loaded data into each item's relation.
public setDataFromCollection ( string $name, Collection &$data, mixed $keyMap = null ) : void
$name string Relation name
$data Collection The relation data to push into this relation
$keyMap mixed Used by many-to-many relations to pass around the local to foreign key map
Résultat void

Property Details

$eager protected_oe property

A list of the names of eager loaded relations
protected $eager

$parentModel protected_oe property

The data model we are attached to
protected $parentModel

$relationTypes protected_oe static_oe property

The known relation types
protected static $relationTypes

$relations protected_oe property

The relations known to us
protected $relations