forked from audrey/intranet
get url of prev and next
This commit is contained in:
parent
72ecfa89e0
commit
40f04f07e6
@ -57,7 +57,7 @@ class SafetyController extends AbstractController
|
|||||||
//We need to get the previous and next topics for nav buttons
|
//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
|
//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);
|
$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']);
|
$arrayKeys = array_keys($contentFile['Cards']);
|
||||||
foreach($arrayKeys as $key)
|
foreach($arrayKeys as $key)
|
||||||
@ -72,19 +72,20 @@ class SafetyController extends AbstractController
|
|||||||
//Assign Previous Topic
|
//Assign Previous Topic
|
||||||
if($i > 0)
|
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
|
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
|
//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
|
$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
|
//TODO: Insert back button
|
||||||
$contents = $this->render('Training/Safety/Topics/'.$topic.".html.twig");
|
$contents = $this->render('Training/Safety/Topics/'.$topic.".html.twig");
|
||||||
$navButtons = $this->render('Training/Safety/navButtons.html.twig');
|
$navButtons = $this->render('Training/Safety/navButtons.html.twig');
|
||||||
$debug = "<body><h3>Prev: " . $previousTopic . ". Next: " . $nextTopic . "</h3></body>";
|
$debug = "<body><h3>Prev: " . $previousTopic['url'] . ". Next: " . $nextTopic['url'] . "</h3></body>";
|
||||||
return new Response($debug . $contents . $navButtons);
|
return new Response($debug . $contents . $navButtons);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user