/**
  * @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);
 }
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;
 }
 /**
  * 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);
 }