예제 #1
0
 /**
  *  Getting the users that have the $selectedright rights
  *  Excluded the admin profil.
  * For a resource
  *
  * @return array UserIds array of user objects|array
  */
 public function getUsersForResourceByRights(ResourceNode $node, $selectedright = 'open', $excludeAdmin = true)
 {
     //        $this->container->get('icap.manager.dropzone_voter')->isAllowToEdit($dropzone);
     //getting the ressource node
     //   $ressourceNode = $dropzone->getResourceNode();
     // getting the rights of the ressource node
     $rights = $node->getRights();
     // will contain the user's ids.
     $userIds = array();
     $test = array();
     // searching for roles with the 'open' right
     foreach ($rights as $ressourceRight) {
         $role = $ressourceRight->getRole();
         //  current role
         $mask = $ressourceRight->getMask();
         // current mask
         // getting decoded rights.
         $decodedRights = $this->maskManager->decodeMask($mask, $node->getResourceType());
         $checkrights = array_key_exists($selectedright, $decodedRights) && $decodedRights[$selectedright] == true;
         // if this role is allowed to $selectedright (and this role is not an Admin role)
         $checkrights = $excludeAdmin ? $checkrights && $role->getName() != 'ROLE_ADMIN' : $checkrights;
         if ($checkrights) {
             $users = $role->getUsers();
             foreach ($users as $user) {
                 array_push($userIds, $user);
             }
         }
     }
     //$users = array_unique($users);
     return $userIds;
 }
 /**
  * @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;
 }
 /**
  * @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("/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);
 }
 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;
 }
 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 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);
 }
예제 #8
0
 public function result($title, User $creator, $total = 20)
 {
     $result = new Result();
     $result->setTotal($total);
     if (!$this->resultType) {
         $this->resultType = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceType')->findOneByName('claroline_result');
     }
     $node = new ResourceNode();
     $node->setName($title);
     $node->setCreator($creator);
     $node->setResourceType($this->resultType);
     $node->setWorkspace($creator->getPersonalWorkspace());
     $node->setClass('Claroline\\ResultBundle\\Entity\\Result');
     $node->setGuid(time());
     $result->setResourceNode($node);
     $this->om->persist($result);
     $this->om->persist($node);
     return $result;
 }
예제 #9
0
 public function lesson($title, User $creator)
 {
     $lesson = new Lesson();
     if (!$this->lessonType) {
         $this->lessonType = new ResourceType();
         $this->lessonType->setName('icap_lesson');
         $this->om->persist($this->lessonType);
     }
     $node = new ResourceNode();
     $node->setName($title);
     $node->setCreator($creator);
     $node->setResourceType($this->lessonType);
     $node->setWorkspace($creator->getPersonalWorkspace());
     $node->setClass('Icap\\LessonBundle\\Entity\\Lesson');
     $node->setGuid(time());
     $lesson->setResourceNode($node);
     $this->om->persist($lesson);
     $this->om->persist($node);
     $this->om->flush();
     return $lesson;
 }
예제 #10
0
 /**
  * needed to create a functional simupoll resource.
  */
 public function simupoll($title, User $creator)
 {
     $simupoll = new Simupoll();
     $simupoll->setTitle($title);
     if (!$this->simupollType) {
         $this->simupollType = new ResourceType();
         $this->simupollType->setName('claroline_result');
         $this->om->persist($this->simupollType);
     }
     $node = new ResourceNode();
     $node->setName($title);
     $node->setCreator($creator);
     $node->setResourceType($this->simupollType);
     $node->setWorkspace($creator->getPersonalWorkspace());
     $node->setClass('CPASimUSante\\SimupollBundle\\Entity\\Simupoll');
     $node->setGuid(time());
     $simupoll->setResourceNode($node);
     $this->om->persist($simupoll);
     $this->om->persist($node);
     return $simupoll;
 }
 /**
  * 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);
 }
예제 #12
0
 private function uploadFile(\DirectoryIterator $file, ResourceNode $parent, array $perms, $published = true)
 {
     $workspaceId = $parent->getWorkspace()->getId();
     $entityFile = new File();
     $fileName = $file->getFilename();
     $size = @filesize($file);
     $extension = pathinfo($fileName, PATHINFO_EXTENSION);
     $mimeType = $this->container->get('claroline.utilities.mime_type_guesser')->guess($extension);
     $hashName = 'WORKSPACE_' . $workspaceId . DIRECTORY_SEPARATOR . $this->container->get('claroline.utilities.misc')->generateGuid() . "." . $extension;
     $destination = $this->container->getParameter('claroline.param.files_directory') . DIRECTORY_SEPARATOR . $hashName;
     copy($file->getPathname(), $destination);
     $entityFile->setSize($size);
     $entityFile->setName($fileName);
     $entityFile->setHashName($hashName);
     $entityFile->setMimeType($mimeType);
     return $this->resourceManager->create($entityFile, $this->resourceManager->getResourceTypeByName('file'), $this->tokenStorage->getToken()->getUser(), $parent->getWorkspace(), $parent, null, $perms, $published);
 }
예제 #13
0
 /**
  * @param string        $title
  * @param Question[]    $questions
  * @param User          $user
  *
  * @return Exercise
  */
 public function exercise($title, array $questions = [], User $user = null)
 {
     $exercise = new Exercise();
     if ($user) {
         if (!isset($this->exoType)) {
             $this->exoType = new ResourceType();
             $this->exoType->setName('exercise');
             $this->om->persist($this->exoType);
         }
         $node = new ResourceNode();
         $node->setName($title);
         $node->setCreator($user);
         $node->setResourceType($this->exoType);
         $node->setWorkspace($user->getPersonalWorkspace());
         $node->setClass('UJM\\ExoBundle\\Entity\\Exercise');
         $node->setGuid(time());
         $exercise->setResourceNode($node);
         $this->om->persist($node);
     }
     $this->om->persist($exercise);
     for ($i = 0, $max = count($questions); $i < $max; ++$i) {
         $step = new Step();
         $step->setText('step');
         $step->setOrder($i);
         // Add step to the exercise
         $exercise->addStep($step);
         $this->om->persist($step);
         $stepQuestion = new StepQuestion();
         $stepQuestion->setStep($step);
         $stepQuestion->setQuestion($questions[$i]);
         $stepQuestion->setOrdre(0);
         $this->om->persist($stepQuestion);
     }
     return $exercise;
 }
예제 #14
0
 /**
  * Find ResourceRights for each descendant of a resource for a role.
  *
  * @param \Claroline\CoreBundle\Entity\Resource\ResourceNode $resource
  * @param \Claroline\CoreBundle\Entity\Role                  $role
  *
  * @return array
  */
 public function findRecursiveByResourceAndRole(ResourceNode $resource, Role $role)
 {
     $dql = "\n            SELECT rights, role, resource\n            FROM Claroline\\CoreBundle\\Entity\\Resource\\ResourceRights rights\n            JOIN rights.resourceNode resource\n            JOIN rights.role role\n            WHERE resource.path LIKE :path AND role.name = :roleName\n        ";
     $query = $this->_em->createQuery($dql);
     $query->setParameter('path', $resource->getPath() . '%');
     $query->setParameter('roleName', $role->getName());
     return $query->getResult();
 }
예제 #15
0
 /**
  * @param \Claroline\CoreBundle\Entity\Resource\ResourceNode $directory
  * @param \Claroline\CoreBundle\Entity\Resource\ResourceNode $directoryCopy
  * @param \Claroline\CoreBundle\Entity\User $user
  * @param array $workspaceRoles
  */
 private function duplicateDirectoryContent(ResourceNode $directory, ResourceNode $directoryCopy, User $user, array $workspaceRoles)
 {
     $children = $directory->getChildren();
     $copies = array();
     $resourcesErrors = array();
     foreach ($children as $child) {
         try {
             $copy = $this->resourceManager->copy($child, $directoryCopy, $user, false, false);
             $copies[] = $copy;
         } catch (NotPopulatedEventException $e) {
             $resourcesErrors[] = array('resourceName' => $child->getName(), 'resourceType' => $child->getResourceType()->getName(), 'type' => 'copy', 'error' => $e->getMessage());
             continue;
         }
         /*** Copies rights ***/
         $this->duplicateRights($child, $copy->getResourceNode(), $workspaceRoles);
         /*** Recursive call for a directory ***/
         if ($child->getResourceType()->getName() === 'directory') {
             $errors = $this->duplicateDirectoryContent($child, $copy->getResourceNode(), $user, $workspaceRoles);
             $resourcesErrors = array_merge_recursive($resourcesErrors, $errors);
         }
     }
     $this->linkResourcesArray($copies);
     $this->om->flush();
     return $resourcesErrors;
 }
예제 #16
0
 public function getRealTarget(ResourceNode $node, $throwException = true)
 {
     if ($node->getClass() === 'Claroline\\CoreBundle\\Entity\\Resource\\ResourceShortcut') {
         $resource = $this->getResourceFromNode($node);
         if ($resource === null) {
             if ($throwException) {
                 throw new \Exception('The resource was removed.');
             }
             return null;
         }
         $node = $resource->getTarget();
         if ($node === null) {
             if ($throwException) {
                 throw new \Exception('The node target was removed.');
             }
             return null;
         }
     }
     return $node;
 }
예제 #17
0
 public function createDefaultPostRights(ResourceNode $node)
 {
     $workspace = $node->getWorkspace();
     $resourceType = $node->getResourceType();
     $role = $this->roleRepo->findOneBaseWorkspaceRole('COLLABORATOR', $workspace);
     if (!is_null($role)) {
         $postDecoder = $this->maskManager->getDecoder($resourceType, 'post');
         if (!is_null($postDecoder)) {
             $rights = $this->rightsManager->getOneByRoleAndResource($role, $node);
             $value = $postDecoder->getValue();
             $mask = $rights->getMask();
             $permissions = $mask | $value;
             $this->rightsManager->editPerms($permissions, $role, $node);
         }
     }
 }
예제 #18
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());
 }
 /**
  * @EXT\Route(
  *     "/node/{node}/icon/edit",
  *     name="claro_resource_icon_edit",
  *     options={"expose"=true}
  * )
  * @EXT\Template("ClarolineCoreBundle:Resource:iconEditForm.html.twig")
  * @EXT\ParamConverter("user", options={"authenticatedUser" = true})
  *
  * Changes the resource properties.
  *
  * @param ResourceNode $node
  * @param \Claroline\CoreBundle\Entity\User $user
  * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException
  * @return SResponse
  */
 public function iconEditAction(ResourceNode $node, User $user)
 {
     $collection = new ResourceCollection(array($node));
     $this->checkAccess('EDIT', $collection);
     $creatorUsername = $node->getCreator()->getUsername();
     $form = $this->formFactory->create(new ResourceIconType($creatorUsername), $node);
     $form->handleRequest($this->request);
     if ($form->isValid()) {
         $file = $form->get('newIcon')->getData();
         if ($file) {
             $this->resourceManager->changeIcon($node, $file);
         }
         $arrayNode = $this->resourceManager->toArray($node, $this->tokenStorage->getToken());
         return new JsonResponse($arrayNode);
     }
     $isDir = $node->getResourceType()->getName() === 'directory';
     return array('form' => $form->createView(), 'nodeId' => $node->getId(), 'isDir' => $isDir);
 }
예제 #20
0
 private function getIcon(ResourceNode $resourceNode, &$_files)
 {
     $icon = $resourceNode->getIcon();
     if ($icon->getMimeType() !== 'custom') {
         return null;
     }
     $iconPath = $this->container->getParameter('claroline.param.web_directory') . '/' . $icon->getRelativeUrl();
     $uid = uniqid() . '.' . pathinfo($iconPath, PATHINFO_EXTENSION);
     if (file_exists($iconPath)) {
         $_files[$uid] = $iconPath;
         return $uid;
     }
     return null;
 }
예제 #21
0
 /**
  * @param File $template
  * @param User $owner
  */
 public function importResources(File $template, User $owner, ResourceNode $directory)
 {
     $data = $this->container->get('claroline.manager.workspace_manager')->getTemplateData($template, true);
     $data = $this->reorderData($data);
     $workspace = $directory->getWorkspace();
     $this->om->startFlushSuite();
     $this->setImporters($template, $workspace->getCreator());
     $resourceImporter = $this->container->get('claroline.tool.resource_manager_importer');
     if (isset($data['tools']) && is_array($data['tools'])) {
         foreach ($data['tools'] as $dataTool) {
             $tool = $dataTool['tool'];
             if ($tool['type'] === 'resource_manager') {
                 $resourceImporter->import($tool, $workspace, [], $this->container->get('claroline.manager.resource_manager')->getResourceFromNode($directory), false);
                 break;
             }
         }
     }
     $this->om->endFlushSuite();
     $this->importRichText($directory->getWorkspace(), $data);
     $this->container->get('claroline.manager.workspace_manager')->removeTemplate($template);
 }
예제 #22
0
 /**
  * @EXT\Route(
  *     "/{node}/rights/users/with/rights/ordered/by/{orderedBy}/order/{order}/page/{page}/max/{max}/form/search/{search}",
  *     name="claro_resources_rights_users_with_rights_form",
  *     options={"expose"=true},
  *     defaults={"search"="","ordered"="firstName","order"="ASC","page"=1,"max"=50}
  * )
  * @EXT\Template("ClarolineCoreBundle:Resource:resourcesRightsUsersWithRightsForm.html.twig")
  *
  * Displays the resource rights form for all users.
  *
  * @param ResourceNode $node
  * @param string $search
  * @param string $orderedBy
  * @param string $order
  * @param int $page
  * @param int $max
  *
  * @return Response
  */
 public function resourcesRightsUsersWithRightsFormAction(ResourceNode $node, $search = '', $orderedBy = 'firstName', $order = 'ASC', $page = 1, $max = 50)
 {
     $collection = new ResourceCollection(array($node));
     $this->checkAccess('ADMINISTRATE', $collection);
     $isDir = $node->getResourceType()->getName() === 'directory';
     $resourceType = $node->getResourceType();
     $mask = $this->maskManager->decodeMask($resourceType->getDefaultMask(), $resourceType);
     $users = empty($search) ? $this->userManager->getUsersWithRights($node, $orderedBy, $order, $page, $max) : $this->userManager->getSearchedUsersWithRights($node, $search, $orderedBy, $order, $page, $max);
     $roleKeys = array();
     $usersRoles = array();
     $usersRights = array();
     foreach ($users as $user) {
         $roleKeys[] = $user->getUsername();
     }
     $usersRolesRaw = $this->roleManager->getUserRolesByTranslationKeys($roleKeys);
     foreach ($usersRolesRaw as $userRole) {
         $usersRoles[$userRole->getTranslationKey()] = $userRole;
     }
     $userRolesRights = $this->rightsManager->getUserRolesResourceRights($node, $roleKeys);
     foreach ($userRolesRights as $right) {
         $usersRights[$right->getRole()->getTranslationKey()] = $right;
     }
     return array('resource' => $node, 'isDir' => $isDir, 'mask' => $mask, 'users' => $users, 'usersRoles' => $usersRoles, 'usersRights' => $usersRights, 'orderedBy' => $orderedBy, 'order' => $order, 'max' => $max, 'search' => $search);
 }
예제 #23
0
 /**
  * @param Configuration $configuration
  * @param User $owner
  */
 public function importResources(Configuration $configuration, User $owner, ResourceNode $directory)
 {
     $configuration->setOwner($owner);
     $data = $configuration->getData();
     $data = $this->reorderData($data);
     $this->data = $data;
     $this->workspace = $directory->getWorkspace();
     $this->om->startFlushSuite();
     $this->setImporters($configuration, $data);
     $resourceImporter = $this->container->get('claroline.tool.resource_manager_importer');
     if (isset($data['tools']) && is_array($data['tools'])) {
         foreach ($data['tools'] as $dataTool) {
             $tool = $dataTool['tool'];
             if ($tool['type'] === 'resource_manager') {
                 $resourceImporter->import($tool, $this->workspace, array(), $this->container->get('claroline.manager.resource_manager')->getResourceFromNode($directory), false);
                 break;
             }
         }
     }
     $this->om->endFlushSuite();
 }
 /**
  * Copies a file (no persistence).
  *
  * @param File $resource
  *
  * @return File
  */
 private function copy(File $resource, ResourceNode $destParent)
 {
     $ds = DIRECTORY_SEPARATOR;
     $workspace = $destParent->getWorkspace();
     $newFile = new File();
     $newFile->setSize($resource->getSize());
     $newFile->setName($resource->getName());
     $newFile->setMimeType($resource->getMimeType());
     $hashName = 'WORKSPACE_' . $workspace->getId() . $ds . $this->container->get('claroline.utilities.misc')->generateGuid() . '.' . pathinfo($resource->getHashName(), PATHINFO_EXTENSION);
     $newFile->setHashName($hashName);
     $fileDir = $this->container->getParameter('claroline.param.files_directory');
     $filePath = $fileDir . $ds . $resource->getHashName();
     $newPath = $fileDir . $ds . $hashName;
     $workspaceDir = $fileDir . $ds . 'WORKSPACE_' . $workspace->getId();
     if (!is_dir($workspaceDir)) {
         mkdir($workspaceDir);
     }
     copy($filePath, $newPath);
     return $newFile;
 }
예제 #25
0
 private function isWorkspaceManager(ResourceNode $node, array $roles)
 {
     $rolenames = array();
     foreach ($roles as $role) {
         if ($role instanceof \Symfony\Component\Security\Core\Role\Role) {
             $rolenames[] = $role->getRole();
         } else {
             $rolenames[] = $role;
         }
     }
     $isWorkspaceManager = false;
     $ws = $node->getWorkspace();
     $managerRole = 'ROLE_WS_MANAGER_' . $ws->getGuid();
     if (in_array($managerRole, $rolenames)) {
         $isWorkspaceManager = true;
     }
     if (in_array('ROLE_ADMIN', $rolenames)) {
         $isWorkspaceManager = true;
     }
     return $isWorkspaceManager;
 }
예제 #26
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;
 }
예제 #27
0
 /**
  * Checks if a resource whose type is $type
  * can be created in the directory $resource by the $token.
  *
  * @param $type
  * @param ResourceNode                                     $node
  * @param TokenInterface                                   $token
  * @param \Claroline\CoreBundle\Entity\Workspace\Workspace $workspace
  *
  * @return array
  */
 public function checkCreation($type, ResourceNode $node, TokenInterface $token, Workspace $workspace)
 {
     $errors = array();
     //even the workspace manager can't break the file limit.
     $workspace = $node->getWorkspace();
     $isLimitExceeded = $this->resourceManager->checkResourceLimitExceeded($workspace);
     if ($isLimitExceeded) {
         $currentCount = $this->workspaceManager->countResources($workspace);
         $errors[] = $this->translator->trans('resource_limit_exceeded', array('%current%' => $currentCount, '%max%' => $workspace->getMaxUploadResources()), 'platform');
     }
     //if I am the manager, I can do whatever I want
     if ($this->isWorkspaceManager($workspace, $token)) {
         return $errors;
     }
     //otherwise we need to check
     $rightsCreation = $this->repository->findCreationRights($this->ut->getRoles($token), $node);
     if (!$this->canCreate($rightsCreation, $type)) {
         $errors[] = $this->translator->trans('resource_creation_wrong_type', array('%path%' => $node->getPathForDisplay(), '%type%' => $this->translator->trans(strtolower($type), array(), 'resource')), 'platform');
     }
     return $errors;
 }
예제 #28
0
 /**
  * Return the resource rights as a readable array. This array can be used for the resource creation.
  * @param ResourceNode $node
  *
  * @return array
  */
 public function getCustomRoleRights(ResourceNode $node)
 {
     $perms = array();
     foreach ($node->getRights() as $right) {
         //if not ROLE_ANONYMOUS nor ROLE_USER because they're added automatically in ResourceManager::createRights
         if ($right->getRole()->getName() !== 'ROLE_ANONYMOUS' && $right->getRole()->getName() !== 'ROLE_USER') {
             $rolePerms = $this->maskManager->decodeMask($right->getMask(), $node->getResourceType());
             $perms[$right->getRole()->getName()] = $rolePerms;
             $perms[$right->getRole()->getName()]['role'] = $right->getRole();
             //no implementation for rights creations yet
             $perms[$right->getRole()->getName()]['create'] = array();
         }
     }
     return $perms;
 }
예제 #29
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;
 }
예제 #30
0
 /**
  * Replace a node icon.
  *
  * @param \Claroline\CoreBundle\Entity\Resource\ResourceNode $resource
  * @param \Claroline\CoreBundle\Entity\Resource\ResourceIcon $icon
  *
  * @return \Claroline\CoreBundle\Entity\Resource\ResourceNode
  */
 public function replace(ResourceNode $resource, ResourceIcon $icon)
 {
     $this->om->startFlushSuite();
     $oldIcon = $resource->getIcon();
     if (!$oldIcon->isShortcut()) {
         $oldShortcutIcon = $oldIcon->getShortcutIcon();
         $shortcutIcon = $icon->getShortcutIcon();
         if (!is_null($oldShortcutIcon) && !is_null($shortcutIcon)) {
             $nodes = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceNode')->findBy(array('icon' => $oldShortcutIcon));
             foreach ($nodes as $node) {
                 $node->setIcon($shortcutIcon);
                 $this->om->persist($node);
             }
         }
     }
     $this->delete($oldIcon);
     $resource->setIcon($icon);
     $this->om->persist($resource);
     $this->om->endFlushSuite();
     return $resource;
 }