From ed060f8f2a53e6ced049b572cbee7e299952e003 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 29 May 2013 18:06:11 +0200 Subject: [PATCH] Adding ckeditor support in free answers --- main/exercice/exercise_submit.php | 17 ++++------ main/exercice/hotspot_admin.inc.php | 9 +++-- main/inc/lib/exercise.lib.php | 28 +++++++-------- .../Editor/Toolbar/TestFreeAnswer.php | 34 +++++++++++++++++++ 4 files changed, 57 insertions(+), 31 deletions(-) create mode 100644 src/ChamiloLMS/Component/Editor/Toolbar/TestFreeAnswer.php diff --git a/main/exercice/exercise_submit.php b/main/exercice/exercise_submit.php index 87f707bc3d..91526457f0 100644 --- a/main/exercice/exercise_submit.php +++ b/main/exercice/exercise_submit.php @@ -1052,16 +1052,13 @@ if (!empty($error)) { //3. Hotspots var hotspot = $(\'*[name*="hotspot[\'+question_id+\']"]\').serialize(); - // Checking FCK - if (typeof(FCKeditorAPI) !== "undefined") { - var oEditor = FCKeditorAPI.GetInstance("choice["+question_id+"]") ; - var fck_content = ""; - if (oEditor) { - fck_content = oEditor.GetHTML(); - my_choice = {}; - my_choice["choice["+question_id+"]"] = fck_content; - my_choice = $.param(my_choice); - } + var ckeditor = CKEDITOR.instances[\'choice[\'+question_id+\']\']; + + if (ckeditor) { + value = ckeditor.getData(); + my_choice = {}; + my_choice["choice["+question_id+"]"] = value; + my_choice = $.param(my_choice); } if ($(\'input[name="remind_list[\'+question_id+\']"]\').is(\':checked\')) { diff --git a/main/exercice/hotspot_admin.inc.php b/main/exercice/hotspot_admin.inc.php index 52d7b5bf5b..f1dd184320 100644 --- a/main/exercice/hotspot_admin.inc.php +++ b/main/exercice/hotspot_admin.inc.php @@ -838,7 +838,6 @@ if ($modifyAnswers) { $oFCKeditor->Height = '100'; $oFCKeditor->Value = $content; $return = $oFCKeditor->CreateHtml(); - /* */ ?>   @@ -853,15 +852,15 @@ if ($modifyAnswers) { ?> - + - - - + + + diff --git a/main/inc/lib/exercise.lib.php b/main/inc/lib/exercise.lib.php index 8dbe4aadd6..cc0567dd0c 100644 --- a/main/inc/lib/exercise.lib.php +++ b/main/inc/lib/exercise.lib.php @@ -59,10 +59,14 @@ class ExerciseLib $pictureName = $objQuestionTmp->selectPicture(); $s = null; + // @todo use a formvalidator + $form = new FormValidator('question'); + $renderer = $form->defaultRenderer(); + $form_template = '{content}'; + $renderer->setFormTemplate($form_template); if ($answerType != HOT_SPOT && $answerType != HOT_SPOT_DELINEATION) { // Question is not a hotspot - if (!$only_questions) { $questionDescription = $objQuestionTmp->selectDescription(); if ($show_title) { @@ -138,13 +142,10 @@ class ExerciseLib } $num_suggestions = ($nbrAnswers - $j) + 1; } elseif ($answerType == FREE_ANSWER) { - $fck_content = isset($user_choice[0]) && !empty($user_choice[0]['answer']) ? $user_choice[0]['answer'] : null; - $oFCKeditor = new FCKeditor("choice[".$questionId."]"); - $oFCKeditor->ToolbarSet = 'TestFreeAnswer'; - $oFCKeditor->Width = '100%'; - $oFCKeditor->Height = '200'; - $oFCKeditor->Value = $fck_content; - $s .= $oFCKeditor->CreateHtml(); + $content = isset($user_choice[0]) && !empty($user_choice[0]['answer']) ? $user_choice[0]['answer'] : null; + $form->addElement('html_editor', "choice[".$questionId."]", null, array('id' => "choice[".$questionId."]"), array('ToolbarSet' => 'TestFreeAnswer')); + $form->setDefaults(array("choice[".$questionId."]" => $content)); + $s .= $form->return_form(); } elseif ($answerType == ORAL_EXPRESSION) { // Add nanogong if (api_get_setting('enable_nanogong') == 'true') { @@ -170,13 +171,9 @@ class ExerciseLib $s .= $nano->show_button(); } - $oFCKeditor = new FCKeditor("choice[".$questionId."]"); - $oFCKeditor->ToolbarSet = 'TestFreeAnswer'; - $oFCKeditor->Width = '100%'; - $oFCKeditor->Height = '150'; - $oFCKeditor->ToolbarStartExpanded = false; - $oFCKeditor->Value = ''; - $s .= $oFCKeditor->CreateHtml(); + $form->addElement('html_editor', "choice[".$questionId."]", null, array('id' => "choice[".$questionId."]"), array('ToolbarSet' => 'TestFreeAnswer')); + //$form->setDefaults(array("choice[".$questionId."]" => $content)); + $s .= $form->return_form(); } // Now navigate through the possible answers, using the max number of @@ -241,7 +238,6 @@ class ExerciseLib } $answer = Security::remove_XSS($answer, STUDENT); - $s .= Display::input('hidden', 'choice2['.$questionId.']', '0'); $answer_input = null; diff --git a/src/ChamiloLMS/Component/Editor/Toolbar/TestFreeAnswer.php b/src/ChamiloLMS/Component/Editor/Toolbar/TestFreeAnswer.php new file mode 100644 index 0000000000..82b340c3a5 --- /dev/null +++ b/src/ChamiloLMS/Component/Editor/Toolbar/TestFreeAnswer.php @@ -0,0 +1,34 @@ + 'document', 'groups' =>array('mode', 'document', 'doctools')), +// array('name' => 'clipboard', 'groups' =>array('clipboard', 'undo', )), + //array('name' => 'editing', 'groups' =>array('clipboard', 'undo', )), + //array('name' => 'forms', 'groups' =>array('clipboard', 'undo', )), + '/', + array('name' => 'basicstyles', 'groups' =>array('basicstyles', 'cleanup', )), + array('name' => 'paragraph', 'groups' =>array('list', 'indent', 'blocks', 'align' )), + array('name' => 'links'), + array('name' => 'insert'), + '/', + array('name' => 'styles'), + array('name' => 'colors'), + array('name' => 'tools'), + array('name' => 'others') + ); + + $config['fullPage'] = 'true'; + //$config['height'] = '200'; + + return $config; + } +} + +