From 72ecfa89e08628712c729ead5204c00bbca23485 Mon Sep 17 00:00:00 2001 From: Audrey Jensen Date: Wed, 19 Jul 2023 18:38:12 +0000 Subject: [PATCH 1/6] add logic finding index of prev and next topics --- src/Controller/SafetyController.php | 50 +++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/src/Controller/SafetyController.php b/src/Controller/SafetyController.php index 1d19a26..2551eeb 100644 --- a/src/Controller/SafetyController.php +++ b/src/Controller/SafetyController.php @@ -46,14 +46,58 @@ class SafetyController extends AbstractController return $this->render('Training/Safety/SafetyQuiz.html.twig',['quiz'=>$form]); } #[Route('/Training/Safety/Topics/{topic?}')] - public function Topics(?string $topic) : Response + public function Topics(?string $topic, LoggerInterface $log) : Response { //We want to show the safety homepage if this is blank if($topic == null) { return $this->redirectToRoute('safetyHome'); } + + //We need to get the previous and next topics for nav buttons + //FEATURING: Regret for not having mapped this YAML file to a data model that would have saved myself a lot of trouble and spaghetti + $contentFile = Yaml::parseFile('../config/safetyLinks.yaml', 2, 2, Yaml::PARSE_OBJECT_FOR_MAP); + $previousTopic = $nextTopic = -1; //declare ahead of time for scoping + + $arrayKeys = array_keys($contentFile['Cards']); + foreach($arrayKeys as $key) + { + $card = $contentFile['Cards'][$key]; + for($i = 0; $i < count($card); $i++) + { + $entry = $card[$i]; + $cardIndex = array_search($key, $arrayKeys); + if($entry['url'] == $topic) + { + //Assign Previous Topic + if($i > 0) + { + $previousTopic = $i - 1; + } + else if($cardIndex > 0) //there's a previous card, use the last entry in it + { + $previousTopic = count($contentFile['Cards'][$arrayKeys[$cardIndex-1]]) -1; + } + + //Assign Next Topic + if($i < count($card)) //Next topic should be within the same card + { + $nextTopic = $i + 1; + } + else if($cardIndex > count($contentFile['Cards'])) //Next topic is not in same card, or does not exist + { + $nextTopic = $contentFile['Cards'][$arrayKeys[$cardIndex+1]][0]; //Set to first entry in next card + } + break 2; //Got what we needed, break out of both for loops + } + } + } + $topic = strtolower($topic); - return $this->render('Training/Safety/Topics/'.$topic.".html.twig"); + //TODO: Insert back button + $contents = $this->render('Training/Safety/Topics/'.$topic.".html.twig"); + $navButtons = $this->render('Training/Safety/navButtons.html.twig'); + $debug = "

Prev: " . $previousTopic . ". Next: " . $nextTopic . "

"; + return new Response($debug . $contents . $navButtons); } -} \ No newline at end of file +} From 40f04f07e636d593b957b252e7a7d59756b2a6fe Mon Sep 17 00:00:00 2001 From: Audrey Jensen Date: Wed, 19 Jul 2023 20:04:54 +0000 Subject: [PATCH 2/6] get url of prev and next --- src/Controller/SafetyController.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Controller/SafetyController.php b/src/Controller/SafetyController.php index 2551eeb..ce785dd 100644 --- a/src/Controller/SafetyController.php +++ b/src/Controller/SafetyController.php @@ -57,7 +57,7 @@ class SafetyController extends AbstractController //We need to get the previous and next topics for nav buttons //FEATURING: Regret for not having mapped this YAML file to a data model that would have saved myself a lot of trouble and spaghetti $contentFile = Yaml::parseFile('../config/safetyLinks.yaml', 2, 2, Yaml::PARSE_OBJECT_FOR_MAP); - $previousTopic = $nextTopic = -1; //declare ahead of time for scoping + $previousTopic = $nextTopic = ""; //declare ahead of time for scoping $arrayKeys = array_keys($contentFile['Cards']); foreach($arrayKeys as $key) @@ -72,19 +72,20 @@ class SafetyController extends AbstractController //Assign Previous Topic if($i > 0) { - $previousTopic = $i - 1; + $previousTopic = $contentFile['Cards'][$arrayKeys[$cardIndex]][$i-1]; } else if($cardIndex > 0) //there's a previous card, use the last entry in it { - $previousTopic = count($contentFile['Cards'][$arrayKeys[$cardIndex-1]]) -1; + //NOTE: Should be fine to use end, at this point we shouldn't care about the array's internal pointer, we're done iterating + $previousTopic = end($contentFile['Cards'][$arrayKeys[$cardIndex-1]]); } //Assign Next Topic - if($i < count($card)) //Next topic should be within the same card + if($i < count($card)-1) //Next topic should be within the same card { - $nextTopic = $i + 1; + $nextTopic = $contentFile['Cards'][$arrayKeys[$cardIndex]][$i+1]; } - else if($cardIndex > count($contentFile['Cards'])) //Next topic is not in same card, or does not exist + else if($cardIndex < count($contentFile['Cards'])) //Next topic is not in same card, or does not exist { $nextTopic = $contentFile['Cards'][$arrayKeys[$cardIndex+1]][0]; //Set to first entry in next card } @@ -97,7 +98,7 @@ class SafetyController extends AbstractController //TODO: Insert back button $contents = $this->render('Training/Safety/Topics/'.$topic.".html.twig"); $navButtons = $this->render('Training/Safety/navButtons.html.twig'); - $debug = "

Prev: " . $previousTopic . ". Next: " . $nextTopic . "

"; + $debug = "

Prev: " . $previousTopic['url'] . ". Next: " . $nextTopic['url'] . "

"; return new Response($debug . $contents . $navButtons); } } From b053c7b6171754c10279126b36a37d36f7198d6b Mon Sep 17 00:00:00 2001 From: Audrey Jensen Date: Wed, 19 Jul 2023 20:18:13 +0000 Subject: [PATCH 3/6] render prev next page buttons --- src/Controller/SafetyController.php | 6 +++--- templates/Training/Safety/navButtons.html.twig | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 templates/Training/Safety/navButtons.html.twig diff --git a/src/Controller/SafetyController.php b/src/Controller/SafetyController.php index ce785dd..083b29c 100644 --- a/src/Controller/SafetyController.php +++ b/src/Controller/SafetyController.php @@ -96,9 +96,9 @@ class SafetyController extends AbstractController $topic = strtolower($topic); //TODO: Insert back button + $navButtonData = ['previous'=> $previousTopic, 'next' => $nextTopic]; $contents = $this->render('Training/Safety/Topics/'.$topic.".html.twig"); - $navButtons = $this->render('Training/Safety/navButtons.html.twig'); - $debug = "

Prev: " . $previousTopic['url'] . ". Next: " . $nextTopic['url'] . "

"; - return new Response($debug . $contents . $navButtons); + $navButtons = $this->render('Training/Safety/navButtons.html.twig',$navButtonData); + return new Response($contents . $navButtons); } } diff --git a/templates/Training/Safety/navButtons.html.twig b/templates/Training/Safety/navButtons.html.twig new file mode 100644 index 0000000..5c3c1c5 --- /dev/null +++ b/templates/Training/Safety/navButtons.html.twig @@ -0,0 +1,16 @@ + +
+
+
+ {% if previous != null %} + Previous Page: {{previous.title}} + {% endif %} +
+
+ {% if next != null %} + Next Page: {{next.title}} + {% endif %} +
+
+
+ \ No newline at end of file From be44377631f3ba808a27c5f1d3126ebd1dee95bb Mon Sep 17 00:00:00 2001 From: Audrey Jensen Date: Wed, 19 Jul 2023 20:19:03 +0000 Subject: [PATCH 4/6] fix error when next card null --- src/Controller/SafetyController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/SafetyController.php b/src/Controller/SafetyController.php index 083b29c..b2f2f00 100644 --- a/src/Controller/SafetyController.php +++ b/src/Controller/SafetyController.php @@ -85,7 +85,7 @@ class SafetyController extends AbstractController { $nextTopic = $contentFile['Cards'][$arrayKeys[$cardIndex]][$i+1]; } - else if($cardIndex < count($contentFile['Cards'])) //Next topic is not in same card, or does not exist + else if($cardIndex < count($contentFile['Cards'])-1) //Next topic is not in same card, or does not exist { $nextTopic = $contentFile['Cards'][$arrayKeys[$cardIndex+1]][0]; //Set to first entry in next card } From 6021760dc8f5c18a445f1e922b41b21ce2af9f6d Mon Sep 17 00:00:00 2001 From: Audrey Jensen Date: Wed, 19 Jul 2023 20:27:17 +0000 Subject: [PATCH 5/6] add nav buttons to tops of topic pages --- src/Controller/SafetyController.php | 2 +- templates/Training/Safety/Topics/actionplan.html.twig | 1 + templates/Training/Safety/Topics/bloodborne.html.twig | 1 + templates/Training/Safety/Topics/crane.html.twig | 1 + templates/Training/Safety/Topics/electrical.html.twig | 1 + templates/Training/Safety/Topics/extinguisher.html.twig | 1 + templates/Training/Safety/Topics/fireprevention.html.twig | 1 + templates/Training/Safety/Topics/general.html.twig | 5 +++-- templates/Training/Safety/Topics/guarding.html.twig | 1 + .../Training/Safety/Topics/hazardcommunication.html.twig | 1 + templates/Training/Safety/Topics/hearing.html.twig | 1 + templates/Training/Safety/Topics/powertools.html.twig | 1 + templates/Training/Safety/Topics/ppe.html.twig | 1 + templates/Training/Safety/Topics/safelifting.html.twig | 1 + templates/Training/Safety/Topics/tagout.html.twig | 1 + templates/Training/Safety/Topics/welding.html.twig | 1 + 16 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Controller/SafetyController.php b/src/Controller/SafetyController.php index b2f2f00..a9ad58f 100644 --- a/src/Controller/SafetyController.php +++ b/src/Controller/SafetyController.php @@ -97,7 +97,7 @@ class SafetyController extends AbstractController $topic = strtolower($topic); //TODO: Insert back button $navButtonData = ['previous'=> $previousTopic, 'next' => $nextTopic]; - $contents = $this->render('Training/Safety/Topics/'.$topic.".html.twig"); + $contents = $this->render('Training/Safety/Topics/'.$topic.".html.twig", $navButtonData); $navButtons = $this->render('Training/Safety/navButtons.html.twig',$navButtonData); return new Response($contents . $navButtons); } diff --git a/templates/Training/Safety/Topics/actionplan.html.twig b/templates/Training/Safety/Topics/actionplan.html.twig index c33cdbe..d40f0af 100644 --- a/templates/Training/Safety/Topics/actionplan.html.twig +++ b/templates/Training/Safety/Topics/actionplan.html.twig @@ -3,6 +3,7 @@ {{ include('_header.html.twig') }} {{ include('_navbar.html.twig')}} +{{ include('Training/Safety/navButtons.html.twig') }}

Emergency Action Plan

diff --git a/templates/Training/Safety/Topics/bloodborne.html.twig b/templates/Training/Safety/Topics/bloodborne.html.twig index 2584b2b..d1b3019 100644 --- a/templates/Training/Safety/Topics/bloodborne.html.twig +++ b/templates/Training/Safety/Topics/bloodborne.html.twig @@ -3,6 +3,7 @@ {{ include('_header.html.twig') }} {{ include('_navbar.html.twig')}} +{{ include('Training/Safety/navButtons.html.twig') }}
diff --git a/templates/Training/Safety/Topics/crane.html.twig b/templates/Training/Safety/Topics/crane.html.twig index ed724fb..5aa12f6 100644 --- a/templates/Training/Safety/Topics/crane.html.twig +++ b/templates/Training/Safety/Topics/crane.html.twig @@ -3,6 +3,7 @@ {{ include('_header.html.twig') }} {{ include('_navbar.html.twig')}} +{{ include('Training/Safety/navButtons.html.twig') }}

Crane / Hoist Safety

diff --git a/templates/Training/Safety/Topics/electrical.html.twig b/templates/Training/Safety/Topics/electrical.html.twig index 72e246d..9f3472f 100644 --- a/templates/Training/Safety/Topics/electrical.html.twig +++ b/templates/Training/Safety/Topics/electrical.html.twig @@ -3,6 +3,7 @@ {{ include('_header.html.twig') }} {{ include('_navbar.html.twig')}} +{{ include('Training/Safety/navButtons.html.twig') }}

Electrical Safety

diff --git a/templates/Training/Safety/Topics/extinguisher.html.twig b/templates/Training/Safety/Topics/extinguisher.html.twig index 848391f..6f90654 100644 --- a/templates/Training/Safety/Topics/extinguisher.html.twig +++ b/templates/Training/Safety/Topics/extinguisher.html.twig @@ -3,6 +3,7 @@ {{ include('_header.html.twig') }} {{ include('_navbar.html.twig')}} +{{ include('Training/Safety/navButtons.html.twig') }}

Fire Extinguisher Operation

diff --git a/templates/Training/Safety/Topics/fireprevention.html.twig b/templates/Training/Safety/Topics/fireprevention.html.twig index 4d0eff7..a2b5909 100644 --- a/templates/Training/Safety/Topics/fireprevention.html.twig +++ b/templates/Training/Safety/Topics/fireprevention.html.twig @@ -3,6 +3,7 @@ {{ include('_header.html.twig') }} {{ include('_navbar.html.twig')}} +{{ include('Training/Safety/navButtons.html.twig') }}

Fire Prevention

diff --git a/templates/Training/Safety/Topics/general.html.twig b/templates/Training/Safety/Topics/general.html.twig index 926c496..9c83c88 100644 --- a/templates/Training/Safety/Topics/general.html.twig +++ b/templates/Training/Safety/Topics/general.html.twig @@ -2,9 +2,10 @@ {{ include('_header.html.twig') }} - +{{ include('_navbar.html.twig')}} +{{ include('Training/Safety/navButtons.html.twig') }} - {{ include('_navbar.html.twig')}} +

General Rules at J.V. Manufacturing, Inc.

    diff --git a/templates/Training/Safety/Topics/guarding.html.twig b/templates/Training/Safety/Topics/guarding.html.twig index 5d9917f..ac342e5 100644 --- a/templates/Training/Safety/Topics/guarding.html.twig +++ b/templates/Training/Safety/Topics/guarding.html.twig @@ -3,6 +3,7 @@ {{ include('_header.html.twig') }} {{ include('_navbar.html.twig')}} +{{ include('Training/Safety/navButtons.html.twig') }}

    Machine Guarding

    diff --git a/templates/Training/Safety/Topics/hazardcommunication.html.twig b/templates/Training/Safety/Topics/hazardcommunication.html.twig index 12c204f..5cd90d5 100644 --- a/templates/Training/Safety/Topics/hazardcommunication.html.twig +++ b/templates/Training/Safety/Topics/hazardcommunication.html.twig @@ -3,6 +3,7 @@ {{ include('_header.html.twig') }} {{ include('_navbar.html.twig')}} +{{ include('Training/Safety/navButtons.html.twig') }}

    Hazard Communication

    diff --git a/templates/Training/Safety/Topics/hearing.html.twig b/templates/Training/Safety/Topics/hearing.html.twig index 4b4686f..558714d 100644 --- a/templates/Training/Safety/Topics/hearing.html.twig +++ b/templates/Training/Safety/Topics/hearing.html.twig @@ -3,6 +3,7 @@ {{ include('_header.html.twig') }} {{ include('_navbar.html.twig')}} +{{ include('Training/Safety/navButtons.html.twig') }}

    Hearing Protection

    diff --git a/templates/Training/Safety/Topics/powertools.html.twig b/templates/Training/Safety/Topics/powertools.html.twig index a8f2bd3..13a5883 100644 --- a/templates/Training/Safety/Topics/powertools.html.twig +++ b/templates/Training/Safety/Topics/powertools.html.twig @@ -3,6 +3,7 @@ {{ include('_header.html.twig') }} {{ include('_navbar.html.twig')}} +{{ include('Training/Safety/navButtons.html.twig') }}

    Hand & Power Tools

    diff --git a/templates/Training/Safety/Topics/ppe.html.twig b/templates/Training/Safety/Topics/ppe.html.twig index 97b84d3..b23e27d 100644 --- a/templates/Training/Safety/Topics/ppe.html.twig +++ b/templates/Training/Safety/Topics/ppe.html.twig @@ -3,6 +3,7 @@ {{ include('_header.html.twig') }} {{ include('_navbar.html.twig')}} +{{ include('Training/Safety/navButtons.html.twig') }}

    Personal Protective Equipment (Eyes, Face, Hands, & Feet)

    diff --git a/templates/Training/Safety/Topics/safelifting.html.twig b/templates/Training/Safety/Topics/safelifting.html.twig index d2f059d..04c0508 100644 --- a/templates/Training/Safety/Topics/safelifting.html.twig +++ b/templates/Training/Safety/Topics/safelifting.html.twig @@ -3,6 +3,7 @@ {{ include('_header.html.twig') }} {{ include('_navbar.html.twig')}} +{{ include('Training/Safety/navButtons.html.twig') }}

    Safe Lifting

    diff --git a/templates/Training/Safety/Topics/tagout.html.twig b/templates/Training/Safety/Topics/tagout.html.twig index 9f13895..0d2b8bf 100644 --- a/templates/Training/Safety/Topics/tagout.html.twig +++ b/templates/Training/Safety/Topics/tagout.html.twig @@ -3,6 +3,7 @@ {{ include('_header.html.twig') }} {{ include('_navbar.html.twig')}} +{{ include('Training/Safety/navButtons.html.twig') }}

    Lockout Tagout

    diff --git a/templates/Training/Safety/Topics/welding.html.twig b/templates/Training/Safety/Topics/welding.html.twig index b11542f..523299a 100644 --- a/templates/Training/Safety/Topics/welding.html.twig +++ b/templates/Training/Safety/Topics/welding.html.twig @@ -3,6 +3,7 @@ {{ include('_header.html.twig') }} {{ include('_navbar.html.twig')}} +{{ include('Training/Safety/navButtons.html.twig') }}

    Welding Safety

    From 011fcfa6141385aa63bc3f2764df5561e2ec31cd Mon Sep 17 00:00:00 2001 From: Audrey Jensen Date: Wed, 19 Jul 2023 20:32:57 +0000 Subject: [PATCH 6/6] back button --- templates/Training/Safety/navButtons.html.twig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/templates/Training/Safety/navButtons.html.twig b/templates/Training/Safety/navButtons.html.twig index 5c3c1c5..9b7512f 100644 --- a/templates/Training/Safety/navButtons.html.twig +++ b/templates/Training/Safety/navButtons.html.twig @@ -7,6 +7,9 @@ {% endif %}
    + Back +
    +
    {% if next != null %} Next Page: {{next.title}} {% endif %}