Пример #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;
 }
Пример #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);
     }
 }
Пример #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);
 }
 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();
 }
Пример #5
0
 /**
  * Returns the last revision of a text.
  *
  * @param Text $text
  *
  * @return Revision
  */
 public function getLastRevision(Text $text)
 {
     $dql = "\n            SELECT r FROM Claroline\\CoreBundle\\Entity\\Resource\\Revision r\n            JOIN r.text t2\n            WHERE r.version = (SELECT MAX(r2.version) FROM Claroline\\CoreBundle\\Entity\\Resource\\Revision r2\n            JOIN r2.text t WHERE t.id = {$text->getId()})\n            and t2.id = {$text->getId()}\n        ";
     $query = $this->_em->createQuery($dql);
     return $query->getSingleResult();
 }
Пример #6
0
 public function setText(Text $text)
 {
     $this->text = $text;
     $text->addRevision($this);
 }
Пример #7
0
 /**
  * @Route(
  *     "/open/{text}",
  *     name="claro_text_open"
  * )
  *
  * Handles the text edition form submission.
  *
  * @param integer $textId
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function openAction(Text $text)
 {
     $revisionRepo = $this->getDoctrine()->getManager()->getRepository('ClarolineCoreBundle:Resource\\Revision');
     $collection = new ResourceCollection(array($text->getResourceNode()));
     $isGranted = $this->container->get('security.authorization_checker')->isGranted('EDIT', $collection);
     return $this->render('ClarolineCoreBundle:Text:index.html.twig', array('text' => $revisionRepo->getLastRevision($text)->getContent(), '_resource' => $text, 'isEditGranted' => $isGranted));
 }
Пример #8
0
 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();
 }