Пример #1
0
 public function onCreate(CreateResourceEvent $event)
 {
     $request = $this->container->get('request');
     $form = $this->container->get('form.factory')->create(new ExerciseType(), new Exercise());
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em = $this->container->get('doctrine.orm.entity_manager');
         $user = $this->container->get('security.token_storage')->getToken()->getUser();
         $exercise = $form->getData();
         $exercise->setName($exercise->getTitle());
         $exercise->setDateCreate(new \Datetime());
         $exercise->setNbQuestionPage(1);
         $exercise->setPublished(FALSE);
         $subscription = new Subscription($user, $exercise);
         $subscription->setAdmin(true);
         $subscription->setCreator(true);
         $em->persist($exercise);
         $em->persist($subscription);
         $event->setResources(array($exercise));
         $event->stopPropagation();
         return;
     }
     $content = $this->container->get('templating')->render('UJMExoBundle:Exercise:new.html.twig', array('resourceType' => 'ujm_exercise', 'form' => $form->createView()));
     $event->setErrorFormContent($content);
     $event->stopPropagation();
 }
Пример #2
0
 /**
  * @DI\Observe("create_icap_blog")
  *
  * @param CreateResourceEvent $event
  */
 public function onCreate(CreateResourceEvent $event)
 {
     $form = $this->container->get('form.factory')->create(new BlogType(), new Blog());
     $form->bind($this->request);
     if ($form->isValid()) {
         $event->setResources([$form->getData()]);
         $event->stopPropagation();
         return;
     }
     $content = $this->container->get('templating')->render('ClarolineCoreBundle:Resource:createForm.html.twig', ['form' => $form->createView(), 'resourceType' => 'icap_blog']);
     $event->setErrorFormContent($content);
     $event->stopPropagation();
 }
Пример #3
0
 /**
  * @DI\Observe("create_icap_dropzone")
  *
  * @param CreateResourceEvent $event
  */
 public function onCreate(CreateResourceEvent $event)
 {
     $form = $this->container->get('form.factory')->create(new DropzoneType(), new Dropzone());
     $form->handleRequest($this->request);
     if ($form->isValid()) {
         $dropzone = $form->getData();
         $event->setResources([$dropzone]);
     } else {
         $content = $this->container->get('templating')->render('ClarolineCoreBundle:Resource:createForm.html.twig', ['form' => $form->createView(), 'resourceType' => 'icap_dropzone']);
         $event->setErrorFormContent($content);
     }
     $event->stopPropagation();
 }
Пример #4
0
 public function onCreate(CreateResourceEvent $event)
 {
     $request = $this->container->get('request');
     $form = $this->container->get('form.factory')->create(new LessonType(), new Lesson());
     $form->handleRequest($request);
     if ($form->isValid()) {
         $lesson = $form->getData();
         $event->setResources(array($lesson));
     } else {
         $content = $this->container->get('templating')->render('ClarolineCoreBundle:Resource:create_form.html.twig', array('form' => $form->createView(), 'resourceType' => 'icap_lesson'));
         $event->setErrorFormContent($content);
     }
     $event->stopPropagation();
 }
Пример #5
0
 /**
  * @DI\Observe("create_claroline_chat_room")
  *
  * @param CreateResourceEvent $event
  */
 public function onCreate(CreateResourceEvent $event)
 {
     $form = $this->formFactory->create(new ChatRoomType(), new ChatRoom());
     $form->handleRequest($this->request);
     if ($form->isValid()) {
         $chatRoom = $form->getData();
         $this->om->persist($chatRoom);
         $event->setResources(array($chatRoom));
         $event->stopPropagation();
         return;
     }
     $content = $this->templating->render('ClarolineCoreBundle:Resource:createForm.html.twig', array('form' => $form->createView(), 'resourceType' => 'claroline_chat_room'));
     $event->setErrorFormContent($content);
     $event->stopPropagation();
 }
Пример #6
0
 /**
  * @DI\Observe("create_hevinci_url")
  *
  * @param CreateResourceEvent $event
  */
 public function onCreate(CreateResourceEvent $event)
 {
     $form = $this->formFactory->create(new UrlType(), new Url());
     $form->handleRequest($this->request);
     if ($form->isValid()) {
         $url = $form->getData();
         $this->urlManager->setUrl($url);
         $event->setResources([$url]);
         $event->stopPropagation();
         return;
     }
     $content = $this->templating->render('ClarolineCoreBundle:Resource:createForm.html.twig', ['form' => $form->createView(), 'resourceType' => $event->getResourceType()]);
     $event->setErrorFormContent($content);
     $event->stopPropagation();
 }
 /**
  * when resource creation modal form is sent
  *
  * @param CreateFormResourceEvent $event
  */
 public function onCreate(CreateResourceEvent $event)
 {
     $request = $this->container->get('request');
     $form = $this->container->get('form.factory')->create(new H5pType(), new H5p(), array('inside' => false));
     $form->handleRequest($request);
     if ($form->isValid()) {
         $h5pclaroline = $form->getData();
         $event->setResources(array($h5pclaroline));
         $event->stopPropagation();
         return;
     }
     $content = $this->container->get('templating')->render('ClarolineCoreBundle:Resource:createForm.html.twig', array('form' => $form->createView(), 'resourceType' => 'cpasimusante_h5pclaroline'));
     $event->setErrorFormContent($content);
     $event->stopPropagation();
 }
 public function onCreate(CreateResourceEvent $event)
 {
     $request = $this->container->get('request');
     $form = $this->container->get('form.factory')->create(new SimupollType(), new Simupoll(), array('inside' => false));
     $form->handleRequest($request);
     if ($form->isValid()) {
         $simupoll = $form->getData();
         //update name
         $simupoll->setName($simupoll->getTitle());
         $event->setResources(array($simupoll));
         $event->stopPropagation();
     }
     $content = $this->container->get('templating')->render('CPASimUSanteSimupollBundle:Simupoll:createForm.html.twig', array('form' => $form->createView(), 'resourceType' => $event->getResourceType()));
     $event->setErrorFormContent($content);
     $event->stopPropagation();
 }
Пример #9
0
 public function onCreate(CreateResourceEvent $event)
 {
     $request = $this->container->get('request');
     $form = $this->container->get('form.factory')->create(new ForumType(), new Forum());
     $form->handleRequest($request);
     if ($form->isValid()) {
         $forum = $form->getData();
         $this->container->get('claroline.manager.forum_manager')->createCategory($forum, $forum->getName(), false);
         $event->setResources(array($forum));
         $event->stopPropagation();
         return;
     }
     $content = $this->container->get('templating')->render('ClarolineCoreBundle:Resource:createForm.html.twig', array('form' => $form->createView(), 'resourceType' => 'claroline_forum'));
     $event->setErrorFormContent($content);
     $event->stopPropagation();
 }
 /**
  * @DI\Observe("create_innova_audio_recorder")
  * @param CreateResourceEvent $event
  */
 public function onCreate(CreateResourceEvent $event)
 {
     $request = $this->container->get('request');
     $formData = $request->request->all();
     $blob = $request->files->get('file');
     $workspace = $event->getParent()->getWorkspace();
     $result = $this->arm->uploadFileAndCreateResource($formData, $blob, $workspace);
     if (!is_null($result['errors']) && count($result['errors']) > 0) {
         $msg = $result['errors'][0];
         $event->setErrorFormContent($msg);
     }
     $file = $result['file'];
     $event->setPublished(true);
     $event->setResourceType('file');
     $event->setResources(array($file));
     $event->stopPropagation();
 }
 /**
  * when resource creation modal form is sent.
  *
  * @param CreateFormResourceEvent $event
  */
 public function onCreate(CreateResourceEvent $event)
 {
     $request = $this->container->get('request');
     $form = $this->container->get('form.factory')->create(new ItemSelectorType(), new ItemSelector(), ['inside' => false]);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $itemselector = $form->getData();
         //update name
         $itemselector->setName($itemselector->getTitle());
         $event->setResources([$itemselector]);
         $event->stopPropagation();
         return;
     }
     $content = $this->container->get('templating')->render('ClarolineCoreBundle:Resource:createForm.html.twig', ['form' => $form->createView(), 'resourceType' => 'cpasimusante_itemselector']);
     $event->setErrorFormContent($content);
     $event->stopPropagation();
 }
 /**
  * @DI\Observe("create_cpasimusante_hangout")
  *
  * @param CreateResourceEvent $event
  */
 public function onCreate(CreateResourceEvent $event)
 {
     $request = $this->container->get('request');
     $form = $this->container->get('form.factory')->create(new HangoutType(), new Hangout());
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em = $this->container->get('doctrine.orm.entity_manager');
         $resource = $form->getData();
         $em->persist($resource);
         $event->setResources(array($resource));
         $event->stopPropagation();
         //exit the modal
         return;
     }
     $content = $this->container->get('templating')->render('CPASimUSanteGhangoutBundle:Hangout:createForm.html.twig', array('form' => $form->createView(), 'resourceType' => $event->getResourceType()));
     $event->setErrorFormContent($content);
     $event->stopPropagation();
 }
Пример #13
0
 /**
  * @DI\Observe("create_ujm_exercise")
  *
  * @param CreateResourceEvent $event
  */
 public function onCreate(CreateResourceEvent $event)
 {
     $request = $this->container->get('request');
     $form = $this->container->get('form.factory')->create(new ExerciseType());
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em = $this->container->get('doctrine.orm.entity_manager');
         $user = $this->container->get('security.token_storage')->getToken()->getUser();
         $exercise = $form->getData();
         $event->setPublished((bool) $form->get('published')->getData());
         $this->container->get('ujm.exo.subscription_manager')->subscribe($exercise, $user);
         $em->persist($exercise);
         $event->setResources([$exercise]);
     } else {
         $content = $this->container->get('templating')->render('ClarolineCoreBundle:Resource:createForm.html.twig', ['resourceType' => 'ujm_exercise', 'form' => $form->createView()]);
         $event->setErrorFormContent($content);
     }
     $event->stopPropagation();
 }
Пример #14
0
 /**
  * Fired when a new ResourceNode of type Path is opened
  * @param \Claroline\CoreBundle\Event\CreateResourceEvent $event
  */
 public function onCreate(CreateResourceEvent $event)
 {
     // Create form
     $form = $this->container->get('form.factory')->create('innova_path', new Path());
     // Try to process form
     $request = $this->container->get('request');
     $form->handleRequest($request);
     if ($form->isValid()) {
         $path = $form->getData();
         $published = $form->get('published')->getData();
         $event->setPublished($published);
         $path->initializeStructure();
         // Send new path to dispatcher through event object
         $event->setResources(array($path));
     } else {
         $content = $this->container->get('templating')->render('ClarolineCoreBundle:Resource:createForm.html.twig', array('form' => $form->createView(), 'resourceType' => 'innova_path'));
         $event->setErrorFormContent($content);
     }
     $event->stopPropagation();
 }
 /**
  * @DI\Observe("create_innova_media_resource")
  *
  * @param CreateResourceEvent $event
  *
  * @throws \Exception
  */
 public function onCreate(CreateResourceEvent $event)
 {
     // Create form
     $form = $this->container->get('form.factory')->create(new MediaResourceType(), new MediaResource());
     // Try to process form
     $request = $this->container->get('request');
     $form->submit($request);
     if ($form->isValid()) {
         $mediaResource = $form->getData();
         $file = $form['file']->getData();
         $workspace = $event->getParent()->getWorkspace();
         $this->container->get('innova_media_resource.manager.media_resource')->createMediaResourceDefaultOptions($mediaResource);
         $this->container->get('innova_media_resource.manager.media_resource')->handleMediaResourceMedia($file, $mediaResource, $workspace);
         // Send new MediaResource to dispatcher through event object
         $event->setResources([$mediaResource]);
     } else {
         $content = $this->container->get('templating')->render('ClarolineCoreBundle:Resource:createForm.html.twig', ['form' => $form->createView(), 'resourceType' => 'innova_media_resource']);
         $event->setErrorFormContent($content);
     }
     $event->stopPropagation();
     return;
 }
Пример #16
0
 /**
  * @Observe("create_activity")
  *
  * @param CreateResourceEvent $event
  */
 public function onCreate(CreateResourceEvent $event)
 {
     $form = $this->formFactory->create(new ActivityType(), new Activity());
     $form->handleRequest($this->request);
     if ($form->isValid()) {
         $published = $form->get('published')->getData();
         $event->setPublished($published);
         $activity = $form->getData();
         $activity->setName($activity->getTitle());
         $activityParameters = new ActivityParameters();
         $activityParameters->setActivity($activity);
         $activity->setParameters($activityParameters);
         $event->setResources(array($activity));
         $event->stopPropagation();
         return;
     }
     $content = $this->templating->render('ClarolineCoreBundle:Resource:createForm.html.twig', array('form' => $form->createView(), 'resourceType' => 'activity'));
     $event->setErrorFormContent($content);
     $event->stopPropagation();
 }
Пример #17
0
 /**
  * @DI\Observe("create_claroline_web_resource")
  *
  * @param CreateResourceEvent $event
  */
 public function onCreate(CreateResourceEvent $event)
 {
     $request = $this->container->get('request');
     $workspace = $event->getParent()->getWorkspace();
     $form = $this->container->get('form.factory')->create(new FileType(), new File());
     $form->handleRequest($request);
     if ($form->isValid()) {
         if (!$this->isZip($form->get('file')->getData())) {
             $error = $this->container->get('translator')->trans('not_a_zip', [], 'resource');
             $form->addError(new FormError($error));
         } else {
             $event->setResources([$this->create($form->get('file')->getData(), $workspace)]);
             $event->stopPropagation();
             return;
         }
     }
     $content = $this->container->get('templating')->render('ClarolineCoreBundle:Resource:createForm.html.twig', ['form' => $form->createView(), 'resourceType' => $event->getResourceType()]);
     $event->setErrorFormContent($content);
     $event->stopPropagation();
 }
Пример #18
0
 /**
  * @DI\Observe("create_file")
  *
  * @param CreateResourceEvent $event
  */
 public function onCreate(CreateResourceEvent $event)
 {
     $request = $this->container->get('request');
     $form = $this->container->get('form.factory')->create(new FileType(true), new File());
     $form->handleRequest($request);
     if ($form->isValid()) {
         $workspace = $event->getParent()->getWorkspace();
         $workspaceDir = $this->workspaceManager->getStorageDirectory($workspace);
         $isStorageLeft = $this->resourceManager->checkEnoughStorageSpaceLeft($workspace, $form->get('file')->getData());
         if (!$isStorageLeft) {
             $this->resourceManager->addStorageExceededFormError($form, filesize($form->get('file')->getData()), $workspace);
         } else {
             //check if there is enough space liedt
             $file = $form->getData();
             $tmpFile = $form->get('file')->getData();
             $published = $form->get('published')->getData();
             $event->setPublished($published);
             $fileName = $tmpFile->getClientOriginalName();
             $ext = strtolower($tmpFile->getClientOriginalExtension());
             $mimeType = $this->container->get('claroline.utilities.mime_type_guesser')->guess($ext);
             if (!is_dir($workspaceDir)) {
                 mkdir($workspaceDir);
             }
             if (pathinfo($fileName, PATHINFO_EXTENSION) === 'zip' && $form->get('uncompress')->getData()) {
                 $roots = $this->unzip($tmpFile, $event->getParent(), $published);
                 $event->setResources($roots);
                 //do not process the resources afterwards because nodes have been created with the unzip function.
                 $event->setProcess(false);
                 $event->stopPropagation();
             } else {
                 $file = $this->createFile($file, $tmpFile, $fileName, $mimeType, $workspace);
                 $event->setResources(array($file));
                 $event->stopPropagation();
             }
             return;
         }
     }
     $content = $this->container->get('templating')->render('ClarolineCoreBundle:Resource:createForm.html.twig', array('form' => $form->createView(), 'resourceType' => $event->getResourceType()));
     $event->setErrorFormContent($content);
     $event->stopPropagation();
 }
Пример #19
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();
 }
Пример #20
0
 /**
  * Fired when a new ResourceNode of type Path is opened.
  *
  * @DI\Observe("create_innova_path")
  *
  * @param \Claroline\CoreBundle\Event\CreateResourceEvent $event
  */
 public function onCreate(CreateResourceEvent $event)
 {
     // Create form
     $form = $this->container->get('form.factory')->create('innova_path', new Path());
     // Try to process form
     $request = $this->container->get('request');
     $form->handleRequest($request);
     if ($form->isValid()) {
         $path = $form->getData();
         $published = $form->get('published')->getData();
         $event->setPublished($published);
         $path->setStructure('');
         // We need to force the save of the Path to get its ID
         $this->container->get('claroline.persistence.object_manager')->persist($path);
         $this->container->get('claroline.persistence.object_manager')->flush();
         // Initialize JSON structure for the Path
         $path->initializeStructure();
         // Send new path to dispatcher through event object
         $event->setResources([$path]);
     } else {
         $content = $this->container->get('templating')->render('ClarolineCoreBundle:Resource:createForm.html.twig', ['form' => $form->createView(), 'resourceType' => 'innova_path']);
         $event->setErrorFormContent($content);
     }
     $event->stopPropagation();
 }
 /**
  * @DI\Observe("create_cpasimusante_simuresource")
  *
  * @param CreateResourceEvent $event
  */
 public function onCreate(CreateResourceEvent $event)
 {
     $request = $this->container->get('request');
     $form = $this->formfactory->create(new SimuResourceType(), new SimuResource());
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em = $this->container->get('doctrine.orm.entity_manager');
         $resource = $form->getData();
         //the claroline Resource needs a name, we set it with whatever we have
         $resource->setName($resource->getField());
         $em->persist($resource);
         $event->setResources(array($resource));
         $event->stopPropagation();
         //exit the modal
         return;
     }
     $content = $this->templating->render('CPASimUSanteSimuResourceBundle:SimuResource:createForm.html.twig', array('form' => $form->createView(), 'resourceType' => $event->getResourceType()));
     $event->setErrorFormContent($content);
     $event->stopPropagation();
 }
 /**
  * @DI\Observe("create_claroline_announcement_aggregate")
  *
  * @param CreateResourceEvent $event
  *
  * @throws \Claroline\CoreBundle\Listener\NoHttpRequestException
  */
 public function onCreate(CreateResourceEvent $event)
 {
     if (!$this->request) {
         throw new NoHttpRequestException();
     }
     $form = $this->formFactory->create(new ResourceNameType(), new AnnouncementAggregate());
     $form->handleRequest($this->request);
     if ($form->isValid()) {
         $announcementAggregate = $form->getData();
         $event->setResources(array($announcementAggregate));
         $event->stopPropagation();
         return;
     }
     $content = $this->templating->render('ClarolineCoreBundle:Resource:createForm.html.twig', array('form' => $form->createView(), 'resourceType' => 'claroline_announcement_aggregate'));
     $event->setErrorFormContent($content);
     $event->stopPropagation();
 }
Пример #23
0
 /**
  * @DI\Observe("create_claroline_survey")
  *
  * @param CreateResourceEvent $event
  */
 public function onCreate(CreateResourceEvent $event)
 {
     $form = $this->formFactory->create(new SurveyType(), new Survey());
     $form->handleRequest($this->request);
     if ($form->isValid()) {
         $survey = $form->getData();
         $this->om->persist($survey);
         $event->setResources([$survey]);
         $event->stopPropagation();
         return;
     }
     $content = $this->templating->render('ClarolineCoreBundle:Resource:createForm.html.twig', ['form' => $form->createView(), 'resourceType' => 'claroline_survey']);
     $event->setErrorFormContent($content);
     $event->stopPropagation();
 }
Пример #24
0
 /**
  * @DI\Observe("create_claroline_scorm_12")
  *
  * @param CreateResourceEvent $event
  */
 public function onCreate(CreateResourceEvent $event)
 {
     $form = $this->formFactory->create(new ScormType(), new Scorm12Resource());
     $form->handleRequest($this->request);
     try {
         if ($form->isValid()) {
             $tmpFile = $form->get('file')->getData();
             $workspace = $event->getParent()->getWorkspace();
             if ($this->isScormArchive($tmpFile)) {
                 $scormResource = $this->container->get('claroline.manager.scorm_manager')->createScorm($tmpFile, $form->get('name')->getData(), '1.2');
                 $event->setResources(array($scormResource));
                 $event->stopPropagation();
                 return;
             }
         }
     } catch (InvalidScormArchiveException $e) {
         $msg = $e->getMessage();
         $errorMsg = $this->translator->trans($msg, array(), 'resource');
         $form->addError(new FormError($errorMsg));
     }
     $content = $this->templating->render('ClarolineCoreBundle:Resource:createForm.html.twig', array('form' => $form->createView(), 'resourceType' => $event->getResourceType()));
     $event->setErrorFormContent($content);
     $event->stopPropagation();
 }
Пример #25
0
 /**
  * @DI\Observe("create_claroline_flashcard")
  *
  * @param CreateResourceEvent $event
  */
 public function onCreate(CreateResourceEvent $event)
 {
     if ($this->formHandler->isValid('claroline_form_deck', $this->request, new Deck())) {
         $event->setResources([$this->manager->create($this->formHandler->getData())]);
     } else {
         $view = $this->formHandler->getView();
         $event->setErrorFormContent($this->manager->getResultFormContent($view));
     }
     $event->stopPropagation();
 }
Пример #26
0
 /**
  * @DI\Observe("create_directory")
  *
  * @param CreateResourceEvent $event
  */
 public function onCreate(CreateResourceEvent $event)
 {
     $request = $this->container->get('request');
     $form = $this->formFactory->create(new DirectoryType(), new Directory());
     $form->handleRequest($request);
     if ($form->isValid()) {
         $published = $form->get('published')->getData();
         $event->setPublished($published);
         $event->setResources(array($form->getData()));
         $event->stopPropagation();
         return;
     }
     $content = $this->templating->render('ClarolineCoreBundle:Resource:createForm.html.twig', array('form' => $form->createView(), 'resourceType' => 'directory'));
     $event->setErrorFormContent($content);
     $event->stopPropagation();
 }