/** * Publish path * Create all needed resources for path to be played * * @Route( * "/publish/{id}/{redirect}", * name = "innova_path_publish", * requirements = {"id" = "\d+"}, * options = {"expose" = true} * ) * @Method({"GET", "PUT"}) */ public function publishAction(Path $path, $redirect = false, Request $request) { $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; } if ($redirect) { // That's not an AJAX call, so display a flash message and redirect the User $message = 'OK' === $response['status'] ? 'publish_success' : 'publish_error'; $this->session->getFlashBag()->add('OK' === $response['status'] ? 'success' : 'error', $this->translator->trans($message, array(), 'path_wizards')); return new RedirectResponse($request->headers->get('referer')); } return new JsonResponse($response); }
/** * 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)); }
/** * 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); }
/** * 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)]; }