|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Base daft objects. |
|
4
|
|
|
* |
|
5
|
|
|
* @author SignpostMarv |
|
6
|
|
|
*/ |
|
7
|
|
|
declare(strict_types=1); |
|
8
|
|
|
|
|
9
|
|
|
namespace SignpostMarv\DaftObject; |
|
10
|
|
|
|
|
11
|
|
|
abstract class DaftWriteableObjectMemoryTree extends DaftObjectMemoryTree implements DaftNestedWriteableObjectTree |
|
12
|
|
|
{ |
|
13
|
|
|
use TraitWriteableTree; |
|
14
|
|
|
|
|
15
|
112 |
|
public function RememberDaftObject(DefinesOwnIdPropertiesInterface $object) : void |
|
16
|
|
|
{ |
|
17
|
112 |
|
static::ThrowIfNotType($object, DaftNestedWriteableObject::class, 1, __METHOD__); |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var DaftNestedWriteableObject $object |
|
21
|
|
|
*/ |
|
22
|
112 |
|
$object = $object; |
|
23
|
|
|
|
|
24
|
112 |
|
$left = $object->GetIntNestedLeft(); |
|
25
|
112 |
|
$right = $object->GetIntNestedRight(); |
|
26
|
112 |
|
$level = $object->GetIntNestedLevel(); |
|
27
|
|
|
|
|
28
|
112 |
|
if (0 === $left && 0 === $right && 0 === $level) { |
|
29
|
110 |
|
if ($this->CountDaftNestedObjectFullTree() > 0) { |
|
30
|
84 |
|
$tree = $this->RecallDaftNestedObjectFullTree(); |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var DaftNestedWriteableObject $end |
|
34
|
|
|
*/ |
|
35
|
84 |
|
$end = end($tree); |
|
36
|
|
|
|
|
37
|
84 |
|
$left = $end->GetIntNestedRight() + 1; |
|
38
|
|
|
} else { |
|
39
|
110 |
|
$left = $this->CountDaftNestedObjectFullTree() * 2; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
110 |
|
$object->SetIntNestedLeft($left); |
|
43
|
110 |
|
$object->SetIntNestedRight($left + 1); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
112 |
|
parent::RememberDaftObject($object); |
|
47
|
112 |
|
} |
|
48
|
|
|
|
|
49
|
112 |
|
protected function RememberDaftObjectData(DefinesOwnIdPropertiesInterface $object) : void |
|
50
|
|
|
{ |
|
51
|
112 |
|
static::ThrowIfNotType($object, DaftNestedWriteableObject::class, 1, __METHOD__); |
|
52
|
|
|
|
|
53
|
112 |
|
parent::RememberDaftObjectData($object); |
|
54
|
112 |
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param DaftObject|string $object |
|
58
|
|
|
*/ |
|
59
|
114 |
|
protected static function ThrowIfNotType( |
|
60
|
|
|
$object, |
|
61
|
|
|
string $type, |
|
62
|
|
|
int $argument, |
|
63
|
|
|
string $function |
|
64
|
|
|
) : void { |
|
65
|
114 |
|
if ( ! is_a($object, DaftNestedWriteableObject::class, is_string($object))) { |
|
66
|
2 |
|
throw new DaftObjectRepositoryTypeByClassMethodAndTypeException( |
|
67
|
2 |
|
$argument, |
|
68
|
2 |
|
static::class, |
|
69
|
2 |
|
$function, |
|
70
|
2 |
|
DaftNestedWriteableObject::class, |
|
71
|
2 |
|
is_string($object) ? $object : get_class($object) |
|
72
|
|
|
); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
112 |
|
parent::ThrowIfNotType($object, $type, $argument, $function); |
|
76
|
112 |
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|