1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ByTIC\Models\SmartProperties\RecordsTraits\HasSmartProperties; |
4
|
|
|
|
5
|
|
|
use ByTIC\Models\SmartProperties\Definitions\Builders\FolderBuilders; |
6
|
|
|
use ByTIC\Models\SmartProperties\Definitions\DefinitionRegistry; |
7
|
|
|
use ByTIC\Models\SmartProperties\Definitions\RepositoryDefinitions; |
8
|
|
|
use ByTIC\Models\SmartProperties\Properties\AbstractProperty\Generic as PropertyValue; |
9
|
|
|
use ByTIC\Models\SmartProperties\Definitions\Definition; |
10
|
|
|
use Exception; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class RecordsTrait |
14
|
|
|
* @package ByTIC\Models\SmartProperties\RecordsTraits\HasStatus |
15
|
|
|
*/ |
16
|
|
|
trait RecordsTrait |
17
|
|
|
{ |
18
|
|
|
use \ByTIC\Models\SmartProperties\RecordsTraits\AbstractTrait\RecordsTrait; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @return array |
22
|
2 |
|
*/ |
23
|
|
|
public function getSmartPropertiesDefinitions(): array |
24
|
2 |
|
{ |
25
|
|
|
return $this->getSmartPropertyDefinitionRegistry()->all(); |
26
|
2 |
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
18 |
|
* @param $name |
30
|
|
|
* @return PropertyValue[]|null |
31
|
18 |
|
* @throws Exception |
32
|
18 |
|
*/ |
33
|
|
|
public function getSmartPropertyItems($name) |
34
|
18 |
|
{ |
35
|
|
|
$definition = $this->getSmartPropertyDefinition($name); |
36
|
18 |
|
return $definition->getItems(); |
37
|
|
|
} |
38
|
18 |
|
|
39
|
18 |
|
/** |
40
|
18 |
|
* @param string $name |
41
|
|
|
* @return null|Definition |
42
|
|
|
*/ |
43
|
|
|
public function getSmartPropertyDefinition($name) |
44
|
|
|
{ |
45
|
|
|
return $this->getSmartPropertyDefinitionRegistry()->get($name); |
46
|
|
|
} |
47
|
2 |
|
|
48
|
|
|
/** |
49
|
2 |
|
* @param string $name |
50
|
2 |
|
* @return bool |
51
|
2 |
|
*/ |
52
|
|
|
public function hasSmartPropertyDefinition($name): bool |
53
|
|
|
{ |
54
|
|
|
return $this->getSmartPropertyDefinitionRegistry()->has($name); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param $name |
59
|
|
|
* @param $field |
60
|
16 |
|
* @return \ByTIC\Models\SmartProperties\Properties\AbstractProperty\Generic[]|null |
61
|
|
|
*/ |
62
|
16 |
|
public function getSmartPropertyValues($name, $field) |
63
|
16 |
|
{ |
64
|
|
|
$definition = $this->getSmartPropertyDefinition($name); |
65
|
|
|
return $definition->getValues($field); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param string $property |
70
|
|
|
* @param string $value |
71
|
|
|
* @return PropertyValue |
72
|
|
|
* @throws Exception |
73
|
16 |
|
*/ |
74
|
|
|
public function getSmartPropertyItem($property, $value) |
75
|
16 |
|
{ |
76
|
|
|
$definition = $this->getSmartPropertyDefinition($property); |
77
|
16 |
|
return $definition->getItem($value); |
78
|
16 |
|
} |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
abstract protected function registerSmartProperties(); |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param $field |
85
|
|
|
*/ |
86
|
|
|
protected function registerSmartProperty($field, $name = null) |
87
|
2 |
|
{ |
88
|
|
|
$definition = FolderBuilders::create($this, $field, $name); |
|
|
|
|
89
|
2 |
|
$this->addSmartPropertyDefinition($definition); |
90
|
2 |
|
} |
91
|
2 |
|
|
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param Definition $definition |
95
|
|
|
*/ |
96
|
|
|
protected function addSmartPropertyDefinition($definition) |
97
|
|
|
{ |
98
|
|
|
$this->getSmartPropertyDefinitionRegistry()->add($definition); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
10 |
|
* @return RepositoryDefinitions |
103
|
|
|
*/ |
104
|
10 |
|
protected function getSmartPropertyDefinitionRegistry(): RepositoryDefinitions |
105
|
10 |
|
{ |
106
|
10 |
|
return DefinitionRegistry::instance()->get($this, function () { |
107
|
|
|
$this->registerSmartProperties(); |
108
|
|
|
}); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|