-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathindex.php
176 lines (148 loc) · 4.4 KB
/
index.php
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
use Nepster\Matrix\Coord;
use Nepster\Matrix\Matrix;
use Nepster\Matrix\MatrixRender;
use Nepster\Matrix\MatrixManager;
use Nepster\Matrix\MatrixPositionManager;
include '../vendor/autoload.php';
$matrix = new Matrix(3, 2);
$matrixPositionManager = new MatrixPositionManager($matrix);
$matrix->addTenant(null, function (Coord $coord): array {
return [
'name' => 'Superman',
'avatar' => 'images/avatar-superman.jpg',
];
});
$matrix->addTenant(null, function (Coord $coord): array {
return [
'name' => 'Diana',
'avatar' => 'images/avatar-wonder-woman.jpg',
];
});
$matrix->addTenant(null, function (Coord $coord): array {
return [
'name' => 'The Flash',
'avatar' => 'images/avatar-flash.jpg',
];
});
$matrix->addTenant($matrixPositionManager->positionToCoord(6), function (Coord $coord): array {
return [
'name' => 'Batman',
'avatar' => 'images/avatar-batman.jpg',
];
});
// Matrix Render
$render = new MatrixRender($matrix);
$render->setOptions(['class' => 'matrix']);
$render->setDepthOptions(['class' => 'depth']);
$render->setGroupSeparatorOptions(['class' => 'matrix-group-separator']);
$render->setClearOptions(['style' => 'clear:both']);
$render->setGroupJoinOptions(['class' => 'matrix-join-group']);
$render->registerDepthCallback(function (Matrix $matrix, int $d, array $tenants): string {
return '<div class="depth-counter">Depth ' . (++$d) . '</div>';
});
$render->registerCellCallback(function (Matrix $matrix, Coord $coord, $tenant) use ($matrixPositionManager): string {
if ($tenant === null) {
return '<div class="cell">
' . $matrixPositionManager->coordToPosition($coord) . '
<div class="user">
<div class="avatar" style="background-image: url(images/free.jpg)"></div>
</div>
<div style="color: silver">free</div>
</div>';
}
return '<div class="cell">
' . $matrixPositionManager->coordToPosition($coord) . '
<div class="user">
<div class="avatar" style="background-image: url(' . $tenant['avatar'] . ')"></div>
<div class="matrix-user-info">
Extra info
</div>
</div>
<div class="user-name">' . $tenant['name'] . '</div>
</div>';
});
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>MLM Matrix</title>
<style type="text/css">
body {
font-family: Arial, Helvetica, sans-serif;
}
.matrix {
margin: auto;
font-size: 12px;
}
.matrix .depth {
width: 680px;
min-height: 20px;
margin: 20px auto;
text-align: center;
clear: both;
border: dashed 1px #D3D3D3;
}
.matrix .depth-counter {
margin-bottom: 10px;
display: block;
text-align: left;
font-weight: bold;
padding: 10px 5px 0 10px;
}
.matrix .user {
width: 45px;
height: 45px;
border: double 3px silver;
overflow: hidden;
margin: 5px auto;
}
.matrix .user .avatar {
width: 45px;
height: 45px;
background-size: cover;
overflow: hidden;
}
.matrix .user-name {
white-space: nowrap;
}
.matrix .cell {
width: 60px;
display: inline-block;
border: dashed 1px #D3D3D3;
margin: 10px 0;
padding: 5px 1px 5px 1px;
overflow: hidden;
text-align: center;
}
.matrix .matrix-join-group {
display: inline-block;
}
.matrix .matrix-group-separator {
width: 10px;
display: inline-block;
}
.matrix .matrix-user-info {
display: none
}
.matrix .user:hover .matrix-user-info {
display: block;
position: absolute;
width: 200px;
min-height: 30px;
border: double 3px silver;
background: #8BAA79;
padding: 10px;
margin-left: -3px;
margin-top: -3px;
color: white;
font-weight: bold;
letter-spacing: 1px;
}
</style>
</head>
<body>
<?= $render->show() ?>
</body>
</html>