Internal: Fix lesson issues - refs BT#21540

pull/5409/head
christianbeeznst 1 year ago
parent 26078de552
commit 0986bbfd4f
  1. 4
      assets/css/document.css
  2. 9
      assets/js/legacy/document.js
  3. 77
      assets/js/translatehtml.js
  4. 36
      assets/vue/components/course/CourseIntroduction.vue
  5. 2
      assets/vue/views/course/CourseHome.vue
  6. 6
      public/main/exercise/exercise.class.php
  7. 6
      public/main/exercise/exercise_result.php
  8. 18
      public/main/exercise/exercise_submit.php
  9. 2
      public/main/forum/forumfunction.inc.php
  10. 11
      public/main/forum/iframe_thread.php
  11. 7
      public/main/inc/lib/api.lib.php
  12. 4
      src/CoreBundle/EventListener/CourseListener.php

@ -2,3 +2,7 @@
.hidden { .hidden {
display: none; display: none;
} }
.mce-translatehtml, span[lang] {
display: none;
}

@ -1,6 +1,9 @@
/** This JS will be included when loading an HTML in the Document tool */ import { createPinia, setActivePinia } from 'pinia'
import translateHtml from './../translatehtml.js'; const pinia = createPinia()
setActivePinia(pinia)
import translateHtml from './../translatehtml.js'
document.addEventListener('DOMContentLoaded', function () { document.addEventListener('DOMContentLoaded', function () {
translateHtml(); translateHtml()
}); });

@ -1,51 +1,56 @@
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
import { usePlatformConfig } from "../vue/store/platformConfig"; import { usePlatformConfig } from "../vue/store/platformConfig"
function normalizeLocale(locale) { function normalizeLocale(locale) {
return locale.split('_')[0]; return locale.split('_')[0]
} }
export default function translateHtml() { export default async function translateHtml() {
const platformConfigStore = usePlatformConfig(); try {
const platformConfigStore = usePlatformConfig()
await platformConfigStore.initialize()
if ( if (
window.user && window.user &&
window.user.locale && window.user.locale &&
"true" === platformConfigStore.getSetting("editor.translate_html") "true" === platformConfigStore.getSetting("editor.translate_html")
) { ) {
var isoCode = normalizeLocale(window.user.locale); var isoCode = normalizeLocale(window.user.locale)
const translateElement = document.querySelector(".mce-translatehtml"); const translateElement = document.querySelector(".mce-translatehtml")
if (translateElement) { if (translateElement) {
document.querySelectorAll(".mce-translatehtml").forEach(function (el) { document.querySelectorAll(".mce-translatehtml").forEach(function (el) {
el.style.display = "none"; el.style.display = "none"
}); })
const selectedLang = document.querySelectorAll(`[lang="${isoCode}"]`); const selectedLang = document.querySelectorAll(`[lang="${isoCode}"]`)
if (selectedLang.length > 0) { if (selectedLang.length > 0) {
selectedLang.forEach(function (userLang) { selectedLang.forEach(function (userLang) {
userLang.classList.remove("hidden"); userLang.classList.remove("hidden")
userLang.style.display = "block"; userLang.style.display = "block"
}); })
}
} }
}
// it checks content from old version // it checks content from old version
const langSpans = document.querySelectorAll('span[lang]'); const langSpans = document.querySelectorAll('span[lang]')
const langs = [...langSpans].filter(span => !span.classList.contains('mce-translatehtml')); const langs = [...langSpans].filter(span => !span.classList.contains('mce-translatehtml'))
if (langs.length > 0) { if (langs.length > 0) {
// it hides all contents with lang // it hides all contents with lang
langs.forEach(function (el) { langs.forEach(function (el) {
el.style.display = "none"; el.style.display = "none"
}); })
const selectedLang = document.querySelectorAll(`span[lang="${isoCode}"]`); const selectedLang = document.querySelectorAll(`span[lang="${isoCode}"]`)
if (selectedLang.length > 0) { if (selectedLang.length > 0) {
selectedLang.forEach(function (userLang) { selectedLang.forEach(function (userLang) {
userLang.classList.remove("hidden"); userLang.classList.remove("hidden")
userLang.style.display = "block"; userLang.style.display = "block"
}); })
}
} }
} }
} catch (error) {
console.error("Error in translateHtml:", error)
} }
} }

@ -18,6 +18,13 @@ const { course, session } = storeToRefs(cidReqStore)
const intro = ref(null) const intro = ref(null)
const props = defineProps({
isAllowedToEdit: {
type: Boolean,
required: true
}
})
courseService.loadHomeIntro(course.value.id, session.value?.id).then((data) => (intro.value = data)) courseService.loadHomeIntro(course.value.id, session.value?.id).then((data) => (intro.value = data))
const goToIntroCreate = () => { const goToIntroCreate = () => {
@ -77,20 +84,21 @@ defineExpose({
v-if="intro.introText" v-if="intro.introText"
v-html="intro.introText" v-html="intro.introText"
/> />
<EmptyState <div v-else-if="isAllowedToEdit">
v-else <EmptyState
:detail="t('Add a course introduction to display to your students.')" :detail="t('Add a course introduction to display to your students.')"
:summary="t('You don\'t have any course content yet.')" :summary="t('You don\'t have any course content yet.')"
icon="courses" icon="courses"
> >
<BaseButton <BaseButton
:label="t('Course introduction')" :label="t('Course introduction')"
class="mt-4" class="mt-4"
icon="plus" icon="plus"
type="primary" type="primary"
@click="goToIntroCreate" @click="goToIntroCreate"
/> />
</EmptyState> </EmptyState>
</div>
</div> </div>
<Skeleton <Skeleton
v-else v-else

@ -116,8 +116,8 @@
</div> </div>
<CourseIntroduction <CourseIntroduction
v-if="isAllowedToEdit"
ref="courseIntroEl" ref="courseIntroEl"
:is-allowed-to-edit="isAllowedToEdit"
/> />
<div <div

@ -6732,9 +6732,9 @@ class Exercise
$attemptCount = Event::get_attempt_count( $attemptCount = Event::get_attempt_count(
api_get_user_id(), api_get_user_id(),
$this->getId(), $this->getId(),
$lpId, (int) $lpId,
$lpItemId, (int) $lpItemId,
$lpItemViewId (int) $lpItemViewId
); );
if ($attemptCount >= $exerciseAttempts) { if ($attemptCount >= $exerciseAttempts) {

@ -149,9 +149,9 @@ if ('embeddable' !== $origin) {
$attempt_count = Event::get_attempt_count( $attempt_count = Event::get_attempt_count(
$currentUserId, $currentUserId,
$objExercise->id, $objExercise->id,
$learnpath_id, (int) $learnpath_id,
$learnpath_item_id, (int) $learnpath_item_id,
$learnpath_item_view_id (int) $learnpath_item_view_id
); );
if ($objExercise->selectAttempts() > 0) { if ($objExercise->selectAttempts() > 0) {

@ -263,9 +263,9 @@ if ($objExercise->selectAttempts() > 0) {
$attempt_count = Event::get_attempt_count( $attempt_count = Event::get_attempt_count(
$user_id, $user_id,
$exerciseId, $exerciseId,
$learnpath_id, (int) $learnpath_id,
$learnpath_item_id, (int) $learnpath_item_id,
$learnpath_item_view_id (int) $learnpath_item_view_id
); );
if ($attempt_count >= $objExercise->selectAttempts()) { if ($attempt_count >= $objExercise->selectAttempts()) {
@ -848,9 +848,9 @@ if ($formSent && isset($_POST)) {
$attempt_count = Event::get_attempt_count( $attempt_count = Event::get_attempt_count(
api_get_user_id(), api_get_user_id(),
$exerciseId, $exerciseId,
$learnpath_id, (int) $learnpath_id,
$learnpath_item_id, (int) $learnpath_item_id,
$learnpath_item_view_id (int) $learnpath_item_view_id
); );
if ($attempt_count >= $objExercise->selectAttempts()) { if ($attempt_count >= $objExercise->selectAttempts()) {
echo Display::return_message( echo Display::return_message(
@ -917,9 +917,9 @@ if (0 != $question_count) {
$attempt_count = Event::get_attempt_count( $attempt_count = Event::get_attempt_count(
api_get_user_id(), api_get_user_id(),
$exerciseId, $exerciseId,
$learnpath_id, (int) $learnpath_id,
$learnpath_item_id, (int) $learnpath_item_id,
$learnpath_item_view_id (int) $learnpath_item_view_id
); );
if ($attempt_count >= $objExercise->selectAttempts()) { if ($attempt_count >= $objExercise->selectAttempts()) {
Display::return_message( Display::return_message(

@ -1972,7 +1972,7 @@ function show_add_post_form(CForum $forum, CForumThread $thread, CForumPost $pos
if ($showPreview) { if ($showPreview) {
if ('newthread' !== $action && !empty($threadId)) { if ('newthread' !== $action && !empty($threadId)) {
$iframe = '<iframe style="border: 1px solid black" $iframe = '<iframe style="border: 1px solid black"
src="iframe_thread.php?'.api_get_cidreq().'&forum='.$forumId.'&thread='.$threadId.'#'.$postId.'" width="100%"></iframe>'; src="'.api_get_path(WEB_CODE_PATH).'forum/iframe_thread.php?'.api_get_cidreq().'&forum='.$forumId.'&thread='.$threadId.'#'.$postId.'" width="100%"></iframe>';
} }
if (!empty($iframe)) { if (!empty($iframe)) {
$form->addElement('label', get_lang('Thread'), $iframe); $form->addElement('label', get_lang('Thread'), $iframe);

@ -25,8 +25,11 @@ use Chamilo\CourseBundle\Entity\CForumThread;
*/ */
require_once __DIR__.'/../inc/global.inc.php'; require_once __DIR__.'/../inc/global.inc.php';
$cid = isset($_REQUEST['cid']) ? (int) $_REQUEST['cid'] : null;
$sid = isset($_REQUEST['sid']) ? (int) $_REQUEST['sid'] : null;
// A notice for unauthorized people. // A notice for unauthorized people.
api_protect_course_script(true); api_protect_course_script(true, false, '', $cid);
$nameTools = get_lang('Forums'); $nameTools = get_lang('Forums');
@ -47,8 +50,8 @@ if (!empty($threadId)) {
$threadEntity = $repoThread->find($threadId); $threadEntity = $repoThread->find($threadId);
} }
$courseEntity = api_get_course_entity(api_get_course_int_id()); $courseEntity = api_get_course_entity($cid);
$sessionEntity = api_get_session_entity(api_get_session_id()); $sessionEntity = api_get_session_entity($sid);
/* Is the user allowed here? */ /* Is the user allowed here? */
// if the user is not a course administrator and the forum is hidden // if the user is not a course administrator and the forum is hidden
@ -61,8 +64,6 @@ if (!api_is_allowed_to_create_course() &&
api_not_allowed(false); api_not_allowed(false);
} }
$course_id = api_get_course_int_id();
$table_posts = Database::get_course_table(TABLE_FORUM_POST); $table_posts = Database::get_course_table(TABLE_FORUM_POST);
$table_users = Database::get_main_table(TABLE_MAIN_USER); $table_users = Database::get_main_table(TABLE_MAIN_USER);

@ -885,9 +885,14 @@ function api_valid_email($address)
* *
* @author Roan Embrechts * @author Roan Embrechts
*/ */
function api_protect_course_script($print_headers = false, $allow_session_admins = false, $checkTool = '') function api_protect_course_script($print_headers = false, $allow_session_admins = false, string $checkTool = '', $cid = null): bool
{ {
$course_info = api_get_course_info(); $course_info = api_get_course_info();
if (isset($cid)) {
$course_info = api_get_course_info_by_id($cid);
}
if (empty($course_info)) { if (empty($course_info)) {
api_not_allowed($print_headers); api_not_allowed($print_headers);

@ -30,6 +30,7 @@ use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Contracts\Translation\TranslatorInterface; use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment; use Twig\Environment;
use ChamiloSession;
/** /**
* Class CourseListener. * Class CourseListener.
@ -114,6 +115,9 @@ class CourseListener implements EventSubscriberInterface
$sessionHandler->set('cid', $course->getId()); $sessionHandler->set('cid', $course->getId());
$sessionHandler->set('_cid', $course->getCode()); $sessionHandler->set('_cid', $course->getCode());
$sessionHandler->set('_course', $courseInfo); $sessionHandler->set('_course', $courseInfo);
ChamiloSession::write('cid', $course->getId());
ChamiloSession::write('_real_cid', $course->getId());
ChamiloSession::write('_course', $courseInfo);
// Setting variables for the twig templates. // Setting variables for the twig templates.
$twig->addGlobal('course', $course); $twig->addGlobal('course', $course);

Loading…
Cancel
Save