Fix course home/listeners to read cid/sid/gid parameters.

pull/3064/head
Julio 5 years ago
parent 5ea97910b7
commit 805611d766
  1. 6
      public/main/document/document.php
  2. 21
      src/CoreBundle/Block/BreadcrumbBlockService.php
  3. 14
      src/CoreBundle/Controller/CourseController.php
  4. 8
      src/CoreBundle/Controller/CourseHomeController.php
  5. 25
      src/CourseBundle/EventListener/CourseListener.php
  6. 10
      src/ThemeBundle/Resources/views/Breadcrumb/breadcrumb.html.twig
  7. 8
      src/ThemeBundle/Resources/views/Layout/breadcrumb.html.twig

@ -16,10 +16,10 @@ use ChamiloSession as Session;
*/
//require_once __DIR__.'/../inc/global.inc.php';
$courseCode = isset($_GET['cidReq']) ? htmlentities($_GET['cidReq']) : '';
$sessionId = isset($_GET['id_session']) ? (int) $_GET['id_session'] : 0;
$courseCode = isset($_GET['cid']) ? (int) $_GET['cid'] : 0;
$sessionId = isset($_GET['sid']) ? (int) $_GET['sid'] : 0;
$url = "../../../resources/document/files?cidReq=$courseCode&id_session=$sessionId";
$url = "../../../resources/document/files?cid=$courseCode&sid=$sessionId";
header("Location: $url");
exit;

@ -4,6 +4,7 @@
namespace Chamilo\CoreBundle\Block;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\Session;
use Sonata\BlockBundle\Block\BlockContextInterface;
use Sonata\SeoBundle\Block\Breadcrumb\BaseBreadcrumbMenuBlockService;
use Symfony\Component\OptionsResolver\OptionsResolver;
@ -56,27 +57,27 @@ class BreadcrumbBlockService extends BaseBreadcrumbMenuBlockService
$menu->addChild('Home', ['route' => 'home']);
$sessionId = 0;
if ($blockContext->getBlock()->getSetting('session_id')) {
$sessionId = $blockContext->getBlock()->getSetting('session_id');
// Course/Session block are set here src/ThemeBundle/Resources/views/Layout/breadcrumb.html.twig
if ($blockContext->getBlock()->getSetting('session')) {
/** @var Session $course */
$session = $blockContext->getBlock()->getSetting('session');
if ($session) {
$sessionId = $session->getId();
}
}
// Add course
/** @var Course $course */
if ($course = $blockContext->getBlock()->getSetting('course')) {
if (is_array($course)) {
$title = $course['title'];
$code = $course['code'];
} else {
$title = $course->getTitle();
$code = $course->getCode();
}
$courseId = $course->getId();
$menu->addChild(
$title,
[
'route' => 'course_home',
'route' => 'chamilo_core_course_home',
'routeParameters' => [
'course' => $code,
'cid' => $courseId,
'sid' => $sessionId,
],
]

@ -54,10 +54,22 @@ class CourseController extends AbstractController
}
/**
* @Route("/{courseCode}", name="chamilo_core_course_home")
* Redirects legacy /courses/ABC/index.php to /courses/1/ (where 1 is the course id).
*
* @Route("/{courseCode}/index.php", name="chamilo_core_course_home_redirect")
*
* @Entity("course", expr="repository.findOneByCode(courseCode)")
*/
public function homeRedirectAction(Course $course): Response
{
return $this->redirectToRoute('chamilo_core_course_home', ['cid' => $course->getId()]);
}
/**
* @Route("/{cid}", name="chamilo_core_course_home")
*
* @Entity("course", expr="repository.find(cid)")
*/
public function homeAction(Course $course): Response
{
return $this->render('@ChamiloTheme/Course/welcome.html.twig', ['course' => $course]);

@ -1,7 +1,7 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CourseBundle\Controller\Home;
namespace Chamilo\CoreBundle\Controller;
use Chamilo\CourseBundle\Controller\ToolBaseController;
use Chamilo\CourseBundle\Entity\CTool;
@ -22,13 +22,13 @@ use Symfony\Component\Routing\Annotation\Route;
*
* @author Julio Montoya <gugli100@gmail.com>
*
* @Route("/")
* @Route("/sad")
*/
class CourseHomeController extends ToolBaseController
{
/**
* @Route("/", name="course_home")
* @Route("/index.php", methods={"GET"})
* Route("/", name="course_home")
* Route("/index.php", methods={"GET"})
*
* @return Response
*/

@ -49,6 +49,7 @@ class CourseListener
if ($request->attributes->get('_route') === '_wdt') {
return;
}
// Ignore toolbar
if ($request->attributes->get('_profiler') === '_wdt') {
return;
@ -58,12 +59,11 @@ class CourseListener
$container = $this->container;
$translator = $container->get('translator');
$course = null;
// Check if URL has cid value
if ($request->attributes->has('cid')) {
$course = null;
// Check if URL has cid value. Using Symfony request.
$courseId = $request->get('cid');
if (!empty($courseId)) {
/** @var EntityManager $em */
$em = $container->get('doctrine')->getManager();
$checker = $container->get('security.authorization_checker');
@ -82,16 +82,19 @@ class CourseListener
}
if (null !== $course) {
$sessionHandler->set('courseObj', $course);
$courseInfo = api_get_course_info($course->getCode());
$container->get('twig')->addGlobal('course', $course);
// Setting variables in the session.
$sessionHandler->set('course', $course);
$sessionHandler->set('_real_cid', $course->getId());
$sessionHandler->set('cid', $course->getId());
$sessionHandler->set('_cid', $course->getCode());
$courseInfo = api_get_course_info($course->getCode());
$sessionHandler->set('_course', $courseInfo);
// Session
// Setting variables for the twig templates.
$container->get('twig')->addGlobal('course', $course);
// Checking if sid is used.
$sessionId = (int) $request->get('sid');
$session = null;
if (empty($sessionId)) {
@ -120,9 +123,9 @@ class CourseListener
$sessionHandler->set('session_name', $session->getName());
$sessionHandler->set('sid', $session->getId());
$sessionHandler->set('sessionObj', $session);
$sessionHandler->set('session', $session);
$container->get('twig')->addGlobal('sessionObj', $session);
$container->get('twig')->addGlobal('session', $session);
} else {
throw new NotFoundHttpException($translator->trans('Session not found'));
}

@ -8,7 +8,7 @@
{% if course is defined %}
<li>
<a href="{{ url('course_home', {'course': course }) }}">
<a href="{{ url('chamilo_core_course_home', {'course': course }) }}">
<i class="fa fa-book"></i>
{{ course.title }}
</a>
@ -17,10 +17,10 @@
{% if tool.name is defined and tool.name != '' %}
<li>
<a href="{{ url('chamilo_'~ tool.name ~'_index', {'course': course }) }}">
<i class="fa fa-cube"></i>
{{ tool.name }}
</a>
{# <a href="{{ url('chamilo_'~ tool.name ~'_index', {'course': course }) }}">#}
{# <i class="fa fa-cube"></i>#}
{# {{ tool.name }}#}
{# </a>#}
</li>
{% endif %}

@ -1,20 +1,16 @@
{% autoescape false %}
{# Course comes from the base-layout.html #}
{% if course is not defined %}
{% set course = '' %}
{% endif %}
{% if legacy_breadcrumb is not defined %}
{% set legacy_breadcrumb = '' %}
{% endif %}
{# course and session variables are set in the src/CourseBundle/EventListener/CourseListener.php #}
{{
sonata_block_render_event(
'breadcrumb',
{
'context': 'chamilo_core.block.breadcrumb',
'course': course,
'session_id': session,
'session': session,
'legacy_breadcrumb': legacy_breadcrumb,
'current_uri': app.request.requestUri
}

Loading…
Cancel
Save