Internal: Fix lesson issues - refs BT#21540

pull/5409/head
christianbeeznst 1 year ago
parent 26078de552
commit 0986bbfd4f
  1. 6
      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

@ -1,4 +1,8 @@
/** CSS that will be included when loading an HTML in the Document tool */
.hidden {
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 () {
translateHtml();
translateHtml()
});

@ -1,51 +1,56 @@
/* For licensing terms, see /license.txt */
import { usePlatformConfig } from "../vue/store/platformConfig";
import { usePlatformConfig } from "../vue/store/platformConfig"
function normalizeLocale(locale) {
return locale.split('_')[0];
return locale.split('_')[0]
}
export default function translateHtml() {
const platformConfigStore = usePlatformConfig();
export default async function translateHtml() {
try {
const platformConfigStore = usePlatformConfig()
await platformConfigStore.initialize()
if (
window.user &&
window.user.locale &&
"true" === platformConfigStore.getSetting("editor.translate_html")
) {
var isoCode = normalizeLocale(window.user.locale);
const translateElement = document.querySelector(".mce-translatehtml");
if (translateElement) {
document.querySelectorAll(".mce-translatehtml").forEach(function (el) {
el.style.display = "none";
});
const selectedLang = document.querySelectorAll(`[lang="${isoCode}"]`);
if (selectedLang.length > 0) {
selectedLang.forEach(function (userLang) {
userLang.classList.remove("hidden");
userLang.style.display = "block";
});
if (
window.user &&
window.user.locale &&
"true" === platformConfigStore.getSetting("editor.translate_html")
) {
var isoCode = normalizeLocale(window.user.locale)
const translateElement = document.querySelector(".mce-translatehtml")
if (translateElement) {
document.querySelectorAll(".mce-translatehtml").forEach(function (el) {
el.style.display = "none"
})
const selectedLang = document.querySelectorAll(`[lang="${isoCode}"]`)
if (selectedLang.length > 0) {
selectedLang.forEach(function (userLang) {
userLang.classList.remove("hidden")
userLang.style.display = "block"
})
}
}
}
// it checks content from old version
const langSpans = document.querySelectorAll('span[lang]');
const langs = [...langSpans].filter(span => !span.classList.contains('mce-translatehtml'));
// it checks content from old version
const langSpans = document.querySelectorAll('span[lang]')
const langs = [...langSpans].filter(span => !span.classList.contains('mce-translatehtml'))
if (langs.length > 0) {
// it hides all contents with lang
langs.forEach(function (el) {
el.style.display = "none";
});
if (langs.length > 0) {
// it hides all contents with lang
langs.forEach(function (el) {
el.style.display = "none"
})
const selectedLang = document.querySelectorAll(`span[lang="${isoCode}"]`);
if (selectedLang.length > 0) {
selectedLang.forEach(function (userLang) {
userLang.classList.remove("hidden");
userLang.style.display = "block";
});
const selectedLang = document.querySelectorAll(`span[lang="${isoCode}"]`)
if (selectedLang.length > 0) {
selectedLang.forEach(function (userLang) {
userLang.classList.remove("hidden")
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 props = defineProps({
isAllowedToEdit: {
type: Boolean,
required: true
}
})
courseService.loadHomeIntro(course.value.id, session.value?.id).then((data) => (intro.value = data))
const goToIntroCreate = () => {
@ -77,20 +84,21 @@ defineExpose({
v-if="intro.introText"
v-html="intro.introText"
/>
<EmptyState
v-else
:detail="t('Add a course introduction to display to your students.')"
:summary="t('You don\'t have any course content yet.')"
icon="courses"
>
<BaseButton
:label="t('Course introduction')"
class="mt-4"
icon="plus"
type="primary"
@click="goToIntroCreate"
/>
</EmptyState>
<div v-else-if="isAllowedToEdit">
<EmptyState
:detail="t('Add a course introduction to display to your students.')"
:summary="t('You don\'t have any course content yet.')"
icon="courses"
>
<BaseButton
:label="t('Course introduction')"
class="mt-4"
icon="plus"
type="primary"
@click="goToIntroCreate"
/>
</EmptyState>
</div>
</div>
<Skeleton
v-else

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

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

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

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

@ -1972,7 +1972,7 @@ function show_add_post_form(CForum $forum, CForumThread $thread, CForumPost $pos
if ($showPreview) {
if ('newthread' !== $action && !empty($threadId)) {
$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)) {
$form->addElement('label', get_lang('Thread'), $iframe);

@ -25,8 +25,11 @@ use Chamilo\CourseBundle\Entity\CForumThread;
*/
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.
api_protect_course_script(true);
api_protect_course_script(true, false, '', $cid);
$nameTools = get_lang('Forums');
@ -47,8 +50,8 @@ if (!empty($threadId)) {
$threadEntity = $repoThread->find($threadId);
}
$courseEntity = api_get_course_entity(api_get_course_int_id());
$sessionEntity = api_get_session_entity(api_get_session_id());
$courseEntity = api_get_course_entity($cid);
$sessionEntity = api_get_session_entity($sid);
/* Is the user allowed here? */
// 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);
}
$course_id = api_get_course_int_id();
$table_posts = Database::get_course_table(TABLE_FORUM_POST);
$table_users = Database::get_main_table(TABLE_MAIN_USER);

@ -885,9 +885,14 @@ function api_valid_email($address)
*
* @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();
if (isset($cid)) {
$course_info = api_get_course_info_by_id($cid);
}
if (empty($course_info)) {
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\Contracts\Translation\TranslatorInterface;
use Twig\Environment;
use ChamiloSession;
/**
* Class CourseListener.
@ -114,6 +115,9 @@ class CourseListener implements EventSubscriberInterface
$sessionHandler->set('cid', $course->getId());
$sessionHandler->set('_cid', $course->getCode());
$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.
$twig->addGlobal('course', $course);

Loading…
Cancel
Save