Skip to content

Instantly share code, notes, and snippets.

@kaliaparijat
Created July 6, 2012 23:05
Show Gist options
  • Save kaliaparijat/3063259 to your computer and use it in GitHub Desktop.
Save kaliaparijat/3063259 to your computer and use it in GitHub Desktop.
Coding style sample: Controller code for a web page, uses DOCTRINE ORM for querying
public function executeQuizResults(sfWebRequest $request)
{
if($request->isMethod('post'))
{
$contentId = $request->getParameter('id');
$this->quiz =
$questionsForContentId = Doctrine_Core::getTable('Questions')->findByContentId($contentId);
foreach($questionsForContentId as $questionOfContentId)
{
$questionId = $questionOfContentId->getQuestionId();
$userChoices[$questionId] = $userChoice = $request->getParameter('solution_options_'.$questionId);
$correctChoices[$questionId] = $questionOfContentId->getSolution();
{
$feedback[$questionId][1] = $questionOfContentId->getFeedback1();
$feedback[$questionId][2] = $questionOfContentId->getFeedback2();
$feedback[$questionId][3] = $questionOfContentId->getFeedback3();
$feedback[$questionId][4] = $questionOfContentId->getFeedback4();
$feedback[$questionId][5] = $questionOfContentId->getFeedback5();
}
}
$this->feedbacks = $feedback;
$this->usersChoices = $userChoices;
// returns an array with questionsIds and answers as key value pairs.
$this->wrongChoices = array_diff_assoc($userChoices, $correctChoices) ;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment