Skip to content

Instantly share code, notes, and snippets.

@codecowboy
Created October 29, 2011 07:34
Show Gist options
  • Save codecowboy/1324206 to your computer and use it in GitHub Desktop.
Save codecowboy/1324206 to your computer and use it in GitHub Desktop.
DefaultController
public function indexAction()
{
$user = $user = $this->get('security.context')->getToken()->getUser();
$challenge = $this->getDoctrine()
->getRepository('GymloopCoreBundle:Challenge')
->find(1);
if(!$challenge) {
throw $this->createNotFoundException('No challenge found');
}
$coordinates = $challenge->getCoordinates();
//get the UserChallenge object for this challenge id (if it exists)
//pass the user's distance to the view
$UserChallenge = $this->getDoctrine()
->getRepository('GymloopCoreBundle:UsersChallenges')
->findOneByUserAndChallenge($user,$challenge);
if($UserChallenge) {
\Doctrine\Common\Util\Debug::dump($UserChallenge);
$userDistance = $UserChallenge->getDistance();
} else {
$userDistance = 0;
}
return $this->render('GymloopChallengeBundle:Default:index.html.twig', array('challenge' => $challenge, 'user_distance'=> $userDistance));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment