コード例 #1
0
 /**
  * @param string $attribute
  * @param LearningMaterialInterface $material
  * @param TokenInterface $token
  * @return bool
  */
 protected function voteOnAttribute($attribute, $material, TokenInterface $token)
 {
     $user = $token->getUser();
     if (!$user instanceof UserInterface) {
         return false;
     }
     switch ($attribute) {
         case self::VIEW:
             // Deny access to LMs that are 'in draft' if the current user
             // does not have elevated privileges.
             return LearningMaterialStatusInterface::IN_DRAFT !== $material->getStatus()->getId() || $this->userHasRole($user, ['Faculty', 'Course Director', 'Developer']);
             break;
         case self::CREATE:
             // users with 'Faculty', 'Course director' or 'Developer' role can create materials.
             return $this->userHasRole($user, ['Faculty', 'Course Director', 'Developer']);
             break;
         case self::EDIT:
         case self::DELETE:
             // in order to grant EDIT and DELETE privileges on the given learning material to the given user,
             // at least one of the following statements must be true:
             // 1. the user owns the learning material
             // 2. the user has at least one of 'Faculty', 'Course Director' or 'Developer' roles.
             return $this->usersAreIdentical($user, $material->getOwningUser()) || $this->userHasRole($user, ['Faculty', 'Course Director', 'Developer']);
             break;
     }
     return false;
 }
コード例 #2
0
 /**
  * @param LearningMaterialInterface $learningMaterial
  * @param Router $router
  */
 public function __construct(LearningMaterialInterface $learningMaterial, Router $router)
 {
     if ($learningMaterial->getFilename()) {
         $link = $router->generate('ilios_core_downloadlearningmaterial', ['token' => $learningMaterial->getToken()], UrlGenerator::ABSOLUTE_URL);
         $this->absoluteFileUri = $link;
     }
     $this->id = $learningMaterial->getId();
     $this->title = $learningMaterial->getTitle();
     $this->description = $learningMaterial->getDescription();
     $this->uploadDate = $learningMaterial->getUploadDate();
     $this->originalAuthor = $learningMaterial->getOriginalAuthor();
     $this->userRole = (string) $learningMaterial->getUserRole();
     $this->status = (string) $learningMaterial->getStatus();
     $this->owningUser = (string) $learningMaterial->getOwningUser();
     $this->citation = $learningMaterial->getCitation();
     $this->copyrightPermission = $learningMaterial->hasCopyrightPermission();
     $this->copyrightRationale = $learningMaterial->getCopyrightRationale();
     $this->mimetype = $learningMaterial->getMimetype();
     $this->filesize = $learningMaterial->getFilesize();
     $this->filename = $learningMaterial->getFilename();
     $this->link = $learningMaterial->getLink();
     $courseLearningMaterialIds = $learningMaterial->getCourseLearningMaterials()->map(function (CourseLearningMaterialInterface $lm) {
         return (string) $lm;
     });
     $this->courseLearningMaterials = $courseLearningMaterialIds->toArray();
     $sessionLearningMaterialIds = $learningMaterial->getSessionLearningMaterials()->map(function (SessionLearningMaterialInterface $lm) {
         return (string) $lm;
     });
     $this->sessionLearningMaterials = $sessionLearningMaterialIds->toArray();
 }