Adding ckeditor support in free answers

skala
Julio Montoya 12 years ago
parent f8e3d7cf7d
commit ed060f8f2a
  1. 17
      main/exercice/exercise_submit.php
  2. 9
      main/exercice/hotspot_admin.inc.php
  3. 28
      main/inc/lib/exercise.lib.php
  4. 34
      src/ChamiloLMS/Component/Editor/Toolbar/TestFreeAnswer.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\')) {

@ -838,7 +838,6 @@ if ($modifyAnswers) {
$oFCKeditor->Height = '100';
$oFCKeditor->Value = $content;
$return = $oFCKeditor->CreateHtml();
/* <td align="left"><textarea wrap="virtual" rows="1" cols="25" name="comment[<?php echo $i; ?>]" style="width: 100%"><?php echo api_htmlentities($comment[$i], ENT_QUOTES, api_get_system_encoding()); ?></textarea></td> */
?>
<td>&nbsp;</td>
<td align="left" ><?php echo $return; ?></td>
@ -853,15 +852,15 @@ if ($modifyAnswers) {
?>
<input type="hidden" name="weighting[<?php echo $i; ?>]" class="span3" value="0" />
<?php } else { ?>
<input type="text" name="weighting[<?php echo $i; ?>]" class="span3" value="<?php echo (isset($weighting[$i]) ? $weighting[$i] : 10); ?>" />
<input type="text" name="weighting[<?php echo $i; ?>]" class="span3" value="<?php echo (isset($weighting[$i]) ? $weighting[$i] : 10); ?>" />
<?php
}
}
if ($answerType == HOT_SPOT) {
?>
<input type="text" name="weighting[<?php echo $i; ?>]" class="span3" value="<?php echo (isset($weighting[$i]) ? $weighting[$i] : 10); ?>" />
<input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="<?php echo (empty($hotspot_coordinates[$i]) ? '0;0|0|0' : $hotspot_coordinates[$i]); ?>" />
<input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="<?php echo (empty($hotspot_type[$i]) ? 'square' : $hotspot_type[$i]); ?>" />
<input type="text" name="weighting[<?php echo $i; ?>]" class="span3" value="<?php echo (isset($weighting[$i]) ? $weighting[$i] : 10); ?>" />
<input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="<?php echo (empty($hotspot_coordinates[$i]) ? '0;0|0|0' : $hotspot_coordinates[$i]); ?>" />
<input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="<?php echo (empty($hotspot_type[$i]) ? 'square' : $hotspot_type[$i]); ?>" />
<?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;

@ -0,0 +1,34 @@
<?php
namespace ChamiloLMS\Component\Editor\Toolbar;
class TestFreeAnswer extends Basic
{
public function getConfig()
{
$config['toolbarGroups'] = array(
// array('name' => '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;
}
}
Loading…
Cancel
Save