/**
  * 
  * prepares challenge and displays view to solve it
  * requires Session var "Challenge.play" given by PointsController::process()
  * @see PointsController::process()
  */
 function play()
 {
     if (!$this->Session->check('Challenge.play')) {
         $this->Session->setFlash('In order of play a challenge, please choose an action (search, upload or earn points)');
         $this->redirect('/');
     }
     $this->Session->delete('Challenge');
     $user = $this->getConnectedUser();
     $repo = $this->getCurrentRepository();
     if (is_null($repo)) {
         $this->Session->setFlash('You must be in a repository', 'flash_errors');
         $this->redirect('/');
     }
     $repo_id = $repo['Repository']['id'];
     $criterio = $this->Criteria->getRandomCriteria($repo_id);
     if (is_null($criterio)) {
         $this->_skip_challenge();
     }
     $documentos = $this->Criteria->generateChallenge($user['User']['id'], $criterio, $repo_id);
     if (count($documentos) == 0) {
         $this->_skip_challenge();
     }
     $this->Session->write('Challenge.criterio', $documentos[0]['CriteriasDocument']['criteria_id']);
     $this->Session->write('Challenge.validate', true);
     $this->set(compact('documentos', 'criterio'));
 }