Specify paths correctly
[GrooveNet.git] / bootstrap.php
1 <?php declare(strict_types=1);
2
3 require_once('common.php');
4 require_once(__DIR__ . '/config.php');
5
6 function tabs($id, $headings, $contents, $justify = false) {
7 $slug = function($string) {
8 return str_replace(' ', '', $string);
9 };
10
11 $heading = function($heading, $tabid, $active = false) {
12 return '<li class="nav-item"><a class="nav-link' . ($active ? ' active' : '') . '" data-toggle="pill" href="#tab' . $tabid . '">' . $heading . '</a></li>';
13 };
14
15 $content = function($content, $id, $active = false) {
16 return '<div class="container-fluid drivers-main tab-pane' . ($active ? ' active' : '') . '" id="tab' . $id . '" role="tabpanel">' . $content . '</div>';
17 };
18
19 $headingAndContent = zipWith(function($heading, $content) {
20 return ['heading' => $heading, 'content' => $content];
21 }, $headings, $contents);
22
23 $smushenated = array_reduce($headingAndContent, function($c, $v) use ($slug, $heading, $content, $id) {
24 return [
25 'headings' => $c['headings'] . $heading($v['heading'], $id . $slug($v['heading']), !$c['headings']),
26 'contents' => $c['contents'] . $content($v['content'], $id . $slug($v['heading']), !$c['contents'])
27 ];
28 }, ['headings' => '', 'contents' => '']);
29
30 return '<ul class="nav nav-pills' . ($justify ? ' justify-content-center' : '') . '">' . $smushenated['headings'] . '</ul><div class="tab-content">' . $smushenated['contents'] . '</div>';
31 }
32
33 function accordion($id, $headings, $contents) {
34 $slug = function($string) {
35 return str_replace(' ', '', strtolower($string));
36 };
37
38 $a = zipWith(function($heading, $content) use ($slug, $id) {
39 return
40 '<div class="card">' .
41 '<div class="card-header">' .
42 '<a class="collapsed card-link" data-toggle="collapse" href="#' . $slug($heading) . $id . '">' . $heading . '</a>' .
43 '</div>' .
44 '<div id="' . $slug($heading) . $id . '" class="collapse" data-parent="#accordion-' . $id . '">' .
45 '<div class="card-body">' .
46 $content .
47 '</div></div></div>';
48
49
50 }, $headings, $contents);
51
52 return
53 '<div id="accordion-' . $id .'">' .
54 glue('')($a) .
55 '</div>';
56 }
57
58 function table($headings, $rows) {
59 return
60 '<table class="table table-striped">'.
61 '<thead><tr><td>' . glue('</td><td>')($headings) . '</td></tr></thead>' .
62 '<tbody><tr>' .
63 glue('</tr><tr>')(map(function($row) {
64 return '<td>' . glue('</td><td>')($row) . '</td>';
65 })($rows)) .
66 '</tr></tbody></table>';
67 }
68
69 function scores() {
70 $c = lines(trim(file_get_contents(glob(PATH_TO_GROOVENET . '/songs.*.txt')[0])));
71 echo '<pre>';
72 print_r($c);
73 echo '</pre>';
74 }
75
76 function doIt() {
77 $scores = require 'test.php';
78 return accordion(
79 'folders',
80 ['Cam', 'Jayce'],
81 [
82 table(
83 ['Song', 'Difficulty', 'Pranker', 'Score'],
84 $scores['cam']
85 ),
86 table(
87 ['Song', 'Difficulty', 'Pranker', 'Score'],
88 $scores['jayce']
89 )
90 ]
91 );
92 }