Example #1
0
 /**
  * @Route(
  *     "/edit/{old}",
  *     name="claro_text_edit"
  * )
  *
  * Handles the text edition form submission.
  *
  * @param integer $textId
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function editAction(Text $old)
 {
     $collection = new ResourceCollection(array($old->getResourceNode()));
     $this->checkAccess('EDIT', $collection);
     $request = $this->get('request');
     $user = $this->get('security.token_storage')->getToken()->getUser();
     $text = $request->request->get('content');
     $em = $this->getDoctrine()->getManager();
     $version = $old->getVersion();
     $revision = new Revision();
     $revision->setContent($text);
     $revision->setText($old);
     $revision->setVersion(++$version);
     $revision->setUser($user);
     $em->persist($revision);
     $old->setVersion($version);
     $em->flush();
     $route = $this->get('router')->generate('claro_resource_open', array('resourceType' => 'text', 'node' => $old->getResourceNode()->getId()));
     return new RedirectResponse($route);
 }
Example #2
0
 /**
  * @Route(
  *     "/edit/{old}",
  *     name="claro_text_edit"
  * )
  *
  * Handles the text edition form submission.
  *
  * @param integer $textId
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function editAction(Text $old)
 {
     $collection = new ResourceCollection(array($old->getResourceNode()));
     $this->checkAccess('EDIT', $collection);
     $request = $this->get('request');
     $user = $this->get('security.token_storage')->getToken()->getUser();
     $text = $request->request->get('content');
     $em = $this->getDoctrine()->getManager();
     $version = $old->getVersion();
     $revision = new Revision();
     $revision->setContent($text);
     $revision->setText($old);
     $revision->setVersion(++$version);
     $revision->setUser($user);
     $em->persist($revision);
     $old->setVersion($version);
     $em->flush();
     $workspace = $old->getResourceNode()->getWorkspace();
     $usersToNotify = $workspace ? $this->container->get('claroline.manager.user_manager')->getUsersByWorkspaces(array($workspace), null, null, false) : array();
     $this->get('claroline.event.event_dispatcher')->dispatch('log', 'Log\\LogEditResourceText', array('node' => $old->getResourceNode(), 'usersToNotify' => $usersToNotify));
     $route = $this->get('router')->generate('claro_resource_open', array('resourceType' => 'text', 'node' => $old->getResourceNode()->getId()));
     return new RedirectResponse($route);
 }
Example #3
0
 /**
  * @DI\Observe("copy_text")
  *
  * @param CopyResourceEvent $event
  */
 public function onCopy(CopyResourceEvent $event)
 {
     $em = $this->container->get('doctrine.orm.entity_manager');
     $resource = $event->getResource();
     $revisions = $resource->getRevisions();
     $copy = new Text();
     $copy->setVersion($resource->getVersion());
     foreach ($revisions as $revision) {
         $rev = new Revision();
         $rev->setVersion($revision->getVersion());
         $rev->setContent($revision->getContent());
         $rev->setUser($revision->getUser());
         $rev->setText($copy);
         $em->persist($rev);
     }
     $event->setCopy($copy);
 }
 protected static function createText($name, $revisionNumber, ResourceType $type, User $creator, Directory $parent)
 {
     $text = self::prepareResource(new Text(), $type, $creator, $parent->getResourceNode()->getWorkspace(), $name, 'text/mime', $parent->getResourceNode());
     self::create($name, $text);
     $revision = new Revision();
     $revision->setVersion($revisionNumber);
     $revision->setContent($name . 'Content');
     $revision->setText($text);
     self::create("revision/{$text->getName()}-{$revisionNumber}", $revision);
 }