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> <template>
<div class="course-tool"> <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 <a
v-else
:aria-labelledby="`course-tool-${tool.ctool.iid}`" :aria-labelledby="`course-tool-${tool.ctool.iid}`"
:href="goToCourseTool(course, tool)" :href="url"
class="course-tool__link" class="course-tool__link"
:class="cardCustomClass" :class="cardCustomClass"
> >
@ -13,10 +27,20 @@
/> />
</a> </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 <a
v-else
:id="`course-tool-${tool.ctool.iid}`" :id="`course-tool-${tool.ctool.iid}`"
v-t="tool.tool.nameToShow" v-t="tool.tool.nameToShow"
:href="goToCourseTool(course, tool)" :href="url"
class="course-tool__title" class="course-tool__title"
:class="titleCustomClass" :class="titleCustomClass"
/> />
@ -77,9 +101,15 @@ const props = defineProps({
type: Object, type: Object,
required: true required: true
}, },
goToCourseTool: { url: {
type: Function, type: String,
required: true required: false,
default: () => null,
},
to: {
type: String,
required: false,
default: () => null,
}, },
changeVisibility: { changeVisibility: {
type: Function, type: Function,

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

@ -16,6 +16,7 @@ use Chamilo\CoreBundle\Repository\LegalRepository;
use Chamilo\CoreBundle\Repository\Node\IllustrationRepository; use Chamilo\CoreBundle\Repository\Node\IllustrationRepository;
use Chamilo\CoreBundle\Repository\TagRepository; use Chamilo\CoreBundle\Repository\TagRepository;
use Chamilo\CoreBundle\Security\Authorization\Voter\CourseVoter; use Chamilo\CoreBundle\Security\Authorization\Voter\CourseVoter;
use Chamilo\CoreBundle\Tool\AbstractTool;
use Chamilo\CoreBundle\Tool\ToolChain; use Chamilo\CoreBundle\Tool\ToolChain;
use Chamilo\CourseBundle\Controller\ToolBaseController; use Chamilo\CourseBundle\Controller\ToolBaseController;
use Chamilo\CourseBundle\Entity\CCourseDescription; use Chamilo\CourseBundle\Entity\CCourseDescription;
@ -29,7 +30,6 @@ use CourseManager;
use Database; use Database;
use Display; use Display;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Event; use Event;
use Exercise; use Exercise;
use ExtraFieldValue; use ExtraFieldValue;
@ -247,6 +247,7 @@ class CourseController extends ToolBaseController
$tools[] = [ $tools[] = [
'ctool' => $item, 'ctool' => $item,
'tool' => $toolModel, 'tool' => $toolModel,
'url' => $this->generateToolUrl($toolModel),
'category' => $toolModel->getCategory(), '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