I am using a Front Controller to send the user through a series of pages with questions. Pretty much everything must be dynamic as the pages, the questions, and everything else is set in the admin interface and stored in the database.
I am tracking the user's progress through the database by storing a unique identifier in the session and storing the current page the user is on in the database so I can figure out the next page to send them to.
The thing is, there are a lot of special cases to check for. Right now the controller is over 300 lines long and the code is poorly written and I'm the one who wrote it. Plus, I am going to need to add a lot more to this system in the upcoming weeks such as user-generated content and different pages to show depending on where the user is coming from.
I can see that this controller is going to become a big mess fast if I don't organize it well.
What are some good ways or ideas to refactor this?