示例#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("create_text")
  *
  * @param CreateResourceEvent $event
  */
 public function onCreate(CreateResourceEvent $event)
 {
     $request = $this->container->get('request');
     $em = $this->container->get('doctrine.orm.entity_manager');
     $user = $this->container->get('security.token_storage')->getToken()->getUser();
     $keys = array_keys($request->request->all());
     $id = array_pop($keys);
     $form = $this->container->get('claroline.form.factory')->create(FormFactory::TYPE_RESOURCE_TEXT, array($id));
     $form->handleRequest($request);
     if ($form->isValid()) {
         $published = $form->get('published')->getData();
         $event->setPublished($published);
         $revision = new Revision();
         $revision->setContent($form->getData()->getText());
         $revision->setUser($user);
         $text = new Text();
         $text->setName($form->getData()->getName());
         $revision->setText($text);
         $em->persist($text);
         $em->persist($revision);
         $event->setResources(array($text));
         $event->stopPropagation();
         return;
     }
     $errorForm = $this->container->get('claroline.form.factory')->create(FormFactory::TYPE_RESOURCE_TEXT, array('text_' . rand(0, 1000000000)));
     $errorForm->setData($form->getData());
     $children = $form->getIterator();
     $errorChildren = $errorForm->getIterator();
     foreach ($children as $key => $child) {
         $errors = $child->getErrors();
         foreach ($errors as $error) {
             $errorChildren[$key]->addError($error);
         }
     }
     $content = $this->container->get('templating')->render('ClarolineCoreBundle:Text:createForm.html.twig', array('form' => $errorForm->createView(), 'resourceType' => 'text'));
     $event->setErrorFormContent($content);
     $event->stopPropagation();
 }
 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();
 }
 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();
 }