-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
104 lines (93 loc) · 2.49 KB
/
index.php
File metadata and controls
104 lines (93 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
require __DIR__ . '/vendor/autoload.php';
use UserHierarchy\InMemoryCollection\RoleCollection;
use UserHierarchy\InMemoryCollection\UserCollection;
use UserHierarchy\Repository\RoleRepository;
use UserHierarchy\Repository\UserRepository;
use UserHierarchy\Services\Tree\ExternalPackageAdaptor;
use UserHierarchy\Services\Tree\RecursiveTreeAdaptor;
$roles = [
[
'Id' => 1,
'Name' => 'System Administrator',
'Parent' => 0
],
[
'Id' => 2,
'Name' => 'Location Manager',
'Parent' => 1,
],
[
'Id' => 3,
'Name' => 'Supervisor',
'Parent' => 2,
],
[
'Id' => 4,
'Name' => 'Employee',
'Parent' => 3,
],
[
'Id' => 5,
'Name' => 'Trainer',
'Parent' => 3,
]
];
$users = [
[
'Id' => 1,
'Name' => 'Adam Admin',
'Role' => 1
],
[
'Id' => 2,
'Name' => 'Emily Employee',
'Role' => 4
],
[
'Id' => 3,
'Name' => 'Sam Supervisor',
'Role' => 3
],
[
'Id' => 4,
'Name' => 'Mary Manager',
'Role' => 2,
],
[
'Id' => 5,
'Name' => 'Steve Trainer',
'Role' => 5
]
];
// Add Roles
$roleRepository = new RoleRepository(new RoleCollection);
$roleRepository->saveAll($roles);
// Add Users
$userRepository = new UserRepository(new UserCollection);
$userRepository->saveAll($users);
$tree = new RecursiveTreeAdaptor($roleRepository->getAll());
$subordinates = $userRepository->getSubOrdinates($tree, 1);
echo 'Adam Admin`s subordinates: <br>';
echo $subordinates->toJson();
echo "<br><br>";
$tree = new RecursiveTreeAdaptor($roleRepository->getAll());
$subordinates = $userRepository->getSubOrdinates($tree, 2);
echo 'Emily Employee`s subordinates: <br />';
echo $subordinates->toJson();
echo "<br><br>";
$tree = new RecursiveTreeAdaptor($roleRepository->getAll());
$subordinates = $userRepository->getSubOrdinates($tree, 3);
echo 'Sam Supervisor`s subordinates: <br />';
echo $subordinates->toJson();
echo "<br><br>";
$tree = new ExternalPackageAdaptor($roleRepository->getAll());
$subordinates = $userRepository->getSubOrdinates($tree, 4);
echo 'Mary Manager`s subordinates: <br />';
echo $subordinates->toJson();
echo "<br><br>";
$tree = new ExternalPackageAdaptor($roleRepository->getAll());
$subordinates = $userRepository->getSubOrdinates($tree, 5);
echo 'Steve Trainees`s subordinates: <br />';
echo $subordinates->toJson();
echo "<br><br>";