protected function addOrganizations()
 {
     // Create organizations list node
     $organizations = $this->xml->addChild('organizations');
     $organizations->addAttribute('default', 'default_organization');
     // Create the default organization
     $default = $organizations->addChild('organization');
     $default->addAttribute('identifier', 'default_organization');
     $default->addChild('title', $this->node->getName());
     // Create the Resource item
     $item = $default->addChild('item');
     $item->addAttribute('identifier', 'item_' . $this->node->getId());
     $item->addAttribute('identifierref', 'resource_' . $this->node->getId());
     $item->addAttribute('isvisible', true);
     $item->addChild('title', $this->node->getName());
     return $organizations;
 }
 /**
  * @todo find the method wich generate the url from tinymce
  *
  * @param ResourceNode $node
  */
 public function generateDisplayedUrlForTinyMce(ResourceNode $node, $match)
 {
     $imgdata = explode('@', $match[1]);
     $width = $imgdata[1];
     $height = $imgdata[2];
     $style = $imgdata[3];
     $url = $this->router->generate('claro_file_get_media', ['node' => $node->getId()]);
     $img = '<img ';
     if ($width !== '') {
         $img .= "width='{$width}' ";
     }
     if ($height !== '') {
         $img .= "height='{$height}' ";
     }
     if ($style !== '') {
         $img .= "style='{$style}' ";
     }
     $img .= "src='{$url}' alt='{$node->getName()}'>";
     return $img;
 }
Beispiel #3
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;
 }
 /**
  * Constructor.
  *
  * LogResourceEvent is used by plugins for creating custom events when
  * action occured on a resource, or child resource (e.g. post in forum,
  * comment in blog, event in calendar etc.)
  *
  * Possible changes over a resource's child are: creation, delete, update, published, unpublished, etc.
  *
  * "$details" is an array that contains all necessary info to describe indirect resource modification.
  *
  * For example when a comment is published to a blog resource the details could be:
  *
  * array(
  *      'comment' => array(
  *          'text' => 'Very useful post thx',
  *          'owner' => array(
  *              'username' => 'JohnDoe',
  *              'email' => '*****@*****.**'
  *          )
  *      )
  * )
  *
  * Please respect lowerCamelCase naming convention for property names in details
  */
 public function __construct(ResourceNode $node, $details)
 {
     $commonDetails = array('resource' => array('name' => $node->getName(), 'path' => $node->getPathForDisplay()), 'workspace' => array('name' => $node->getWorkspace()->getName()), 'owner' => array('lastName' => $node->getCreator()->getLastName(), 'firstName' => $node->getCreator()->getFirstName()));
     $detailsData = array_merge($commonDetails, $details);
     parent::__construct(static::ACTION, $detailsData, null, null, $node, null, $node->getWorkspace(), $node->getCreator(), null);
 }
 /**
  * Removes a resource.
  *
  * @param \Claroline\CoreBundle\Entity\Resource\ResourceNode $node
  *
  * @throws \LogicException
  */
 public function delete(ResourceNode $resourceNode, $force = false)
 {
     $this->log('Removing ' . $resourceNode->getName() . '[' . $resourceNode->getResourceType()->getName() . ':id:' . $resourceNode->getId() . ']');
     if ($resourceNode->getParent() === null && !$force) {
         throw new \LogicException('Root directory cannot be removed');
     }
     $workspace = $resourceNode->getWorkspace();
     $nodes = $this->getDescendants($resourceNode);
     $count = count($nodes);
     $nodes[] = $resourceNode;
     $softDelete = $this->platformConfigHandler->getParameter('resource_soft_delete');
     $this->om->startFlushSuite();
     $this->log('Looping through ' . $count . ' children...');
     foreach ($nodes as $node) {
         $eventSoftDelete = false;
         $this->log('Removing ' . $node->getName() . '[' . $node->getResourceType()->getName() . ':id:' . $node->getId() . ']');
         $resource = $this->getResourceFromNode($node);
         /*
          * resChild can be null if a shortcut was removed
          * @todo: fix shortcut delete. If a target is removed, every link to the target should be removed too.
          */
         if ($resource !== null) {
             if ($node->getClass() !== 'Claroline\\CoreBundle\\Entity\\Resource\\ResourceShortcut') {
                 $event = $this->dispatcher->dispatch("delete_{$node->getResourceType()->getName()}", 'DeleteResource', [$resource]);
                 $eventSoftDelete = $event->isSoftDelete();
                 foreach ($event->getFiles() as $file) {
                     if ($softDelete) {
                         $parts = explode($this->filesDirectory . DIRECTORY_SEPARATOR, $file);
                         if (count($parts) === 2) {
                             $deleteDir = $this->filesDirectory . DIRECTORY_SEPARATOR . 'DELETED_FILES';
                             $dest = $deleteDir . DIRECTORY_SEPARATOR . $parts[1];
                             $additionalDirs = explode(DIRECTORY_SEPARATOR, $parts[1]);
                             for ($i = 0; $i < count($additionalDirs) - 1; ++$i) {
                                 $deleteDir .= DIRECTORY_SEPARATOR . $additionalDirs[$i];
                             }
                             if (!is_dir($deleteDir)) {
                                 mkdir($deleteDir, 0777, true);
                             }
                             rename($file, $dest);
                         }
                     } else {
                         unlink($file);
                     }
                     //It won't work if a resource has no workspace for a reason or an other. This could be a source of bug.
                     $dir = $this->filesDirectory . DIRECTORY_SEPARATOR . 'WORKSPACE_' . $workspace->getId();
                     if (is_dir($dir) && $this->isDirectoryEmpty($dir)) {
                         rmdir($dir);
                     }
                 }
             }
             //what is it ?
             $this->dispatcher->dispatch('claroline_resources_delete', 'GenericDatas', [[$node]]);
             $this->dispatcher->dispatch('log', 'Log\\LogResourceDelete', [$node]);
             // Delete all associated shortcuts
             $this->deleteAssociatedShortcuts($node);
             if ($softDelete || $eventSoftDelete) {
                 $node->setActive(false);
                 $this->om->persist($node);
             } else {
                 if ($node->getIcon() && $workspace) {
                     $this->iconManager->delete($node->getIcon(), $workspace);
                 }
                 /*
                  * If the child isn't removed here aswell, doctrine will fail to remove $resChild
                  * because it still has $resChild in its UnitOfWork or something (I have no idea
                  * how doctrine works tbh). So if you remove this line the suppression will
                  * not work for directory containing children.
                  */
                 $this->om->remove($resource);
             }
         }
         $this->om->remove($node);
     }
     $this->om->endFlushSuite();
     if (!$softDelete && $resourceNode->getParent()) {
         $this->reorder($resourceNode->getParent());
     }
 }
 private function getDirectoryElement(ResourceNode $resourceNode, &$_files, $setParentNull = false)
 {
     $parentId = $resourceNode->getParent() ? $resourceNode->getParent()->getId() : null;
     if ($setParentNull) {
         $parentId = null;
     }
     $resElement = array('directory' => array('name' => $resourceNode->getName(), 'creator' => null, 'parent' => $parentId, 'published' => $resourceNode->isPublished(), 'uid' => $resourceNode->getId(), 'roles' => $this->getPermsArray($resourceNode), 'index' => $resourceNode->getIndex()));
     if ($icon = $this->getIcon($resourceNode, $_files)) {
         $resElement['directory']['icon'] = $icon;
     }
     return $resElement;
 }
 /**
  * Constructor.
  * $resource is the final copy
  * while $source is the original object
  */
 public function __construct(ResourceNode $resource, ResourceNode $source)
 {
     parent::__construct(self::ACTION, array('resource' => array('name' => $resource->getName(), 'path' => $resource->getPathForDisplay()), 'workspace' => array('name' => $resource->getWorkspace()->getName()), 'owner' => array('lastName' => $resource->getCreator()->getLastName(), 'firstName' => $resource->getCreator()->getFirstName()), 'source' => array('resource' => array('id' => $source->getId(), 'name' => $source->getName(), 'path' => $source->getPathForDisplay()), 'workspace' => array('id' => $source->getWorkspace()->getId(), 'name' => $source->getWorkspace()->getName()))), null, null, $resource, null, $resource->getWorkspace(), $resource->getCreator());
 }
 /**
  * @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>";
 }