blob: 59aa50e4478d600c71abb5339ec5b247011eb2cd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
<?php
namespace Lti;
use SimpleORMap;
/**
* @property int $id
* @property string $name
* @property string $value
* @property int $mkdate
* @property int $chdate
* @property int $configurable_id
* @property string $configurable_type
* @property Registration | Publication | ResourceLink $configurable
*/
class Config extends SimpleORMap
{
protected static function configure($config = [])
{
$config['db_table'] = 'lti_configs';
$config['additional_fields']['configurable'] = [
'set' => 'setConfigurable',
'get' => 'getConfigurable'
];
parent::configure($config);
}
public function setConfigurable(Registration | Publication | ResourceLink $configurable): self
{
$configurables = [
Registration::class => 'registration',
Publication::class => 'publication',
ResourceLink::class => 'resource_link'
];
$this->configurable_type = $configurables[$configurable::class] ?? null;
$this->configurable_id = $configurable->id;
return $this;
}
public function getConfigurable(): Registration | Publication | ResourceLink
{
return match ($this->configurable_type) {
'registration' => Registration::find($this->configurable_id),
'publication' => Publication::find($this->configurable_id),
'resource_link' => ResourceLink::find($this->configurable_id),
default => null
};
}
}
|