vlw.se/public/work/timeline.php
Victor Westerlund 56cf142e0d refactor: major refactor, design overhaul and merge of Reflect API and Vegvisir sources into the same root (#23)
The PR is a huge refactor of all Reflect and Vegvisir code. I've merged the API and "Front-end" codebases together into the same root, this will allow for both Reflect and Vegvisir to use the same resources. Not only that, but I've also added proper database modeling with actual OOP inheritance for database tables.

Reviewed-on: https://codeberg.org/vlw/vlw.se/pulls/23
2025-02-05 04:49:23 +00:00

158 lines
No EOL
4.9 KiB
PHP

<?php
use VLW\Database\Models\Work\Timeline;
use const VLW\{
ICONS_DIR,
DEFAULT_BUTTON_ICON,
TIMELINE_PREVIEW_LIMIT_PARAM
};
require_once VV::root("src/Consts.php");
require_once VV::root("src/Database/Models/Work/Timeline.php");
$timeline = new class extends Timeline {
public function __construct() {}
public static function ordered(): array {
// Get timeline list limit from search param if set
$limit = array_key_exists(TIMELINE_PREVIEW_LIMIT_PARAM, $_GET) ? (int) $_GET[TIMELINE_PREVIEW_LIMIT_PARAM] : null;
$timeline = [];
foreach (parent::all() as $idx => $item) {
// Use year as the first dimension
if (!array_key_exists($item->year(), $timeline)) {
$timeline[$item->year()] = [];
}
// And month as the second dimension
if (!array_key_exists($item->month(), $timeline[$item->year()])) {
$timeline[$item->year()][$item->month()] = [];
}
// Lastly, day as the third dimension
if (!array_key_exists($item->day(), $timeline[$item->year()][$item->month()])) {
$timeline[$item->year()][$item->month()][$item->day()] = [];
}
// Append Work instance on Timeline object to the output array by year->month->day
$timeline[$item->year()][$item->month()][$item->day()][] = $item->work();
// Bail out here if we've reached the theshold for items to display
if ($limit && $idx === $limit) {
return $timeline;
}
}
return $timeline;
}
}
?>
<style><?= VV::css("public/assets/css/pages/work/timeline") ?></style>
<section class="git">
<?= VV::embed("public/assets/media/icons/codeberg.svg") ?>
<p>This timeline has most but not all of my FOSS software. If you want to see a list of all things I've created for the free software world, check out my repos on Codeberg or Forgejo.</p>
<div class="buttons">
<a href="https://codeberg.org/vlw"><button class="inline solid">
<p>Codeberg</p>
<?= VV::embed("public/assets/media/icons/chevron.svg") ?>
</button></a>
<a href="https://git.vlw.se"><button class="inline">
<p>Forgejo</p>
<?= VV::embed("public/assets/media/icons/chevron.svg") ?>
</button></a>
</div>
</section>
<section class="timeline">
<?php // Get year int from key and array of months for current year ?>
<?php foreach ($timeline::ordered() as $year => $months): ?>
<div class="year">
<div class="track">
<p><?= $year ?></p>
</div>
<div class="months">
<?php // Get month int from key and array of days for current month ?>
<?php foreach ($months as $month => $days): ?>
<div class="month">
<div class="track">
<?php // Append leading zero to month ?>
<p><?= sprintf("%02d", $month) ?></p>
</div>
<div class="days">
<?php // Get day int from key and array of items for current day ?>
<?php foreach ($days as $day => $items): ?>
<div class="day">
<div class="track">
<?php // Append leading zero to day ?>
<p><?= sprintf("%02d", $day) ?></p>
</div>
<div class="items">
<?php foreach ($items as $work): ?>
<div class="item">
<?php // List tags if available ?>
<?php if ($work->tags()): ?>
<div class="tags">
<?php foreach ($work->tags() as $tag): ?>
<p class="tag <?= $tag->label()->name ?>"><?= $tag->label()->name ?></p>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php if ($work->title()): ?>
<h2><?= $work->title() ?></h2>
<?php endif; ?>
<p><?= $work->summary() ?></p>
<div class="actions">
<?php if ($work->actions()): ?>
<?php foreach ($work->actions() as $action): ?>
<a href="<?= $action->href() ?? "/work/{$work->id}" ?>"><button class="inline <?= implode(" ", $action->classes()) ?>">
<?php if ($action->icon_prepended()): ?>
<?= VV::embed(ICONS_DIR . $action->icon_prepended()) ?>
<?php endif; ?>
<p><?= $action->display_text() ?></p>
<?php if ($action->icon_appended()): ?>
<?= VV::embed(ICONS_DIR . $action->icon_appended()) ?>
<?php else: ?>
<?= VV::embed(DEFAULT_BUTTON_ICON) ?>
<?php endif; ?>
</button></a>
<?php endforeach; ?>
<?php else: ?>
<a href="<?= "/work/{$work->id}" ?>"><button class="inline">
<p>read more</p>
<?= VV::embed(DEFAULT_BUTTON_ICON) ?>
</button></a>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<?php endforeach; ?>
</section>
<script><?= VV::js("assets/js/pages/work/timeline") ?></script>