Avoid use redirect when accessing course tool

pull/4804/head
Angel Fernando Quiroz Campos 1 year ago
parent 0c2ff6b5bd
commit 688a129829
  1. 40
      assets/vue/components/course/CourseTool.vue
  2. 27
      assets/vue/views/course/CourseHome.vue
  3. 16
      src/CoreBundle/Controller/CourseController.php

@ -1,8 +1,22 @@
<template>
<div class="course-tool">
<router-link
v-if="to"
:aria-labelledby="`course-tool-${tool.ctool.iid}`"
:to="to"
class="course-tool__link"
:class="cardCustomClass"
>
<span
:class="tool.tool.icon + ' ' + iconCustomClass"
aria-hidden="true"
class="course-tool__icon mdi"
/>
</router-link>
<a
v-else
:aria-labelledby="`course-tool-${tool.ctool.iid}`"
:href="goToCourseTool(course, tool)"
:href="url"
class="course-tool__link"
:class="cardCustomClass"
>
@ -13,10 +27,20 @@
/>
</a>
<router-link
v-if="to"
:id="`course-tool-${tool.ctool.iid}`"
:class="titleCustomClass"
:to="to"
class="course-tool__title"
>
{{ tool.tool.nameToShow }}
</router-link>
<a
v-else
:id="`course-tool-${tool.ctool.iid}`"
v-t="tool.tool.nameToShow"
:href="goToCourseTool(course, tool)"
:href="url"
class="course-tool__title"
:class="titleCustomClass"
/>
@ -77,9 +101,15 @@ const props = defineProps({
type: Object,
required: true
},
goToCourseTool: {
type: Function,
required: true
url: {
type: String,
required: false,
default: () => null,
},
to: {
type: String,
required: false,
default: () => null,
},
changeVisibility: {
type: Function,

@ -137,7 +137,8 @@
:key="'tool-' + index.toString()"
:change-visibility="changeVisibility"
:course="course"
:go-to-course-tool="goToCourseTool"
:to="tool.to"
:url="tool.url"
:go-to-setting-course-tool="goToSettingCourseTool"
:tool="tool"
:data-tool="tool.ctool.name"
@ -207,12 +208,28 @@ store.dispatch("session/cleanSession");
const courseItems = ref([]);
const routerTools = [
'document',
'link',
'glossary',
'agenda',
'student_publication',
'course_homepage',
];
axios
.get(ENTRYPOINT + `../course/${courseId}/home.json?sid=${sessionId}`)
.then(({ data }) => {
course.value = data.course;
session.value = data.session;
tools.value = data.tools;
tools.value = data.tools.map((element) => {
if (routerTools.includes(element.ctool.name)) {
element.to = element.url;
}
return element;
});
shortcuts.value = data.shortcuts;
let adminTool = tools.value.filter((element) => element.category === "admin");
@ -220,7 +237,7 @@ axios
if (Array.isArray(adminTool)) {
courseItems.value = adminTool.map((tool) => ({
label: tool.tool.nameToShow,
url: goToCourseTool(course, tool),
url: tool.url,
}));
}
@ -298,10 +315,6 @@ function goToSettingCourseTool(course, tool) {
return "/course/" + courseId + "/settings/" + tool.tool.name + "?sid=" + sessionId;
}
function goToCourseTool(course, tool) {
return "/course/" + courseId + "/tool/" + tool.tool.name + "?sid=" + sessionId;
}
function goToShortCut(shortcut) {
const url = new URLSearchParams("?");

@ -16,6 +16,7 @@ use Chamilo\CoreBundle\Repository\LegalRepository;
use Chamilo\CoreBundle\Repository\Node\IllustrationRepository;
use Chamilo\CoreBundle\Repository\TagRepository;
use Chamilo\CoreBundle\Security\Authorization\Voter\CourseVoter;
use Chamilo\CoreBundle\Tool\AbstractTool;
use Chamilo\CoreBundle\Tool\ToolChain;
use Chamilo\CourseBundle\Controller\ToolBaseController;
use Chamilo\CourseBundle\Entity\CCourseDescription;
@ -29,7 +30,6 @@ use CourseManager;
use Database;
use Display;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Event;
use Exercise;
use ExtraFieldValue;
@ -247,6 +247,7 @@ class CourseController extends ToolBaseController
$tools[] = [
'ctool' => $item,
'tool' => $toolModel,
'url' => $this->generateToolUrl($toolModel),
'category' => $toolModel->getCategory(),
];
}
@ -771,4 +772,17 @@ class CourseController extends ToolBaseController
);
}
}
private function generateToolUrl(AbstractTool $tool): string
{
$link = $tool->getLink();
$course = $this->getCourse();
if (strpos($link, 'nodeId')) {
$nodeId = (string) $course->getResourceNode()->getId();
$link = str_replace(':nodeId', $nodeId, $link);
}
return $link.'?'.$this->getCourseUrlQuery();
}
}

Loading…
Cancel
Save