From c189f77c7a5f15e6dd472d05c348b28c78aafdff Mon Sep 17 00:00:00 2001 From: Julio Date: Fri, 6 Dec 2019 17:04:24 +0100 Subject: [PATCH] Use "course" URL instead of "courses" --- config/packages/sonata_page.yaml | 2 +- .../Controller/CourseController.php | 2 +- .../Controller/CourseHomeController.php | 73 ++++++++++++++++++- src/CourseBundle/Resources/config/routing.yml | 13 ---- src/LtiBundle/Resources/config/routing.yml | 2 +- 5 files changed, 75 insertions(+), 17 deletions(-) diff --git a/config/packages/sonata_page.yaml b/config/packages/sonata_page.yaml index 22947edd53..424afb3bc8 100644 --- a/config/packages/sonata_page.yaml +++ b/config/packages/sonata_page.yaml @@ -17,7 +17,7 @@ sonata_page: - ^/admin(.*) # chamilo admin - ^/api/(.*) - ^/contact(.*) # sonata admin - - ^/courses/(.*) + - ^/course/(.*) - ^/connect/(.*) - ^/editor/(.*) - ^/login/(.*) diff --git a/src/CoreBundle/Controller/CourseController.php b/src/CoreBundle/Controller/CourseController.php index 1dec5fa6a5..c3fac1bb85 100644 --- a/src/CoreBundle/Controller/CourseController.php +++ b/src/CoreBundle/Controller/CourseController.php @@ -19,7 +19,7 @@ use UserManager; /** * Class CourseController. * - * @Route("/courses") + * @Route("/course") */ class CourseController extends AbstractController { diff --git a/src/CoreBundle/Controller/CourseHomeController.php b/src/CoreBundle/Controller/CourseHomeController.php index 0368f90325..b88a673517 100644 --- a/src/CoreBundle/Controller/CourseHomeController.php +++ b/src/CoreBundle/Controller/CourseHomeController.php @@ -3,9 +3,11 @@ namespace Chamilo\CoreBundle\Controller; +use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\ToolChain; use Chamilo\CourseBundle\Controller\ToolBaseController; use Chamilo\CourseBundle\Entity\CTool; +use Chamilo\CourseBundle\Manager\SettingsManager; use Chamilo\CourseBundle\Repository\CToolRepository; use Chamilosession as Session; use CourseManager; @@ -15,16 +17,19 @@ use Event; use ExtraFieldValue; use Security; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Entity; +use Sylius\Bundle\SettingsBundle\Form\Factory\SettingsFormFactory; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Validator\Exception\ValidatorException; /** * Class CourseHomeController. * * @author Julio Montoya * - * @Route("/courses") + * @Route("/course") */ class CourseHomeController extends ToolBaseController { @@ -381,4 +386,70 @@ class CourseHomeController extends ToolBaseController )); } } + + /** + * Edit configuration with given namespace. + * + * @param string $namespace + * @Route("/{cid}/settings/{namespace}", name="chamilo_core_course_settings") + + * @Entity("course", expr="repository.find(cid)") + * + * + * @return Response + */ + public function updateAction(Request $request, Course $course, $namespace, SettingsManager $manager, SettingsFormFactory $formFactory) + { + $schemaAlias = $manager->convertNameSpaceToService($namespace); + $settings = $manager->load($namespace); + $form = $formFactory->create($schemaAlias); + + $form->setData($settings); + + if ($form->handleRequest($request)->isValid()) { + $messageType = 'success'; + try { + $manager->setCourse($course); + $manager->saveSettings($namespace, $form->getData()); + $message = $this->trans( + 'sylius.settings.update', + [], + 'flashes' + ); + } catch (ValidatorException $exception) { + $message = $this->trans( + $exception->getMessage(), + [], + 'validators' + ); + $messageType = 'error'; + } + $request->getSession()->getBag('flashes')->add( + $messageType, + $message + ); + + if ($request->headers->has('referer')) { + return $this->redirect($request->headers->get('referer')); + } + } + $schemas = $manager->getSchemas(); + + return $this->render( + $request->attributes->get( + 'template', + 'ChamiloCourseBundle:Settings:update.html.twig' + ), + [ + 'course' => $course, + 'schemas' => $schemas, + 'settings' => $settings, + 'form' => $form->createView(), + 'keyword' => '', + 'search_form' => '', + ] + ); + } + + } diff --git a/src/CourseBundle/Resources/config/routing.yml b/src/CourseBundle/Resources/config/routing.yml index 649dc15357..e69de29bb2 100644 --- a/src/CourseBundle/Resources/config/routing.yml +++ b/src/CourseBundle/Resources/config/routing.yml @@ -1,13 +0,0 @@ -#chamilo_course.c_tool_intro: -# resource: | -# alias: chamilo_course.c_tool_intro -# path: /courses/{course}/introduction/{tool} -# templates: :Admin/Book -# type: sylius.resource_api - -# Course settings -#chamilo_course_settings: -# path: /course/{cid}/settings/{namespace} -# defaults: -# _controller: Chamilo\CourseBundle\Controller\SettingsController::updateAction -# template: ChamiloCourseBundle:Settings:default.html.twig diff --git a/src/LtiBundle/Resources/config/routing.yml b/src/LtiBundle/Resources/config/routing.yml index 314f82c48f..40429c716e 100644 --- a/src/LtiBundle/Resources/config/routing.yml +++ b/src/LtiBundle/Resources/config/routing.yml @@ -6,7 +6,7 @@ chamilo_lti_admin_controller: chamilo_lti_teacher_controller: resource: '@ChamiloLtiBundle/Controller/CourseController.php' type: annotation - prefix: '/lti/courses/{code}/lti' + prefix: '/lti/course/{code}/lti' chamilo_lti_service_controller: path: /lti/os