示例#1
0
 /**
  * Create (if possible) and|or returns an icon for a resource
  *
  * @param \Claroline\CoreBundle\Entity\Resource\AbstractResource $resource
  *
  * @return \Claroline\CoreBundle\Entity\Resource\ResourceIcon
  */
 public function getIcon(AbstractResource $resource, Workspace $workspace)
 {
     $node = $resource->getResourceNode();
     $mimeElements = explode('/', $node->getMimeType());
     $ds = DIRECTORY_SEPARATOR;
     // if video or img => generate the thumbnail, otherwise find an existing one.
     if ($mimeElements[0] === 'video' || $mimeElements[0] === 'image') {
         $this->om->startFlushSuite();
         $thumbnailPath = $this->createFromFile($this->fileDir . $ds . $resource->getHashName(), $mimeElements[0], $workspace);
         if ($thumbnailPath !== null) {
             $thumbnailName = pathinfo($thumbnailPath, PATHINFO_BASENAME);
             if (is_null($workspace)) {
                 $relativeUrl = $this->basepath . "/{$thumbnailName}";
             } else {
                 $relativeUrl = $this->basepath . $ds . $workspace->getCode() . $ds . $thumbnailName;
             }
             $icon = $this->om->factory('Claroline\\CoreBundle\\Entity\\Resource\\ResourceIcon');
             $icon->setMimeType('custom');
             $icon->setRelativeUrl($relativeUrl);
             $icon->setShortcut(false);
             $this->om->persist($icon);
             $this->createShortcutIcon($icon, $workspace);
             $this->om->endFlushSuite();
             return $icon;
         }
         $this->om->endFlushSuite();
     }
     //default & fallback
     return $this->searchIcon($node->getMimeType());
 }
 /**
  * Checks if the current user has the right to perform an action on a ResourceCollection.
  * Be careful, ResourceCollection may need some aditionnal parameters.
  *
  * - for CREATE: $collection->setAttributes(array('type' => $resourceType))
  *  where $resourceType is the name of the resource type.
  * - for MOVE / COPY $collection->setAttributes(array('parent' => $parent))
  *  where $parent is the new parent entity.
  *
  * @param string                                                 $permission
  * @param \Claroline\CoreBundle\Entity\Resource\AbstractResource $resource
  *
  * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException
  */
 private function checkAccess($permission, AbstractResource $resource)
 {
     $collection = new ResourceCollection([$resource->getResourceNode()]);
     if (!$this->authorization->isGranted($permission, $collection)) {
         throw new AccessDeniedException($collection->getErrorsForDisplay());
     }
 }
 protected static function createResourceRights(Role $role, AbstractResource $resource, $mask, array $creatableResourceTypes = [])
 {
     $rights = new ResourceRights();
     $rights->setRole($role);
     $rights->setResourceNode($resource->getResourceNode());
     $rights->setMask($mask);
     foreach ($creatableResourceTypes as $type) {
         $rights->addCreatableResourceType($type);
     }
     self::create("resource_right/{$role->getName()}-{$resource->getResourceNode()->getName()}", $rights);
 }
示例#4
0
 /**
  * Dispatch export event for the Resource.
  *
  * @param AbstractResource $resource
  * @param string           $locale
  *
  * @return ExportScormResourceEvent
  */
 private function dispatchEvent(AbstractResource $resource, $locale)
 {
     return $this->dispatcher->dispatch('export_scorm_' . $resource->getResourceNode()->getResourceType()->getName(), 'Claroline\\ScormBundle\\Event\\ExportScormResourceEvent', [$resource, $locale]);
 }