/**
  * @Route("/share/form/{resourceId}", name="icap_socialmedia_share_form", )
  * @ParamConverter("user", converter="current_user")
  * @ParamConverter("resourceNode", class="ClarolineCoreBundle:Resource\ResourceNode", options={"id" = "resourceId"})
  * @Template()
  *
  * @param ResourceNode $resourceNode
  * @param User         $user
  *
  * @return array
  */
 public function formAction(ResourceNode $resourceNode, User $user)
 {
     $shareManager = $this->getShareActionManager();
     $sharesCount = $shareManager->countShares(null, array('resource' => $resourceNode->getId()));
     $socialShare = new SocialShare();
     $resourceUrl = $this->generateUrl('claro_resource_open_short', array('node' => $resourceNode->getId()), true);
     return array('resourceNode' => $resourceNode, 'networks' => $socialShare->getNetworks(), 'shares' => $sharesCount, 'resourceUrl' => $resourceUrl);
 }
 /**
  * @Route("/share/form/{resourceId}", name="icap_socialmedia_share_form", )
  * @ParamConverter("user", options={"authenticatedUser" = true})
  * @ParamConverter("resourceNode", class="ClarolineCoreBundle:Resource\ResourceNode", options={"id" = "resourceId"})
  * @Template()
  * @param ResourceNode $resourceNode
  * @param User $user
  * @return array
  */
 public function formAction(ResourceNode $resourceNode, User $user)
 {
     $shareManager = $this->getShareActionManager();
     $sharesCount = $shareManager->countShares(null, array("resource" => $resourceNode->getId()));
     $socialShare = new SocialShare();
     $resourceUrl = $this->generateUrl("claro_resource_open_short", array("node" => $resourceNode->getId()), true);
     return array("resourceNode" => $resourceNode, "networks" => $socialShare->getNetworks(), "shares" => $sharesCount, "resourceUrl" => $resourceUrl);
 }
 /**
  * @Route("/comments/resource/{resourceId}", name="icap_socialmedia_comments_view")
  * @ParamConverter("user", options={"authenticatedUser" = true})
  * @ParamConverter(
  *      "resource",
  *      class="ClarolineCoreBundle:Resource\ResourceNode",
  *      options={"id" = "resourceId"}
  * )
  * @Template()
  * @param ResourceNode $resource
  * @param User $user
  * @return array
  */
 public function viewAction(ResourceNode $resource, User $user)
 {
     $formArray = $this->formAction($resource->getId(), $user);
     $formArray['node'] = $resource;
     $formArray['user'] = $user;
     return $formArray;
 }
 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;
 }
 public function findActivityRuleByActionAndResource($action, ResourceNode $resourceNode, $executeQuery = true)
 {
     $dql = '
         SELECT ar
         FROM Claroline\\CoreBundle\\Entity\\Activity\\ActivityRule ar
         WHERE ar.action = :action
         AND ar.resource = :resourceNodeId
     ';
     $query = $this->_em->createQuery($dql);
     $query->setParameter('action', $action);
     $query->setParameter('resourceNodeId', $resourceNode->getId());
     return $executeQuery ? $query->getResult() : $query;
 }
 public function addTemporaryAccess(ResourceNode $node, User $user = null)
 {
     $temporaryAccessArray = $this->container->get('request')->getSession()->get(self::RESOURCE_TEMPORARY_ACCESS_KEY);
     if ($temporaryAccessArray === null) {
         $temporaryAccessArray = array();
     }
     $temporaryAccessIds = array();
     if (isset($temporaryAccessArray[$this->getUserKey($user)])) {
         $temporaryAccessIds = $temporaryAccessArray[$this->getUserKey($user)];
     }
     $alreadyIn = false;
     foreach ($temporaryAccessIds as $temporaryAccessId) {
         if ($temporaryAccessId == $node->getId()) {
             $alreadyIn = true;
             break;
         }
     }
     if ($alreadyIn == false) {
         $temporaryAccessIds[] = $node->getId();
         $temporaryAccessArray[$this->getUserKey($user)] = $temporaryAccessIds;
     }
     $this->container->get('request')->getSession()->set(self::RESOURCE_TEMPORARY_ACCESS_KEY, $temporaryAccessArray);
 }
Exemplo n.º 7
0
 /**
  * Create SCORM package.
  *
  * @param ResourceNode          $node     - The exported ResourceNode
  * @param string                $locale   - THe locale to use for export
  * @param AbstractScormManifest $manifest - The manifest of the SCORM package
  * @param array                 $scos     - The list of resources to include into the package
  *
  * @return \ZipArchive
  */
 public function createPackage(ResourceNode $node, $locale, AbstractScormManifest $manifest, array $scos = [])
 {
     $scormId = 'scorm-' . $node->getId() . '-' . date('YmdHis');
     // Create and open scorm archive
     if (!is_dir($this->tmpPath)) {
         mkdir($this->tmpPath);
     }
     $archive = new \ZipArchive();
     $archive->open($this->tmpPath . DIRECTORY_SEPARATOR . $scormId . '.zip', \ZipArchive::CREATE);
     // Add manifest
     $this->saveToPackage($archive, 'imsmanifest.xml', $manifest->dump());
     // Add common files
     $this->addCommons($archive, $locale);
     // Add resources files
     foreach ($scos as $sco) {
         // Dump template into file
         $this->saveToPackage($archive, 'scos/resource_' . $sco['node']->getId() . '.html', $sco['template']);
         // Dump additional resource assets
         if (!empty($sco['assets'])) {
             foreach ($sco['assets'] as $filename => $originalFile) {
                 $this->copyToPackage($archive, 'assets/' . $filename, $this->getFilePath($this->webPath, $originalFile));
             }
         }
         // Add uploaded files
         if (!empty($sco['files'])) {
             // $this->container->getParameter('claroline.param.files_directory')
             foreach ($sco['files'] as $filename => $originalFile) {
                 $filePath = $originalFile['absolute'] ? $originalFile['path'] : $this->getFilePath($this->uploadPath, $originalFile['path']);
                 $this->copyToPackage($archive, 'files/' . $filename, $filePath);
             }
         }
         // Add translations
         if (!empty($sco['translation_domains'])) {
             foreach ($sco['translation_domains'] as $domain) {
                 $translationFile = 'js/translations/' . $domain . '/' . $locale . '.js';
                 $this->copyToPackage($archive, 'translations/' . $domain . '.js', $this->getFilePath($this->webPath, $translationFile));
             }
         }
     }
     $archive->close();
     return $archive;
 }
Exemplo n.º 8
0
 /**
  * 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());
     }
 }
 /**
  * @EXT\Route(
  *     "/delete/{node}",
  *     name="hevinci_delete_favourite",
  *     requirements={"node" = "\d+"},
  *     options={"expose"=true}
  * )
  *
  * @EXT\Method("GET")
  */
 public function deleteFavouriteAction(ResourceNode $node)
 {
     $em = $this->getDoctrine()->getManager();
     $user = $this->getUser();
     $favourite = $em->getRepository('HeVinciFavouriteBundle:Favourite')->findOneBy(array('user' => $user, 'resourceNode' => $node->getId()));
     if (!$favourite) {
         throw new \Exception("This favourite doesn't exist !");
     }
     $em->remove($favourite);
     $em->flush();
     return new Response();
 }
Exemplo n.º 10
0
 /**
  * @todo to be removed
  */
 public function findConfigurableRights(ResourceNode $resource)
 {
     $dql = "\n            SELECT rights\n            FROM Claroline\\CoreBundle\\Entity\\Resource\\ResourceRights rights\n            JOIN rights.resourceNode resource\n            JOIN rights.role role\n            WHERE resource.id = :resourceId\n            AND role.name <> :resourceManagerRole\n            AND role.type <> :roleType\n            ORDER BY role.name\n        ";
     $query = $this->_em->createQuery($dql);
     $query->setParameter('resourceId', $resource->getId());
     $query->setParameter('resourceManagerRole', 'ROLE_WS_MANAGER_' . $resource->getWorkspace()->getGuid());
     $query->setParameter('roleType', Role::USER_ROLE);
     return $query->getResult();
 }
Exemplo n.º 11
0
 /**
  * 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());
 }
Exemplo n.º 12
0
 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;
 }
 /**
  * @EXT\Route(
  *     "/testupload/{node}",
  *     name="cpasimusante_simuresource_testupload",
  *     options={"expose"=true}
  * )
  * @EXT\Template("CPASimUSanteSimuResourceBundle:SimuResource:testupload.html.twig")
  */
 public function testuploadAction(ResourceNode $node)
 {
     //retrieve resource object by resource node
     $em = $this->getDoctrine()->getManager();
     $resource = $em->getRepository('CPASimUSanteSimuResourceBundle:SimuResource')->findOneBy(array('resourceNode' => $node->getId()));
     return array('_resource' => $resource);
 }
Exemplo n.º 14
0
 public function removeTaggedObjectsByResourceAndTag(ResourceNode $resourceNode, Tag $tag)
 {
     $taggedObject = $this->getOneTaggedObjectByTagAndObject($tag, $resourceNode->getId(), str_replace('Proxies\\__CG__\\', '', get_class($resourceNode)));
     $this->deleteTaggedObject($taggedObject);
 }
Exemplo n.º 15
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.º 16
0
 /**
  * @EXT\Route(
  *     "/resources/widget/resource/{resourceNode}/open",
  *     name="claro_tag_resource_from_widget_open",
  *     options={"expose"=true}
  * )
  */
 public function resourceFromWidgetOpenAction(ResourceNode $resourceNode)
 {
     $resourceType = $resourceNode->getResourceType();
     if ($resourceType->getName() === 'directory') {
         $route = $this->router->generate('claro_workspace_open_tool', array('toolName' => 'resource_manager', 'workspaceId' => $resourceNode->getWorkspace()->getId()));
         $route .= '?#resources/' . $resourceNode->getId();
         return new RedirectResponse($route);
     } else {
         $route = $this->router->generate('claro_resource_open_short', array('node' => $resourceNode->getId()));
         return new RedirectResponse($route);
     }
 }
Exemplo n.º 17
0
 /**
  * Called on onDoinmodal Listener method for form POST
  * @EXT\Route(
  *     "/edit/{node}",
  *     name="cpasimusante_simuresource_edit_form",
  *     options={"expose"=true}
  * )
  *
  * @EXT\Template("CPASimUSanteSimuResourceBundle:SimuResource:doinmodal.html.twig")
  *
  * @param SimuResource $resourceInstance
  *
  * @return array
  */
 public function doinmodal(ResourceNode $node)
 {
     $resourceconfig = $this->simuresourceManager->getResourceConfigByNode($node->getId());
     $form = $this->getFactory()->create(new SimuResourceEditType(), $resourceconfig);
     return array('form' => $form->createView(), 'node' => $node);
 }
Exemplo n.º 18
0
 /**
  * Edit the resource
  * @EXT\Route(
  *     "/edit/{node}",
  *     name="cpasimusante_ghangout_edit_form",
  *     options={"expose"=true}
  * )
  *
  * @EXT\Template("CPASimUSanteGhangoutBundle:Hangout:edit.html.twig")
  *
  * @return array
  */
 public function edit(ResourceNode $node)
 {
     $resourceconfig = $this->resourceManager->getResourceConfigByNode($node->getId());
     $form = $this->getFactory()->create(new HangoutType(), $resourceconfig);
     return array('form' => $form->createView(), 'node' => $node);
 }
Exemplo n.º 19
0
 public function findDirectoryChildren(ResourceNode $parent)
 {
     $dql = "\n            SELECT file FROM Claroline\\CoreBundle\\Entity\\Resource\\File file\n            JOIN file.resourceNode node\n            JOIN node.parent parent\n            WHERE parent.id = {$parent->getId()}\n        ";
     $query = $this->_em->createQuery($dql);
     return $query->getResult();
 }
Exemplo n.º 20
0
 public function findLastIndex(ResourceNode $node)
 {
     $dql = '
         SELECT MAX(node.index)
         FROM Claroline\\CoreBundle\\Entity\\Resource\\ResourceNode node
         where node.parent = :node';
     $query = $this->_em->createQuery($dql);
     $query->setParameter('node', $node->getId());
     return $query->getSingleScalarResult();
 }
Exemplo n.º 21
0
 /**
  * Filters nodes that are the immediate children of a given node.
  *
  * @param ResourceNode $parent
  *
  * @return ResourceQueryBuilder
  */
 public function whereParentIs(ResourceNode $parent)
 {
     $this->addWhereClause('node.parent = :ar_parentId');
     $this->parameters[':ar_parentId'] = $parent->getId();
     return $this;
 }
Exemplo n.º 22
0
 /**
  * @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;
 }
Exemplo n.º 23
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>";
 }