1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Base daft nested objects. |
4
|
|
|
* |
5
|
|
|
* @author SignpostMarv |
6
|
|
|
*/ |
7
|
|
|
declare(strict_types=1); |
8
|
|
|
|
9
|
|
|
namespace SignpostMarv\DaftObject; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @template T as AbstractArrayBackedDaftNestedObject |
13
|
|
|
* |
14
|
|
|
* @template-implements DaftNestedObject<T> |
15
|
|
|
* |
16
|
|
|
* @property-read int $intNestedLeft |
17
|
|
|
* @property-read int $intNestedRight |
18
|
|
|
* @property-read int $intNestedLevel |
19
|
|
|
* @property-read int $intNestedSortOrder |
20
|
|
|
*/ |
21
|
|
|
abstract class AbstractArrayBackedDaftNestedObject extends AbstractArrayBackedDaftObject implements DaftNestedObject |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @use TraitSortableDaftObject<T> |
25
|
|
|
*/ |
26
|
|
|
use TraitSortableDaftObject; |
27
|
|
|
|
28
|
|
|
const COUNT_EXPECT_NON_EMPTY = 0; |
29
|
|
|
|
30
|
|
|
const SORTABLE_PROPERTIES = [ |
31
|
|
|
'intNestedSortOrder', |
32
|
|
|
]; |
33
|
|
|
|
34
|
92 |
|
public function GetIntNestedLeft() : int |
35
|
|
|
{ |
36
|
92 |
|
return NestedTypeParanoia::ForceInt( |
37
|
92 |
|
$this->RetrievePropertyValueFromData('intNestedLeft') ?? null |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
92 |
|
public function GetIntNestedRight() : int |
42
|
|
|
{ |
43
|
92 |
|
return NestedTypeParanoia::ForceInt( |
44
|
92 |
|
$this->RetrievePropertyValueFromData('intNestedRight') ?? null |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
92 |
|
public function GetIntNestedLevel() : int |
49
|
|
|
{ |
50
|
92 |
|
return NestedTypeParanoia::ForceInt( |
51
|
92 |
|
$this->RetrievePropertyValueFromData('intNestedLevel') ?? null |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
|
55
|
92 |
|
public function GetIntNestedSortOrder() : int |
56
|
|
|
{ |
57
|
92 |
|
return NestedTypeParanoia::ForceInt( |
58
|
92 |
|
$this->RetrievePropertyValueFromData('intNestedSortOrder') ?? null |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
60 |
|
public function ObtainDaftNestedObjectParentId() : array |
63
|
|
|
{ |
64
|
|
|
/** |
65
|
|
|
* @var string[] |
66
|
|
|
*/ |
67
|
60 |
|
$idProps = static::DaftNestedObjectParentIdProperties(); |
68
|
|
|
|
69
|
60 |
|
return array_map( |
70
|
|
|
/** |
71
|
|
|
* @return scalar |
72
|
|
|
*/ |
73
|
|
|
function (string $prop) { |
74
|
|
|
/** |
75
|
|
|
* @var scalar |
76
|
|
|
*/ |
77
|
60 |
|
$out = $this->__get($prop); |
78
|
|
|
|
79
|
60 |
|
return $out; |
80
|
60 |
|
}, |
81
|
60 |
|
$idProps |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
|
85
|
2 |
|
public function ChangedProperties() : array |
86
|
|
|
{ |
87
|
2 |
|
$out = parent::ChangedProperties(); |
88
|
|
|
|
89
|
2 |
|
$props = array_filter( |
90
|
2 |
|
static::DaftNestedObjectParentIdProperties(), |
91
|
|
|
function (string $prop) use ($out) : bool { |
92
|
2 |
|
return in_array($prop, $out, true); |
93
|
2 |
|
} |
94
|
|
|
); |
95
|
|
|
|
96
|
2 |
|
if (count($props) > self::COUNT_EXPECT_NON_EMPTY) { |
97
|
2 |
|
$out[] = 'daftNestedObjectParentId'; |
98
|
|
|
} |
99
|
|
|
|
100
|
2 |
|
return $out; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|