/** * Display path player * @param \Innova\PathBundle\Entity\Path\Path $path * @return array * * @Route( * "/{id}", * name = "innova_path_player_wizard", * defaults = { "stepId" = null }, * options = { "expose" = true } * ) * @Template("InnovaPathBundle:Wizard:player.html.twig") */ public function displayAction(Path $path) { // Check User credentials $this->pathManager->checkAccess('OPEN', $path); $resourceIcons = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceIcon')->findByIsShortcut(false); return array('_resource' => $path, 'userProgression' => $this->pathManager->getUserProgression($path), 'resourceIcons' => $resourceIcons, 'editEnabled' => $this->pathManager->isAllow('EDIT', $path)); }
/** * @DI\Observe("widget_innova_path_widget_configuration") * * @param ConfigureWidgetEvent $event */ public function onConfigure(ConfigureWidgetEvent $event) { $instance = $event->getInstance(); $config = $this->pathManager->getWidgetConfig($instance); $form = $this->formFactory->create('innova_path_widget_config', $config); $content = $this->twig->render('InnovaPathBundle:Widget:config.html.twig', ['form' => $form->createView(), 'instance' => $instance, 'tags' => $this->tagManager->getPlatformTags()]); $event->setContent($content); $event->stopPropagation(); }
/** * Display dashboard for path of users. * * @Route( * "/userpath/{id}", * name = "innova_path_manage_results", * requirements = {"id" = "\d+"}, * options = {"expose" = true} * ) * @Method("GET") * @ParamConverter("path", class="InnovaPathBundle:Path\Path", options={"id" = "id"}) * @Template("InnovaPathBundle::manageResults.html.twig") */ public function displayStepUnlockAction(Path $path) { //prevent direct access $this->pathManager->checkAccess('EDIT', $path); $data = []; $workspace = $path->getWorkspace(); //retrieve users having access to the WS //TODO Optimize $users = $this->om->getRepository('ClarolineCoreBundle:User')->findUsersByWorkspace($workspace); $userdata = []; //for all users in the WS foreach ($users as $user) { //get their progression $userdata[] = ['user' => $user, 'progression' => $this->pathManager->getUserProgression($path, $user), 'locked' => $this->pathManager->getPathLockedProgression($path)]; } $data = ['path' => $path, 'userdata' => $userdata]; return ['_resource' => $path, 'workspace' => $workspace, 'data' => $data]; }
/** * Publish path * Create all needed resources for path to be played * * @Route( * "/publish/{id}", * name = "innova_path_publish", * requirements = {"id" = "\d+"}, * options = {"expose" = true} * ) * @Method("PUT") */ public function publishAction(Path $path) { $this->pathManager->checkAccess('EDIT', $path); $response = array(); try { $this->publishingManager->publish($path); // Publish success $response['status'] = 'OK'; $response['messages'] = array(); $response['data'] = json_decode($path->getStructure()); // Send updated data } catch (\Exception $e) { // Error $response['status'] = 'ERROR'; $response['messages'] = array($e->getMessage()); $response['data'] = null; } return new JsonResponse($response); }
/** * @param WidgetInstance $widgetInstance * @param \Symfony\Component\HttpFoundation\Request $request * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException * @return array * * @Route( * "/widget/config/{widgetInstance}", * name= "innova_path_widget_config" * ) * @Method("POST") * @Template("InnovaPathBundle:Widget:config.html.twig") */ public function updateWidgetAction(WidgetInstance $widgetInstance, Request $request) { // User can not edit the Widget if (!$this->authorizationChecker->isGranted('edit', $widgetInstance)) { throw new AccessDeniedException(); } $config = $this->pathManager->getWidgetConfig($widgetInstance); if (null === $config) { $config = new PathWidgetConfig(); $config->setWidgetInstance($widgetInstance); } $form = $this->formFactory->create('innova_path_widget_config', $config); $form->bind($request); if ($form->isValid()) { // Remove tags $tagsToRemove = $form->get('removeTags')->getData(); if (!empty($tagsToRemove)) { // Search the Tag by ID $existingTags = $config->getTags()->toArray(); $toRemoveArray = array_filter($existingTags, function ($entry) use($tagsToRemove) { return in_array($entry->getId(), $tagsToRemove); }); foreach ($toRemoveArray as $toRemove) { $config->removeTag($toRemove); } } // Add tags $tags = $form->get('tags')->getData(); if (!empty($tags)) { // Ge the list of Tags from data String $tags = explode(',', $tags); $uniqueTags = array(); foreach ($tags as $tag) { $value = trim($tag); if (!empty($value)) { $uniqueTags[strtolower($value)] = $value; } } foreach ($uniqueTags as $tagName) { $tagObject = $this->tagManager->getOnePlatformTagByName($tagName); if (!empty($tagObject)) { $config->addTag($tagObject); } } } $this->om->persist($config); $this->om->flush(); return new Response('success', 204); } return array('form' => $form->createView(), 'instance' => $widgetInstance, 'tags' => $this->tagManager->getPlatformTags()); }
/** * Save Path * @param Path $path * @param \Symfony\Component\HttpFoundation\Request $request * @return \Symfony\Component\HttpFoundation\JsonResponse * * @Route( * "/{id}", * name = "innova_path_editor_wizard_save", * options = { "expose" = true } * ) * @Method("PUT") */ public function saveAction(Path $path, Request $request) { $this->pathManager->checkAccess('EDIT', $path); // Create form $form = $this->formFactory->create('innova_path', $path, array('method' => 'PUT', 'csrf_protection' => false)); $response = array(); // Try to process data $form->handleRequest($request); if ($form->isValid()) { // Form is valid => create or update the path $this->pathManager->edit($path); // Validation OK $response['status'] = 'OK'; $response['messages'] = array(); $response['data'] = $path->getStructure(); } else { // Validation Error $response['status'] = 'ERROR_VALIDATION'; $response['messages'] = $this->getFormErrors($form); $response['data'] = null; } return new JsonResponse($response); }
/** * Display path player. * * @param \Innova\PathBundle\Entity\Path\Path $path * * @return array * * @Route( * "/{id}", * name = "innova_path_player_wizard", * options = { "expose" = true } * ) * @Template("InnovaPathBundle:Wizard:player.html.twig") */ public function displayAction(Path $path) { // Check User credentials $this->pathManager->checkAccess('OPEN', $path); return ['_resource' => $path, 'workspace' => $path->getWorkspace(), 'userProgression' => $this->pathManager->getUserProgression($path), 'editEnabled' => $this->pathManager->isAllow('EDIT', $path), 'totalProgression' => $this->userProgressionManager->calculateUserProgressionInPath($path)]; }