Documentation

MySQLJunctionPropertyService extends AbstractOneManyPropertyService

Contains some of the base programming for a property service backed by a single repository and an array property full of IModel instances.

Links to the target models are based on a junction table.

ie:

Parent model table id - primary key

Target model table id - Primary key

junction model table id - primary key link_parent - id of parent model link_target - id of target model

id is added to the junction table simply to make things easier. The primary key should be compound key (link_parent,link_target) with an additional index on id.

===================================================================

Target model edits are saved unless in read only mode.

Table of Contents

$junctionRepo Junction model repository ISQLRepository
$targetRepo Target model repository type
$jCols Junction model properties IJunctionModelProperties
$tCols Target model properties IJunctionTargetProperties
$readOnly If the target is read only bool
$propCfg Property config for the service IPropertySvcConfig
$lastId Last id from getValue() int
$init
__construct() Create a new property service mixed
getSaveFunction() Junction provider save function IRunnable
loadModels() Load models \buffalokiwi\magicgraph\IModel[]
loadModels() Loads the models from some source array
__construct() Create a new property service mixed
getModelServiceConfig() Get the property config for the main property set IPropertySvcConfig
getSaveFunction() Retrieve the save function used for saving stuff from the provider. IRunnable
getValue() Retrieve the value of some property mixed
setValue() Sets the value of some property void
validate() Test to see if this model is valid prior to save() void
init() Initialize the model. void
getPropertyConfig() Get the property config for the main property set IPropertyConfig
callLoadModels() array
hasAllPriKeyValues() Test to see if some model has values for all primary keys bool

Properties

Methods

__construct()

Create a new property service

public __construct( $cfg : IPropertySvcConfig , $junctionRepo : ISQLRepository , $targetRepo : ISQLRepository [, $junctionIntf : string = IJunctionModelProperties::class ] [, $targetIntf : string = IJunctionTargetProperties::class ] [, $readOnlyTarget : bool = false ] ) : mixed
Parameters
$cfg : IPropertySvcConfig

Property service config

$junctionRepo : ISQLRepository

Junction table repository

$targetRepo : ISQLRepository

Target model repository

$junctionIntf : string = IJunctionModelProperties::class

Junction model property definitions interface

$targetIntf : string = IJunctionTargetProperties::class

Target model property definitions interface

$readOnlyTarget : bool = false
Tags
throws
InvalidArgumentException
Return values
mixed

getSaveFunction()

Junction provider save function

public getSaveFunction( $parent : IModel ) : IRunnable

STEPS:

Save relationships to the junction repo. Requires: parent id target id

pull all relationships from the junction repo matching parent id. Create a list containing the records that exist in the db, but not in the supplied list. Remove them. Save the junction repo models.

============================= Save target edits. Requires: Full target model

Parameters
$parent : IModel
Return values
IRunnable

loadModels()

Load models

protected loadModels( $parentId : int ) : \buffalokiwi\magicgraph\IModel[]
Parameters
$parentId : int

Parent id

Return values
\buffalokiwi\magicgraph\IModel[]

models

loadModels()

Loads the models from some source

protected abstract loadModels( $parentId : int ) : array
Parameters
$parentId : int
Return values
array

getValue()

Retrieve the value of some property

public getValue( $model : IModel , $value : mixed [, $context : array = [] ] ) : mixed
Parameters
$model : IModel
$value : mixed
$context : array = []
Tags
throws
InvalidArgumentException

if the property is invalid

Return values
mixed

value

setValue()

Sets the value of some property

public setValue( $model : IModel , $value : mixed ) : void
Parameters
$model : IModel
$value : mixed

property value

Tags
throws
InvalidArgumentException

if the property is invalid

Search results