|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Tree; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
|
6
|
|
|
use App\Individual; |
|
7
|
|
|
use App\Family; |
|
8
|
|
|
|
|
9
|
|
|
class TreeController extends Controller |
|
10
|
|
|
{ |
|
11
|
|
|
public function index(Individual $individual) |
|
12
|
|
|
{ |
|
13
|
|
|
return $individual->get(['individuals.id', 'individuals.first_name', 'individuals.last_name']); |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
public function links() |
|
17
|
|
|
{ |
|
18
|
|
|
return $individual = \DB::table('child_parent')->select(\DB::raw('child_id as sid'), (\DB::raw('parent_id as tid')))->get('sid', 'tid'); |
|
|
|
|
|
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Get fathers family |
|
23
|
|
|
* |
|
24
|
|
|
* @param Integer $father_id [Father ID] |
|
25
|
|
|
* @return Array | Json |
|
|
|
|
|
|
26
|
|
|
*/ |
|
27
|
|
|
public function pedigree($father_id = 1) |
|
28
|
|
|
{ |
|
29
|
|
|
$father = Family::with(['info','spouse'])->where('type_id','>=',1)->where('father_id',$father_id)->first(); |
|
30
|
|
|
$data = []; |
|
31
|
|
|
if($father){ |
|
32
|
|
|
$data[] = array( |
|
33
|
|
|
'name' => $father->info->getNameAttribute(), |
|
34
|
|
|
'class' => 'node', |
|
35
|
|
|
'textClass' => 'nodeText', |
|
36
|
|
|
'depthOffset' => 1, |
|
37
|
|
|
'marriages' => array( |
|
38
|
|
|
['spouse' => array( |
|
39
|
|
|
'name' => $father->spouse->getNameAttribute() |
|
40
|
|
|
), |
|
41
|
|
|
'children' => $father->info->children->map(function ($item) { |
|
42
|
|
|
return ['name' => $item['first_name'].' '.$item['last_name']]; |
|
43
|
|
|
})->all()], |
|
44
|
|
|
|
|
45
|
|
|
), |
|
46
|
|
|
'extra' => [] |
|
47
|
|
|
); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
return $data; |
|
52
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Get individuals with its children |
|
57
|
|
|
* |
|
58
|
|
|
* @param integer $parent_id [Parent ID / Father ID] |
|
59
|
|
|
* @param integer $nest [Set how many nested children] |
|
60
|
|
|
* @return Array | Json |
|
61
|
|
|
*/ |
|
62
|
|
|
public function show($parent_id = 1, $nest = 1){ |
|
63
|
|
|
$this->nest = 1; // initialize nesting to 1 |
|
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
$parents = Individual::where('is_active', 1)->where('id', $parent_id)->get(); |
|
66
|
|
|
|
|
67
|
|
|
$tree = $this->getChildren($parents, (int)$nest); |
|
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
return $tree; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Loop nested children |
|
75
|
|
|
* |
|
76
|
|
|
* |
|
77
|
|
|
* @param integer $parents [description] |
|
78
|
|
|
* @param integer $nest [description] |
|
79
|
|
|
* @param boolean $show [description] |
|
80
|
|
|
* @return array [description] |
|
81
|
|
|
*/ |
|
82
|
|
|
public function getChildren($parents = 1, $nest = 1, $show = true){ |
|
83
|
|
|
$data = []; |
|
84
|
|
|
if($this->nest <= $nest){ |
|
85
|
|
|
$this->nest++; |
|
86
|
|
|
|
|
87
|
|
|
foreach($parents as $key => $parent) |
|
|
|
|
|
|
88
|
|
|
{ |
|
89
|
|
|
if($show === true){ |
|
90
|
|
|
$data[] = [ |
|
91
|
|
|
'id' => $parent->id, |
|
92
|
|
|
'text' => $parent->getNameAttribute(), |
|
93
|
|
|
'children' => $this->getChildren($parent->children,$nest,$show) |
|
94
|
|
|
]; |
|
95
|
|
|
}else{ |
|
96
|
|
|
$data[] = [ |
|
97
|
|
|
'id' => $parent->id, |
|
98
|
|
|
'name' => $parent->getNameAttribute(), |
|
99
|
|
|
'children' => $this->getChildren($parent->children,$nest,$show) |
|
100
|
|
|
]; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
return $data; |
|
107
|
|
|
|
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Get individuals with its children |
|
112
|
|
|
* |
|
113
|
|
|
* @param integer $parent_id [Parent ID / Father ID] |
|
114
|
|
|
* @param integer $nest [Set how many nested children] |
|
115
|
|
|
* @return Array | Json |
|
116
|
|
|
*/ |
|
117
|
|
|
public function edge($parent_id = 1, $nest = 1){ |
|
118
|
|
|
$this->nest = 1; // initialize nesting to 1 |
|
|
|
|
|
|
119
|
|
|
|
|
120
|
|
|
$parents = Individual::where('is_active', 1)->where('id', $parent_id)->get(); |
|
121
|
|
|
|
|
122
|
|
|
$tree = $this->getChildren($parents, (int)$nest, false); |
|
|
|
|
|
|
123
|
|
|
|
|
124
|
|
|
return $tree; |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.