/** * Checks whether a User has access to a Paper * ATTENTION : As is, anonymous have access to all the other anonymous Papers !!! * * @param Paper $paper * @param User|null $user */ private function assertHasPaperAccess(Paper $paper, User $user = null) { if ($paper->getEnd() || $user !== $paper->getUser()) { throw new AccessDeniedHttpException(); } }
/** * Return user name or anonymous, according to exercise settings. * * @param Paper $paper * * @return string */ private function showUserPaper(Paper $paper) { if (!$paper->getUser() || $paper->getAnonymous()) { $showUser = $this->translator->trans('anonymous', [], 'ujm_exo'); } else { $showUser = $paper->getUser()->getFirstName() . ' ' . $paper->getUser()->getLastName(); } return $showUser; }
/** * To control if the user is allowed to display the paper * * @access private * * @param \Claroline\CoreBundle\Entity\User $user user connected * @param \UJM\ExoBundle\Entity\Paper $paper paper to display * * @return \Symfony\Component\HttpFoundation\Response */ private function ctrlDisplayPaper($user, $paper) { $display = 'none'; if ($this->container->get('ujm.exercise_services')->isExerciseAdmin($paper->getExercise()) || $user->getId() == $paper->getUser()->getId() && ($paper->getExercise()->getCorrectionMode() == 1 || $paper->getExercise()->getCorrectionMode() == 3 && $paper->getExercise()->getDateCorrection()->format('Y-m-d H:i:s') <= date("Y-m-d H:i:s") || $paper->getExercise()->getCorrectionMode() == 2 && $paper->getExercise()->getMaxAttempts() <= $this->container->get('ujm.exercise_services')->getNbPaper($user->getId(), $paper->getExercise()->getId()))) { $display = 'all'; } else { if ($user->getId() == $paper->getUser()->getId() && $paper->getExercise()->getMarkMode() == 2) { $display = 'score'; } } return $display; }