|
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
|
|
|
abstract class AbstractArrayBackedDaftNestedObject extends AbstractArrayBackedDaftObject implements DaftNestedObject |
|
12
|
|
|
{ |
|
13
|
|
|
public function GetIntNestedLeft() : int |
|
14
|
|
|
{ |
|
15
|
|
|
return (int) ($this->RetrievePropertyValueFromData('intNestedLeft') ?? null); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
public function GetIntNestedRight() : int |
|
19
|
|
|
{ |
|
20
|
|
|
return (int) ($this->RetrievePropertyValueFromData('intNestedRight') ?? null); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function GetIntNestedLevel() : int |
|
24
|
|
|
{ |
|
25
|
|
|
return (int) ($this->RetrievePropertyValueFromData('intNestedLevel') ?? null); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function GetIntNestedSortOrder() : int |
|
29
|
|
|
{ |
|
30
|
|
|
return (int) ($this->RetrievePropertyValueFromData('intNestedSortOrder') ?? null); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function ObtainDaftNestedObjectParentId() : array |
|
34
|
|
|
{ |
|
35
|
|
|
/** |
|
36
|
|
|
* @var string[] |
|
37
|
|
|
*/ |
|
38
|
|
|
$idProps = static::DaftNestedObjectParentIdProperties(); |
|
39
|
|
|
|
|
40
|
|
|
return array_map( |
|
41
|
|
|
/** |
|
42
|
|
|
* @return mixed |
|
43
|
|
|
*/ |
|
44
|
|
|
function (string $prop) { |
|
45
|
|
|
return $this->$prop; |
|
46
|
|
|
}, |
|
47
|
|
|
$idProps |
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function SetIntNestedLeft(int $value) : void |
|
52
|
|
|
{ |
|
53
|
|
|
if ( ! is_a(static::class, DaftNestedWriteableObject::class, true)) { |
|
54
|
|
|
throw new ClassDoesNotImplementClassException( |
|
55
|
|
|
static::class, |
|
56
|
|
|
DaftNestedWriteableObject::class |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
$this->NudgePropertyValue('intNestedLeft', $value); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function SetIntNestedRight(int $value) : void |
|
64
|
|
|
{ |
|
65
|
|
|
if ( ! is_a(static::class, DaftNestedWriteableObject::class, true)) { |
|
66
|
|
|
throw new ClassDoesNotImplementClassException( |
|
67
|
|
|
static::class, |
|
68
|
|
|
DaftNestedWriteableObject::class |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
$this->NudgePropertyValue('intNestedRight', $value); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function SetIntNestedLevel(int $value) : void |
|
76
|
|
|
{ |
|
77
|
|
|
if ( ! is_a(static::class, DaftNestedWriteableObject::class, true)) { |
|
78
|
|
|
throw new ClassDoesNotImplementClassException( |
|
79
|
|
|
static::class, |
|
80
|
|
|
DaftNestedWriteableObject::class |
|
81
|
|
|
); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
$this->NudgePropertyValue('intNestedLevel', $value); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function SetIntNestedSortOrder(int $value) : void |
|
88
|
|
|
{ |
|
89
|
|
|
if ( ! is_a(static::class, DaftNestedWriteableObject::class, true)) { |
|
90
|
|
|
throw new ClassDoesNotImplementClassException( |
|
91
|
|
|
static::class, |
|
92
|
|
|
DaftNestedWriteableObject::class |
|
93
|
|
|
); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
$this->NudgePropertyValue('intNestedSortOrder', $value); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @param mixed $value |
|
101
|
|
|
*/ |
|
102
|
|
|
public function AlterDaftNestedObjectParentId($value) : void |
|
103
|
|
|
{ |
|
104
|
|
|
if ( ! is_a(static::class, DaftNestedWriteableObject::class, true)) { |
|
105
|
|
|
throw new ClassDoesNotImplementClassException( |
|
106
|
|
|
static::class, |
|
107
|
|
|
DaftNestedWriteableObject::class |
|
108
|
|
|
); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @var string[] $props |
|
113
|
|
|
*/ |
|
114
|
|
|
$props = static::DaftNestedObjectParentIdProperties(); |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @var scalar $val |
|
118
|
|
|
*/ |
|
119
|
|
|
foreach (array_combine($props, (is_array($value) ? $value : [$value])) as $prop => $val) { |
|
120
|
|
|
$this->NudgePropertyValue($prop, $val); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public function ChangedProperties() : array |
|
125
|
|
|
{ |
|
126
|
|
|
$out = parent::ChangedProperties(); |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @var string $prop |
|
130
|
|
|
*/ |
|
131
|
|
|
foreach (static::DaftNestedObjectParentIdProperties() as $prop) { |
|
132
|
|
|
if (in_array($prop, $out, true)) { |
|
133
|
|
|
$out[] = 'daftNestedObjectParentId'; |
|
134
|
|
|
|
|
135
|
|
|
break; |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
return $out; |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
|