Exemplo n.º 1
0
 /**
  * @todo find the method wich generate the url from tinymce
  *
  * @param ResourceNode $node
  */
 public function generateDisplayedUrlForTinyMce(ResourceNode $node)
 {
     if (strpos('_' . $node->getMimeType(), 'image') > 0) {
         $url = $this->router->generate('claro_file_get_media', ['node' => $node->getId()], UrlGeneratorInterface::ABSOLUTE_URL);
         return "<img style='max-width: 100%;' src='{$url}' alt='{$node->getName()}'>";
     }
     if (strpos('_' . $node->getMimeType(), 'video') > 0) {
         $url = $this->router->generate('claro_file_get_media', ['node' => $node->getId()], UrlGeneratorInterface::ABSOLUTE_URL);
         return "<source type='{$node->getMimeType()}' src='{$url}'></source>";
     }
     $url = $this->router->generate('claro_resource_open', ['resourceType' => $node->getResourceType()->getName(), 'node' => $node->getId()], UrlGeneratorInterface::ABSOLUTE_URL);
     return "<a href='{$url}'>{$node->getName()}</a>";
 }
Exemplo n.º 2
0
 /**
  * Convert a resource into an array (mainly used to be serialized and sent to the manager.js as
  * a json response)
  *
  * @param \Claroline\CoreBundle\Entity\Resource\ResourceNode $node
  * @param \Symfony\Component\Security\Core\Authentication\Token\TokenInterface $toke
  * @param boolean $new: set the 'new' flag to display warning in the resource manager
  * @todo check "new" from log
  * @return array
  */
 public function toArray(ResourceNode $node, TokenInterface $token, $new = false)
 {
     $resourceArray = array();
     $resourceArray['id'] = $node->getId();
     $resourceArray['name'] = $node->getName();
     $resourceArray['parent_id'] = $node->getParent() != null ? $node->getParent()->getId() : null;
     $resourceArray['creator_username'] = $node->getCreator()->getUsername();
     $resourceArray['type'] = $node->getResourceType()->getName();
     $resourceArray['large_icon'] = $node->getIcon()->getRelativeUrl();
     $resourceArray['path_for_display'] = $node->getPathForDisplay();
     $resourceArray['mime_type'] = $node->getMimeType();
     $resourceArray['published'] = $node->isPublished();
     $resourceArray['index_dir'] = $node->getIndex();
     $resourceArray['creation_date'] = $node->getCreationDate()->format($this->translator->trans('date_range.format.with_hours', array(), 'platform'));
     $resourceArray['modification_date'] = $node->getModificationDate()->format($this->translator->trans('date_range.format.with_hours', array(), 'platform'));
     $resourceArray['new'] = $new;
     $isAdmin = false;
     $roles = $this->roleManager->getStringRolesFromToken($token);
     foreach ($roles as $role) {
         if ($role === 'ROLE_ADMIN') {
             $isAdmin = true;
         }
     }
     if ($isAdmin || $token->getUser() !== 'anon.' && $node->getCreator()->getUsername() === $token->getUser()->getUsername()) {
         $resourceArray['mask'] = 1023;
     } else {
         $resourceArray['mask'] = $this->resourceRightsRepo->findMaximumRights($roles, $node);
     }
     //the following line is required because we wanted to disable the right edition in personal worksspaces...
     //this is not required for everything to work properly.
     if ($node->getWorkspace()->isPersonal() && !$this->rightsManager->canEditPwsPerm($token)) {
         $resourceArray['enableRightsEdition'] = false;
     } else {
         $resourceArray['enableRightsEdition'] = true;
     }
     if ($node->getResourceType()->getName() === 'file') {
         if ($node->getClass() === 'Claroline\\CoreBundle\\Entity\\Resource\\ResourceShortcut') {
             $shortcut = $this->getResourceFromNode($node);
             $realNode = $shortcut->getTarget();
         } else {
             $realNode = $node;
         }
         $file = $this->getResourceFromNode($realNode);
         $resourceArray['size'] = $file->getFormattedSize();
     }
     return $resourceArray;
 }
Exemplo n.º 3
0
 private function generateEventName(ResourceNode $node, $eventPrefix, $useBaseType = false)
 {
     $mimeType = $node->getMimeType();
     if ($useBaseType) {
         $mimeElements = explode('/', $mimeType);
         $suffix = strtolower($mimeElements[0]);
     } else {
         $suffix = $mimeType;
     }
     $eventName = strtolower(str_replace('/', '_', $eventPrefix . $suffix));
     $eventName = str_replace('"', '', $eventName);
     return $eventName;
 }