Commit 1b32883e authored by Administrator's avatar Administrator 💬

refacto: clean up a little

parent a23bebe1
...@@ -7,6 +7,7 @@ use Grav\Common\Plugin; ...@@ -7,6 +7,7 @@ use Grav\Common\Plugin;
use Grav\Common\Uri; use Grav\Common\Uri;
use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\Event;
/** /**
* Features: * Features:
* - /sync Cheap git-sync (did not knew about it at the time) * - /sync Cheap git-sync (did not knew about it at the time)
...@@ -222,6 +223,7 @@ class M3P2Plugin extends Plugin ...@@ -222,6 +223,7 @@ class M3P2Plugin extends Plugin
$uri = $this->grav['uri']; $uri = $this->grav['uri'];
// var_dump($uri); // best doc ftw // var_dump($uri); // best doc ftw
// GRAV's routing makes use hook 404 pages and do the URL match ourselves
if ("lessons" != $uri->paths(0)) { if ("lessons" != $uri->paths(0)) {
return; // perhaps not return; // perhaps not
} }
...@@ -247,8 +249,6 @@ class M3P2Plugin extends Plugin ...@@ -247,8 +249,6 @@ class M3P2Plugin extends Plugin
} }
foreach ($page_config->lessons as $lesson) { foreach ($page_config->lessons as $lesson) {
// print("Checking lesson".print_r($lesson, true)."<br>\n");
// if ($lesson_slug == $lesson) {
if ($lesson_slug == $lesson['slug']) { if ($lesson_slug == $lesson['slug']) {
return true; // yay, this page is part of the lesson return true; // yay, this page is part of the lesson
} }
...@@ -265,18 +265,21 @@ class M3P2Plugin extends Plugin ...@@ -265,18 +265,21 @@ class M3P2Plugin extends Plugin
$hb = $b->header(); $hb = $b->header();
$fdp = function ($lesson) use ($lesson_slug) { $fdp = function ($lesson) use ($lesson_slug) {
return $lesson["slug"] == $lesson_slug; return trim($lesson["slug"]) === $lesson_slug;
}; };
// We're assuming the config exists (it should) $mar = array_filter($ha->lessons, $fdp);
// NOOOOPE IT DOES NOT THERE IS A BUG TO HUNT HERE FIXME assert($mar && !empty($mar), "No lesson found for $lesson_slug in page ".$a->url());
$ma = @array_filter($ha->lessons, $fdp)[0]; $ma = array_shift($mar);
$mb = @array_filter($hb->lessons, $fdp)[0];
$mbr = array_filter($hb->lessons, $fdp);
assert($mbr && !empty($mbr), "No lesson found for $lesson_slug in page ".$b->url());
$mb = array_shift($mbr);
if (isset($ma['order'])) { if ($ma && isset($ma['order'])) {
$la = floor($ma['order']); $la = floor($ma['order']);
} }
if (isset($mb['order'])) { if ($mb && isset($mb['order'])) {
$lb = floor($mb['order']); $lb = floor($mb['order']);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment