Admin: Add config allow_quick_question_description_popup

Allows a quick question description edition with a selected
image from a popup.

BT#18814
pull/3892/head
Julio Montoya 4 years ago
parent d925a2a120
commit 0a4b4ea2e4
  1. 44
      main/exercise/question_list_admin.inc.php
  2. 39
      main/inc/ajax/exercise.ajax.php
  3. 2
      main/inc/lib/elfinder/filemanager.php
  4. 3
      main/install/configuration.dist.php
  5. 13
      main/template/default/javascript/editor/elfinder_standalone.tpl

@ -32,6 +32,7 @@ if ($deleteQuestion) {
unset($objQuestionTmp);
}
$ajax_url = api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?'.api_get_cidreq().'&exercise_id='.intval($exerciseId);
$addImageUrl = api_get_path(WEB_CODE_PATH).'inc/lib/elfinder/filemanager.php?add_image=1&'.api_get_cidreq();
?>
<div id="dialog-confirm"
title="<?php echo get_lang('ConfirmYourChoice'); ?>"
@ -41,6 +42,33 @@ $ajax_url = api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?'.api_get_cidreq().'&
</p>
</div>
<script>
function addImageToQuestion(image, questionId) {
let url = '<?php echo $ajax_url; ?>' + '&a=save_question_description&question_id=' + questionId;
let params = {
image: image
}
$.ajax({
url: url,
data: params,
success: function (data) {
window.alert('<?php echo addslashes(get_lang('Updated')); ?>');
}
});
}
function loadEditor(button, questionId) {
event.preventDefault();
let url = '<?php echo $addImageUrl; ?>' + '&question_id=' + questionId;
let w = 850;
let h = 500;
let left = (screen.width / 2) - (w / 2);
let top = (screen.height / 2) - (h / 2);
let params = 'height=' + h + ',width=' + w + ',resizable=0,top=' + top + ',left=' + left;
setTimeout(() => window.open(url, 'editor', params), 1000);
return;
}
$(function () {
$("#dialog:ui-dialog").dialog("destroy");
$("#dialog-confirm").dialog({
@ -226,6 +254,20 @@ if (!$inATest) {
continue;
}
$addImageLink = '';
if (api_get_configuration_value('allow_quick_question_description_popup')) {
$addImageLink = Display::url(
Display::return_icon(
'image.png',
get_lang('AddImage'),
[],
ICON_SIZE_TINY
),
'javascript:void(0);',
['class' => 'btn btn-default btn-sm ajax', 'onclick' => 'loadEditor(this, '.$id.')']
);
}
$clone_link = Display::url(
Display::return_icon(
'cd.png',
@ -292,7 +334,7 @@ if (!$inATest) {
$btnActions = implode(
PHP_EOL,
[$edit_link, $clone_link, $delete_link]
[$edit_link, $clone_link, $addImageLink, $delete_link]
);
$title = Security::remove_XSS($objQuestionTmp->selectTitle());

@ -4,6 +4,7 @@
use Chamilo\CoreBundle\Entity\TrackEExerciseConfirmation;
use Chamilo\CoreBundle\Entity\TrackEExercises;
use Chamilo\CourseBundle\Entity\CQuizQuestion;
use ChamiloSession as Session;
require_once __DIR__.'/../global.inc.php';
@ -417,6 +418,44 @@ switch ($action) {
echo Display::page_subheader(get_lang('VerificationOfAnsweredQuestions'));
echo $objExercise->getReminderTable($questionList, $statInfo, true);
break;
case 'save_question_description':
if (!api_get_configuration_value('allow_quick_question_description_popup')) {
exit;
}
if (!api_is_allowed_to_edit(null, true)) {
exit;
}
/** @var \Exercise $objExercise */
$objExercise = Session::read('objExercise');
if (empty($objExercise)) {
exit;
}
$questionId = isset($_REQUEST['question_id']) ? (int) $_REQUEST['question_id'] : null;
$image = isset($_REQUEST['image']) ? $_REQUEST['image'] : '';
$questionList = $objExercise->getQuestionList();
if (!in_array($questionId, $questionList)) {
echo '0';
exit;
}
$em = Database::getManager();
$repo = $em->getRepository(CQuizQuestion::class);
/** @var CQuizQuestion $question */
$question = $repo->find($questionId);
if (null !== $question) {
$question->setDescription('<img src="'.$image.'" />');
$em->persist($question);
$em->flush();
echo 1;
exit;
}
echo 0;
exit;
break;
case 'save_exercise_by_now':
header('Content-Type: application/json');

@ -17,7 +17,9 @@ if (file_exists($file)) {
$includeFile = '<script type="text/javascript" src="'.api_get_path(WEB_PATH).$filePart.'"></script>';
$language = $iso;
}
$questionId = isset($_REQUEST['question_id']) ? (int) $_REQUEST['question_id'] : 0;
$template->assign('question_id', $questionId);
$template->assign('elfinder_lang', $language);
$template->assign('elfinder_translation_file', $includeFile);
$template->display('default/javascript/editor/ckeditor/elfinder.tpl');

@ -1929,6 +1929,9 @@ ALTER TABLE gradebook_comment ADD CONSTRAINT FK_C3B70763AD3ED51C FOREIGN KEY (gr
// Shows only users from active sessions in tracking.
//$_configuration['show_users_in_active_sessions_in_tracking'] = true;
// Allows a quick question description edition with a selected image from a popup.
//$_configuration['allow_quick_question_description_popup'] = true;
// KEEP THIS AT THE END
// -------- Custom DB changes
// Add user activation by confirmation email

@ -9,7 +9,7 @@
<!-- elFinder translation (OPTIONAL) -->
{{ elfinder_translation_file }}
<script type="text/javascript" charset="utf-8">
<script charset="utf-8">
// Helper function to get parameters from the query string.
function getUrlParam(paramName) {
var reParam = new RegExp('(?:[\?&]|&amp;)' + paramName + '=([^&]+)', 'i');
@ -22,7 +22,16 @@
var elf = $('#elfinder').elfinder({
url : '{{ _p.web_lib ~ 'elfinder/connectorAction.php?' }}{{ course_condition }}', // connector URL (REQUIRED)
getFileCallback : function(file) {
window.opener.CKEDITOR.tools.callFunction(funcNum, file.url);
if (window.opener) {
if (window.opener.CKEDITOR) {
window.opener.CKEDITOR.tools.callFunction(funcNum, file.url);
}
if (window.opener.addImageToQuestion) {
window.opener.addImageToQuestion(file.url, {{ question_id }});
}
}
window.close();
},
startPathHash: 'l2_Lw', // Sets the course driver as default

Loading…
Cancel
Save