PHP Class FOF30\Model\DataModel\RelationManager

Exibir arquivo Open project: akeeba/fof Class Usage Examples

Protected Properties

Property 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

Public Methods

Method 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 method

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
return FOF30\Model\DataModel The parent model, for chaining

__clone() public method

Implements deep cloning of the relation object
public __clone ( )

__construct() public method

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 method

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
return Collection

addRelation() public method

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
return FOF30\Model\DataModel The parent model, for chaining

getCountSubquery() public method

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
return JDatabaseQuery

getData() public method

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
return Collection | DataModel

getForeignKeyMap() public method

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
return array

getNew() public method

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
return FOF30\Model\DataModel

getRelation() public method

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

getRelationNames() public method

Returns a list of all known relations' names
public getRelationNames ( ) : array
return array

getRelationTypes() public static method

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

isMagicMethod() public method

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

isMagicProperty() public method

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
return boolean

rebase() public method

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

removeRelation() public method

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

resetRelationData() public method

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 method

Removes all known relations
public resetRelations ( )

save() public method

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
return FOF30\Model\DataModel The parent model, for chaining

setDataFromCollection() public method

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
return 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