コード例 #1
0
ファイル: IconManager.php プロジェクト: ChMat/CoreBundle
 /**
  * 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());
 }
コード例 #2
0
ファイル: ResourceManager.php プロジェクト: ChMat/CoreBundle
 /**
  * Checks if a resource already has a name.
  *
  * @param \Claroline\CoreBundle\Entity\Resource\AbstractResource $resource
  *
  * @throws MissingResourceNameException
  */
 public function checkResourcePrepared(AbstractResource $resource)
 {
     $stringErrors = '';
     //null or '' shouldn't be valid
     if ($resource->getName() == null) {
         $stringErrors .= 'The resource name is missing' . PHP_EOL;
     }
     if ($stringErrors !== '') {
         throw new MissingResourceNameException($stringErrors);
     }
 }
コード例 #3
0
 /**
  * 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());
     }
 }
コード例 #4
0
 /**
  * Sets the common properties of a resource.
  *
  * @param AbstractResource $resource
  * @param ResourceType     $type
  * @param User             $creator
  * @param Workspace        $workspace
  * @param ResourceNode     $parent
  *
  * @return AbstractResource
  */
 private static function prepareResource(AbstractResource $resource, ResourceType $type, User $creator, Workspace $workspace, $name, $mimeType, $parent = null)
 {
     $node = new ResourceNode();
     $node->setResourceType($type);
     $node->setCreator($creator);
     $node->setWorkspace($workspace);
     $node->setCreationDate(self::$time);
     $node->setClass('resourceClass');
     $node->setName($name);
     $node->setMimeType($mimeType);
     if ($parent) {
         $node->setParent($parent);
     }
     self::$om->persist($node);
     $resource->setResourceNode($node);
     return $resource;
 }
コード例 #5
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]);
 }