From b2910dcc84f7388dc81afd8908fdb4c04d703d4f Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Wed, 29 Mar 2017 12:14:42 +0200 Subject: [PATCH] Add ckeditor to matching and matching drag n drop see BT#12303 --- main/exercise/MatchingDraggable.php | 34 ++++-- main/exercise/matching.class.php | 24 +++- .../Editor/CkEditor/Toolbar/TestMatching.php | 106 ++++++++++++++++++ 3 files changed, 153 insertions(+), 11 deletions(-) create mode 100644 src/Chamilo/CoreBundle/Component/Editor/CkEditor/Toolbar/TestMatching.php diff --git a/main/exercise/MatchingDraggable.php b/main/exercise/MatchingDraggable.php index 83a9935d49..3db5fb0bfb 100644 --- a/main/exercise/MatchingDraggable.php +++ b/main/exercise/MatchingDraggable.php @@ -118,9 +118,14 @@ class MatchingDraggable extends Question Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer')); } + $editorConfig = array( + 'ToolbarSet' => 'TestMatching', + 'Width' => '100%', + 'Height' => '125' + ); + for ($i = 1; $i <= $nb_matches; ++$i) { $renderer = &$form->defaultRenderer(); - $renderer->setElementTemplate( '{error}{element}', "answer[$i]" @@ -138,16 +143,22 @@ class MatchingDraggable extends Question $form->addHtml(''); $form->addHtml("$i"); - $form->addText("answer[$i]", null); + + //$form->addText("answer[$i]", null); + $form->addHtmlEditor( + "answer[$i]", + null, + null, + false, + $editorConfig + ); + $form->addSelect("matches[$i]", null, $matches); $form->addText("weighting[$i]", null, true, ['style' => 'width: 60px;', 'value' => 10]); $form->addHtml(''); } $form->addHtml(''); - $group = array(); - - $form->addGroup($group); // DISPLAY OPTIONS $html = ' @@ -176,19 +187,24 @@ class MatchingDraggable extends Question $form->addHtml(''); $form->addHtml(''); - $form->addText("option[$i]", null); + //$form->addText("option[$i]", null); + $form->addHtmlEditor( + "option[$i]", + null, + null, + false, + $editorConfig + ); $form->addHtml(''); } $form->addHtml('
' . chr(64 + $i) . '
'); - $group = array(); global $text; - + $group = array(); // setting the save button here and not in the question class.php $group[] = $form->addButtonDelete(get_lang('DelElem'), 'lessOptions', true); $group[] = $form->addButtonCreate(get_lang('AddElem'), 'moreOptions', true); $group[] = $form->addButtonSave($text, 'submitQuestion', true); - $form->addGroup($group); if (!empty($this->id)) { diff --git a/main/exercise/matching.class.php b/main/exercise/matching.class.php index db6be626a9..a8d831376a 100755 --- a/main/exercise/matching.class.php +++ b/main/exercise/matching.class.php @@ -123,6 +123,12 @@ class Matching extends Question ); } + $editorConfig = array( + 'ToolbarSet' => 'TestMatching', + 'Width' => '100%', + 'Height' => '125' + ); + for ($i = 1; $i <= $nb_matches; ++$i) { $renderer = &$form->defaultRenderer(); $renderer->setElementTemplate( @@ -142,7 +148,14 @@ class Matching extends Question $form->addHtml(''); $form->addHtml("$i"); - $form->addText("answer[$i]", null); + //$form->addText("answer[$i]", null); + $form->addHtmlEditor( + "answer[$i]", + null, + null, + false, + $editorConfig + ); $form->addSelect( "matches[$i]", null, @@ -188,7 +201,14 @@ class Matching extends Question $form->addHtml(''); $form->addHtml('' . chr(64 + $i) . ''); - $form->addText("option[$i]", null); + $form->addHtmlEditor( + "option[$i]", + null, + null, + false, + $editorConfig + ); + $form->addHtml(''); } diff --git a/src/Chamilo/CoreBundle/Component/Editor/CkEditor/Toolbar/TestMatching.php b/src/Chamilo/CoreBundle/Component/Editor/CkEditor/Toolbar/TestMatching.php new file mode 100644 index 0000000000..c2e5499d0f --- /dev/null +++ b/src/Chamilo/CoreBundle/Component/Editor/CkEditor/Toolbar/TestMatching.php @@ -0,0 +1,106 @@ +getNormalToolbar(); + } else { + $config['toolbar_minToolbar'] = $this->getMinimizedToolbar(); + $config['toolbar_maxToolbar'] = $this->getMaximizedToolbar(); + } + + $config['fullPage'] = false; + $config['extraPlugins'] = 'wordcount'; + $config['wordcount'] = array( + // Whether or not you want to show the Word Count + 'showWordCount' => true, + // Whether or not you want to show the Char Count + 'showCharCount' => true, + // Option to limit the characters in the Editor + 'charLimit' => 'unlimited', + // Option to limit the words in the Editor + 'wordLimit' => 'unlimited' + ); + + //$config['height'] = '200'; + + return $config; + } + + /** + * Get the toolbar configuration when CKEditor is maximized + * @return array + */ + protected function getMaximizedToolbar() + { + return [ + ['NewPage', 'Templates', '-', 'Preview', 'Print'], + ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord'], + ['Undo', 'Redo', '-', 'SelectAll', 'Find', '-', 'RemoveFormat'], + ['Link', 'Unlink', 'Anchor', 'Glossary'], + ['Image', 'Mapping', 'Video', 'Oembed', 'Youtube', 'Flash', 'Audio', 'leaflet', 'Smiley', 'SpecialChar', 'Asciimath',], + '/', + ['Table', '-', 'CreateDiv'], + ['BulletedList', 'NumberedList', 'HorizontalRule', '-', 'Outdent', 'Indent', 'Blockquote'], + ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'], + ['Bold', 'Italic', 'Underline', 'Strike', '-', 'Subscript', 'Superscript', '-', 'TextColor', 'BGColor'], + [api_get_setting('allow_spellcheck') == 'true' ? 'Scayt' : ''], + ['Styles', 'Format', 'Font', 'FontSize'], + ['PageBreak', 'ShowBlocks'], + ['Toolbarswitch'] + ]; + } + + /** + * Get the default toolbar configuration when the setting more_buttons_maximized_mode is false + * @return array + */ + protected function getNormalToolbar() + { + return [ + [ + 'Maximize', + 'Bold', + 'Image', + 'Link', + 'PasteFromWord', + 'Audio', + 'Table', + 'Subscript', + 'Superscript', + 'ShowBlocks' + ] + ]; + } + + /** + * Get the toolbar configuration when CKEditor is minimized + * @return array + */ + protected function getMinimizedToolbar() + { + return [ + $this->getNewPageBlock(), + ['Undo', 'Redo'], + ['Link', 'Image', 'Video', 'Flash', 'Audio', 'Table', 'Asciimath'], + ['BulletedList', 'NumberedList', 'HorizontalRule'], + ['JustifyLeft', 'JustifyCenter', 'JustifyBlock'], + ['Format', 'Font', 'FontSize', 'Bold', 'Italic', 'Underline', 'TextColor', 'BGColor'], + ['Toolbarswitch'] + ]; + } +}