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
$junctionRepo
Junction model repository
private
ISQLRepository
$junctionRepo
$targetRepo
Target model repository
private
type
$targetRepo
$jCols
Junction model properties
private
IJunctionModelProperties
$jCols
$tCols
Target model properties
private
IJunctionTargetProperties
$tCols
$readOnly
If the target is read only
private
bool
$readOnly
$propCfg
Property config for the service
private
IPropertySvcConfig
$propCfg
$lastId
Last id from getValue()
private
int
$lastId
= []
$init
private
mixed
$init
= []
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
Return values
mixedgetSaveFunction()
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
IRunnableloadModels()
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__construct()
Create a new property service
public
__construct(
$cfg :
IPropertyConfig
)
: mixed
Parameters
- $cfg : IPropertyConfig
Return values
mixedgetModelServiceConfig()
Get the property config for the main property set
public
getModelServiceConfig(
)
: IPropertySvcConfig
Return values
IPropertySvcConfig —config
getSaveFunction()
Retrieve the save function used for saving stuff from the provider.
public
getSaveFunction(
$parent :
IModel
)
: IRunnable
Parameters
- $parent : IModel
Return values
IRunnablegetValue()
Retrieve the value of some property
public
getValue(
$model :
IModel
, $value :
mixed
[, $context :
array
= [] ]
)
: mixed
Parameters
- $model : IModel
- $value : mixed
- $context : array = []
Tags
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
validate()
Test to see if this model is valid prior to save()
public
validate(
$model :
IModel
)
: void
Parameters
- $model : IModel
Tags
init()
Initialize the model.
public
init(
$model :
IModel
)
: void
Parameters
- $model : IModel
Model instance
getPropertyConfig()
Get the property config for the main property set
public
getPropertyConfig(
)
: IPropertyConfig
Return values
IPropertyConfig —config
callLoadModels()
private
callLoadModels(
$parentId :
int
)
: array
Parameters
- $parentId : int
Return values
arrayhasAllPriKeyValues()
Test to see if some model has values for all primary keys
private
hasAllPriKeyValues(
$model :
IModel
)
: bool
Parameters
- $model : IModel
Model
Return values
bool —has all keys