|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace kalanis\kw_pedigree\Storage\File; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use kalanis\kw_mapper\Search\Search; |
|
7
|
|
|
use kalanis\kw_pedigree\PedigreeException; |
|
8
|
|
|
use kalanis\kw_pedigree\Storage\AEntryAdapter; |
|
9
|
|
|
use kalanis\kw_pedigree\Storage\APedigreeRecord; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class EntryAdapter |
|
14
|
|
|
* @package kalanis\kw_pedigree\Storage\File |
|
15
|
|
|
*/ |
|
16
|
|
|
class EntryAdapter extends AEntryAdapter |
|
17
|
|
|
{ |
|
18
|
1 |
|
public function getChildren(): array |
|
19
|
|
|
{ |
|
20
|
1 |
|
$search1 = new Search($this->getClearRecord()); |
|
21
|
1 |
|
$search1->exact('motherId', strval($this->getLoadedRecord()->id)); |
|
22
|
|
|
|
|
23
|
1 |
|
$search2 = new Search($this->getClearRecord()); |
|
24
|
1 |
|
$search2->exact('fatherId', strval($this->getLoadedRecord()->id)); |
|
25
|
|
|
|
|
26
|
|
|
// Files cannot use OR in their searches |
|
27
|
1 |
|
return $search1->getResults() + $search2->getResults(); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
1 |
|
public function setFatherId(?int $fatherId): ?bool |
|
31
|
|
|
{ |
|
32
|
1 |
|
if ($this->getLoadedRecord()->fatherId != $fatherId) { |
|
|
|
|
|
|
33
|
1 |
|
$this->getLoadedRecord()->fatherId = strval($fatherId); |
|
|
|
|
|
|
34
|
1 |
|
return true; |
|
35
|
|
|
} |
|
36
|
1 |
|
return null; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
1 |
|
public function getFatherId(): ?int |
|
40
|
|
|
{ |
|
41
|
1 |
|
$data = $this->getLoadedRecord()->fatherId; |
|
|
|
|
|
|
42
|
1 |
|
return !empty($data) ? intval($data) : null; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
1 |
|
public function setMotherId(?int $motherId): ?bool |
|
46
|
|
|
{ |
|
47
|
1 |
|
if ($this->getLoadedRecord()->motherId != $motherId) { |
|
|
|
|
|
|
48
|
1 |
|
$this->getLoadedRecord()->motherId = strval($motherId); |
|
|
|
|
|
|
49
|
1 |
|
return true; |
|
50
|
|
|
} |
|
51
|
1 |
|
return null; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
1 |
|
public function getMotherId(): ?int |
|
55
|
|
|
{ |
|
56
|
1 |
|
$data = $this->getLoadedRecord()->motherId; |
|
|
|
|
|
|
57
|
1 |
|
return !empty($data) ? intval($data) : null; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @throws PedigreeException |
|
62
|
|
|
* @return PedigreeRecord |
|
63
|
|
|
*/ |
|
64
|
9 |
|
public function getLoadedRecord(): APedigreeRecord |
|
65
|
|
|
{ |
|
66
|
9 |
|
return parent::getLoadedRecord(); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Unhook the original class, use only its definition and create new clear copy |
|
71
|
|
|
* @throws PedigreeException |
|
72
|
|
|
* @return APedigreeRecord |
|
73
|
|
|
*/ |
|
74
|
1 |
|
protected function getClearRecord(): APedigreeRecord |
|
75
|
|
|
{ |
|
76
|
1 |
|
$record = get_class($this->getLoadedRecord()); |
|
77
|
1 |
|
return new $record(); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|