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 = "