097af20428fad5dc2e63301e120c59aa3fd50f7f
1 <?php
declare(strict_types
=1);
3 require_once('common.php');
5 function tabs($id, $headings, $contents, $activeHeading = null
, $justify = false
) {
6 $slug = function($string) {
7 return str_replace(' ', '', $string);
10 $heading = function($heading, $tabid, $active = false
) {
11 return '<li class="nav-item"><a class="nav-link' . ($active ?
' active' : '') . '" data-toggle="pill" href="#tab' . $tabid . '">' . $heading . '</a></li>';
14 $content = function($content, $id, $active = false
) {
15 return '<div class="container-fluid drivers-main tab-pane fade' . ($active ?
' active show' : '') . '" id="tab' . $id . '" role="tabpanel">' . $content . '</div>';
18 $headingAndContent = zipWith(function($heading, $content) {
19 return ['heading' => $heading, 'content' => $content];
20 }, $headings, $contents);
22 $smushenated = array_reduce($headingAndContent, function($c, $v) use ($slug, $heading, $content, $id, $activeHeading) {
24 'headings' => $c['headings'] . $heading($v['heading'], $id . $slug($v['heading']), $v['heading'] == $activeHeading),
25 'contents' => $c['contents'] . $content($v['content'], $id . $slug($v['heading']), $v['heading'] == $activeHeading)
27 }, ['headings' => '', 'contents' => '']);
29 return '<ul class="nav nav-pills' . ($justify ?
' justify-content-center' : '') . '">' . $smushenated['headings'] . '</ul><div class="tab-content">' . $smushenated['contents'] . '</div>';
32 function accordion($id, $headings, $contents, $activeHeading = null
) {
33 $slug = function($string) {
34 return str_replace(' ', '', strtolower($string));
37 $a = zipWith(function($heading, $content) use ($slug, $id, $activeHeading) {
39 '<div class="card">' .
40 '<div class="card-header">' .
41 '<a class="collapsed card-link" data-toggle="collapse" href="#' . $slug($heading) . $id . '">' . $heading . '</a>' .
43 '<div id="' . $slug($heading) . $id . '" class="collapse' . ($heading == $activeHeading ?
' show' : '') . '" data-parent="#accordion-' . $id . '">' .
44 '<div class="card-body">' .
49 }, $headings, $contents);
52 '<div id="accordion-' . $id .'">' .
57 function table($rows) {
59 '<table class="table table-striped"><tbody><tr>' .
60 glue('</tr><tr>')(map(function($row) {
61 return '<td>' . glue('</td><td>')($row) . '</td>';
63 '</tr></tbody></table>';
68 $years = array_reverse(range(2018, (int)(new DateTimeImmutable())->format('Y')));
69 $today = turnBackTime(new DateTimeImmutable
);
73 map(function($year) use ($today) {
76 map(∘
('strToUpper', getMonthName
))(range(1,12)),
77 map(function($month) use ($year, $today){
78 $mondays = range(1, count(getMondaysForMonth($year, $month)));
81 map(function($num) { return "Week $num"; })($mondays),
82 map(function($num) use ($month, $year) {
83 $completedTasksFile = getFilePathForWeek($year, $month, $num, PATH_TO_TASKS_FILES
);
84 $completedTasks = file_exists($completedTasksFile) ?
lines(trim(file_get_contents($completedTasksFile))) : [];
85 return table(map(function($task) use($completedTasks) { return [getString($task), in_array($task, $completedTasks) ?
'👍😄' : '👎😱']; })(getTasksForTheWeek($year, $month, $num, require 'taskMatrix.php')));
87 ($year == $today->year
&& $month == $today->month
) ?
'Week ' . $today->weekNum
: 'Week 1'
90 ($year == $today->year
) ?
strToUpper(getMonthName($today->month
)) : 'JANUARY'