PHP 클래스 FOF30\Model\DataModel\RelationManager

파일 보기 프로젝트 열기: akeeba/fof 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$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

공개 메소드들

메소드 설명
__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.

메소드 상세

__call() 공개 메소드

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

__clone() 공개 메소드

Implements deep cloning of the relation object
public __clone ( )

__construct() 공개 메소드

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() 공개 메소드

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
리턴 Collection

addRelation() 공개 메소드

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

getCountSubquery() 공개 메소드

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
리턴 JDatabaseQuery

getData() 공개 메소드

Gets the related items of a relation
또한 보기: 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
리턴 Collection | DataModel

getForeignKeyMap() 공개 메소드

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
리턴 array

getNew() 공개 메소드

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

getRelation() 공개 메소드

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

getRelationNames() 공개 메소드

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

getRelationTypes() 공개 정적인 메소드

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

isMagicMethod() 공개 메소드

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

isMagicProperty() 공개 메소드

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
리턴 boolean

rebase() 공개 메소드

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

removeRelation() 공개 메소드

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

resetRelationData() 공개 메소드

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() 공개 메소드

Removes all known relations
public resetRelations ( )

save() 공개 메소드

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

setDataFromCollection() 공개 메소드

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
리턴 void

프로퍼티 상세

$eager 보호되어 있는 프로퍼티

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

$parentModel 보호되어 있는 프로퍼티

The data model we are attached to
protected $parentModel

$relationTypes 보호되어 있는 정적으로 프로퍼티

The known relation types
protected static $relationTypes

$relations 보호되어 있는 프로퍼티

The relations known to us
protected $relations