Example #1
0
 public function create($content, $title, User $user)
 {
     $revision = new Revision();
     $revision->setContent($content);
     $revision->setUser($user);
     $text = new Text();
     $text->setName($title);
     $revision->setText($text);
     $this->om->persist($text);
     $this->om->persist($revision);
     $this->om->flush();
     return $text;
 }
Example #2
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $user = $this->getReference('user/' . $this->creator);
     foreach ($this->texts as $name) {
         $lipsumGenerator = $this->container->get('claroline.utilities.lipsum_generator');
         $revision = new Revision();
         $revision->setContent($lipsumGenerator->generateLipsum($this->words), true, 1023);
         $revision->setUser($user);
         $manager->persist($revision);
         $text = new Text();
         $text->setName($name);
         $manager->persist($text);
         $revision->setText($text);
         $text = $this->container->get('claroline.manager.resource_manager')->create($text, $manager->getRepository('ClarolineCoreBundle:Resource\\ResourceType')->findOneByName('text'), $user, $this->getReference('directory/' . $this->parent)->getWorkspace(), $this->getReference('directory/' . $this->parent));
         $this->addReference('text/' . $name, $text);
     }
 }
Example #3
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 #4
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 #5
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);
 }
 private function createText(Dropzone $dropzone, Drop $drop, $richText)
 {
     $em = $this->getDoctrine()->getManager();
     $parent = $this->getDropHiddenDirectory($dropzone, $drop);
     $revision = new Revision();
     $revision->setContent($richText);
     $revision->setUser($drop->getUser());
     $text = new Text();
     $text->setName($this->get('translator')->trans('Free text', array(), 'innova_collecticiel'));
     $revision->setText($text);
     $em->persist($text);
     $em->persist($revision);
     $resourceManager = $this->get('claroline.manager.resource_manager');
     $resourceManager->create($text, $resourceManager->getResourceTypeByName('text'), $dropzone->getResourceNode()->getCreator(), $dropzone->getResourceNode()->getWorkspace(), $parent);
     $em->flush();
     return $text->getResourceNode();
 }
 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);
 }
 private function createText(Dropzone $dropzone, Drop $drop, $richText, $titleText)
 {
     $em = $this->getDoctrine()->getManager();
     $parent = $this->getDropHiddenDirectory($dropzone, $drop);
     $revision = new Revision();
     $revision->setContent($richText);
     $revision->setUser($drop->getUser());
     $text = new Text();
     // Maintenant, on insère le TITRE qui est saisi.
     $text->setName($titleText);
     $revision->setText($text);
     $em->persist($text);
     $em->persist($revision);
     $resourceManager = $this->get('claroline.manager.resource_manager');
     $resourceManager->create($text, $resourceManager->getResourceTypeByName('text'), $dropzone->getResourceNode()->getCreator(), $dropzone->getResourceNode()->getWorkspace(), $parent);
     $em->flush();
     return $text->getResourceNode();
 }