/** * To know if an user is the creator of an exercise. * * * @param Exercise $exercise * * @return bool */ public function isExerciseAdmin(Exercise $exercise) { $collection = new ResourceCollection([$exercise->getResourceNode()]); if ($this->authorizationChecker->isGranted('ADMINISTRATE', $collection)) { return true; } else { return false; } }
/** * @param string $permission * * @param Exercise $exo * * @return bool */ protected function isUserGranted($permission, Exercise $exo, $collection = null) { if ($collection === null) { $collection = new ResourceCollection(array($exo->getResourceNode())); } $checkPermission = false; if ($this->get('security.authorization_checker')->isGranted($permission, $collection)) { $checkPermission = true; } return $checkPermission; }
/** * Export metadata of the Exercise in a JSON-encodable format. * * @param Exercise $exercise * * @return array */ private function exportMetadata(Exercise $exercise) { $node = $exercise->getResourceNode(); $creator = $node->getCreator(); $authorName = sprintf('%s %s', $creator->getFirstName(), $creator->getLastName()); // Accessibility dates $startDate = $node->getAccessibleFrom() ? $node->getAccessibleFrom()->format('Y-m-d\\TH:i:s') : null; $endDate = $node->getAccessibleUntil() ? $node->getAccessibleUntil()->format('Y-m-d\\TH:i:s') : null; $correctionDate = $exercise->getDateCorrection() ? $exercise->getDateCorrection()->format('Y-m-d\\TH:i:s') : null; return ['authors' => [['name' => $authorName]], 'created' => $node->getCreationDate()->format('Y-m-d\\TH:i:s'), 'title' => $node->getName(), 'description' => $exercise->getDescription(), 'type' => $exercise->getType(), 'pick' => $exercise->getPickSteps(), 'random' => $exercise->getShuffle(), 'keepSteps' => $exercise->getKeepSteps(), 'maxAttempts' => $exercise->getMaxAttempts(), 'lockAttempt' => $exercise->getLockAttempt(), 'dispButtonInterrupt' => $exercise->getDispButtonInterrupt(), 'metadataVisible' => $exercise->isMetadataVisible(), 'statistics' => $exercise->hasStatistics(), 'anonymous' => $exercise->getAnonymous(), 'duration' => $exercise->getDuration(), 'markMode' => $exercise->getMarkMode(), 'correctionMode' => $exercise->getCorrectionMode(), 'correctionDate' => $correctionDate, 'startDate' => $startDate, 'endDate' => $endDate, 'published' => $node->isPublished(), 'publishedOnce' => $exercise->wasPublishedOnce(), 'minimalCorrection' => $exercise->isMinimalCorrection()]; }
/** * To check the right to open exo or not * * @access private * * @param \UJM\ExoBundle\Entity\Exercise $exo * * @return exception */ private function checkAccess($exo) { $collection = new ResourceCollection(array($exo->getResourceNode())); if (!$this->get('security.authorization_checker')->isGranted('OPEN', $collection)) { throw new AccessDeniedException($collection->getErrorsForDisplay()); } }
private function assertHasPermission($permission, Exercise $exercise) { $collection = new ResourceCollection([$exercise->getResourceNode()]); if (!$this->get('security.authorization_checker')->isGranted($permission, $collection)) { throw new AccessDeniedHttpException(); } }
private function isAdmin(Exercise $exercise) { $collection = new ResourceCollection([$exercise->getResourceNode()]); return $this->authorization->isGranted('ADMINISTRATE', $collection); }
/** * @param Exercise $exercise * @param array $details */ public function __construct(Exercise $exercise, $details) { parent::__construct($exercise->getResourceNode(), $details); }
/** * @param Exercise $exercise * @param string $grade */ public function __construct(Exercise $exercise, $grade) { $details = array('exercise' => array('id' => $exercise->getId(), 'name' => $exercise->getName(), 'title' => $exercise->getTitle()), 'result' => $grade['scorePaper'], 'resultMax' => $grade['maxExoScore']); parent::__construct($exercise->getResourceNode(), $details); }