Adding language support to ckeditor, adding new Free answer strict in order to hide all toolbars but it show a wordcount (ckeditor plugin)

skala
Julio Montoya 12 years ago
parent d089576785
commit ab50aeb79b
  1. 5
      main/exercice/exercise.class.php
  2. 113
      main/exercice/exercise_show.php
  3. 14
      main/inc/lib/exercise.lib.php
  4. 4
      main/inc/lib/formvalidator/Element/html_editor.php
  5. 9
      src/ChamiloLMS/Component/Editor/Editor.php
  6. 18
      src/ChamiloLMS/Component/Editor/Toolbar/Basic.php
  7. 16
      src/ChamiloLMS/Component/Editor/Toolbar/TestFreeAnswer.php
  8. 49
      src/ChamiloLMS/Component/Editor/Toolbar/TestFreeAnswerStrict.php

@ -4276,6 +4276,7 @@ class Exercise
if ($debug) {
error_log('<-- end answer loop -->');
}
$final_answer = true;
foreach ($real_answers as $my_answer) {
if (!$my_answer) {
@ -4876,7 +4877,7 @@ class Exercise
}
/**
* @param array $user_data
* @param string $user_data
* @param string $start_date
* @param int $duration
* @return string
@ -6187,7 +6188,7 @@ class Exercise
// Shows the question + possible answers
$showTitle = $this->getHideQuestionTitle() == 1 ? false : true;
echo ExerciseLib::showQuestion($question_obj, false, $origin, $i, $showTitle, false, $user_choice, false);
echo ExerciseLib::showQuestion($question_obj, false, $origin, $i, $showTitle, false, $user_choice, false, null, false, $this->getModelType());
// Button save and continue
switch ($this->type) {

@ -26,7 +26,7 @@ require_once 'answer.class.php';
require_once '../inc/global.inc.php';
$urlMainExercise = api_get_path(WEB_CODE_PATH).'exercice/';
if (empty($origin) ) {
if (empty($origin)) {
$origin = isset($_REQUEST['origin']) ? $_REQUEST['origin'] : null;
}
@ -60,7 +60,7 @@ if ( empty ( $action ) ) { $action = isset($_REQUEST['actio
$id = intval($_REQUEST['id']); //exe id
if (empty($id)) {
api_not_allowed(true);
api_not_allowed(true);
}
if (api_is_course_session_coach(api_get_user_id(), api_get_course_int_id(), api_get_session_id())) {
@ -68,7 +68,7 @@ if (api_is_course_session_coach(api_get_user_id(), api_get_course_int_id(), api_
api_not_allowed(true);
}
}
$is_allowedToEdit = api_is_allowed_to_edit(null,true) || $is_courseTutor || api_is_session_admin() || api_is_drh();
$is_allowedToEdit = api_is_allowed_to_edit(null, true) || $is_courseTutor || api_is_session_admin() || api_is_drh();
//Getting results from the exe_id. This variable also contain all the information about the exercise
$track_exercise_info = ExerciseLib::get_exercise_track_exercise_info($id);
@ -89,7 +89,7 @@ $current_user_id = api_get_user_id();
$locked = api_resource_is_locked_by_gradebook($exercise_id, LINK_EXERCISE);
if (empty($objExercise)) {
$objExercise = new Exercise();
$objExercise = new Exercise();
$objExercise->read($exercise_id);
}
$feedback_type = $objExercise->feedback_type;
@ -98,7 +98,7 @@ $feedback_type = $objExercise->feedback_type;
//Only users can see their own results
if (!$is_allowedToEdit) {
if ($student_id != $current_user_id) {
api_not_allowed(true);
api_not_allowed(true);
}
}
@ -194,56 +194,59 @@ $show_only_total_score = false;
// Avoiding the "Score 0/0" message when the exe_id is not set
if (!empty($track_exercise_info)) {
// if the results_disabled of the Quiz is 1 when block the script
$result_disabled = $track_exercise_info['results_disabled'];
if (!(api_is_platform_admin() || api_is_course_admin()) ) {
if ($result_disabled == 1) {
//api_not_allowed();
$show_results = false;
//Display::display_warning_message(get_lang('CantViewResults'));
if ($origin != 'learnpath') {
echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">
// if the results_disabled of the Quiz is 1 when block the script
$result_disabled = $track_exercise_info['results_disabled'];
if (!(api_is_platform_admin() || api_is_course_admin()) ) {
if ($result_disabled == 1) {
$show_results = false;
if ($origin != 'learnpath') {
echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2">';
Display::display_warning_message(get_lang('ThankYouForPassingTheTest').'<br /><br />
<a href="'.$urlMainExercise.'exercice.php">'.(get_lang('BackToExercisesList')).'</a>', false);
echo '</td>
</tr>
</table>';
}
} elseif ($result_disabled == 2) {
$show_results = false;
$show_only_total_score = true;
if ($origin != 'learnpath') {
echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">
Display::display_warning_message(get_lang('ThankYouForPassingTheTest').'<br /><br />
<a href="'.$urlMainExercise.'exercice.php">'.(get_lang('BackToExercisesList')).'</a>', false);
echo '</td>
</tr>
</table>';
}
} elseif ($result_disabled == 2) {
$show_results = false;
$show_only_total_score = true;
if ($origin != 'learnpath') {
echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2">';
Display::display_warning_message(get_lang('ThankYouForPassingTheTest'), false);
echo '</td>
</tr>
</table>';
}
}
}
Display::display_warning_message(get_lang('ThankYouForPassingTheTest'), false);
echo '</td>
</tr>
</table>';
}
}
}
} else {
Display::display_warning_message(get_lang('CantViewResults'));
$show_results = false;
Display::display_warning_message(get_lang('CantViewResults'));
$show_results = false;
}
if ($origin == 'learnpath' && !isset($_GET['fb_type']) ) {
$show_results = false;
$show_results = false;
}
if ($show_results || $show_only_total_score) {
$user_info = api_get_user_info($student_id);
//Shows exercise header
echo $objExercise->show_exercise_result_header(api_get_person_name($user_info['firstName'], $user_info['lastName']), api_convert_and_format_date($exercise_date));
// Shows exercise header
echo $objExercise->show_exercise_result_header(
api_get_person_name($user_info['firstName'], $user_info['lastName']),
api_convert_and_format_date($exercise_date)
);
}
$i = $totalScore = $totalWeighting = 0;
if($debug>0){error_log("ExerciseResult: ".print_r($exerciseResult,1)); error_log("QuestionList: ".print_r($questionList,1));}
if ($debug>0) {
error_log("ExerciseResult: ".print_r($exerciseResult,1)); error_log("QuestionList: ".print_r($questionList,1));
}
$arrques = array();
$arrans = array();
@ -268,13 +271,13 @@ $question_list_from_database = array();
$exerciseResult = array();
while ($row = Database::fetch_array($result)) {
$question_list_from_database[] = $row['question_id'];
$exerciseResult[$row['question_id']] = $row['answer'];
$question_list_from_database[] = $row['question_id'];
$exerciseResult[$row['question_id']] = $row['answer'];
}
//Fixing #2073 Fixing order of questions
if (!empty($track_exercise_info['data_tracking'])) {
$temp_question_list = explode(',', $track_exercise_info['data_tracking']);
$temp_question_list = explode(',', $track_exercise_info['data_tracking']);
//Getting question list from data_tracking
if (!empty($temp_question_list)) {
@ -309,19 +312,20 @@ $media_list = array();
$category_list = array();
$tempParentId = null;
$mediaCounter = 0;
$arrid = array();
foreach ($questionList as $questionId) {
$choice = $exerciseResult[$questionId];
$choice = $exerciseResult[$questionId];
// creates a temporary Question object
// creates a temporary Question object
/** @var Question $objQuestionTmp */
$objQuestionTmp = Question::read($questionId);
$objQuestionTmp = Question::read($questionId);
$questionWeighting = $objQuestionTmp->selectWeighting();
$answerType = $objQuestionTmp->selectType();
$questionWeighting = $objQuestionTmp->selectWeighting();
$answerType = $objQuestionTmp->selectType();
// Start buffer
// Start buffer
ob_start();
/* Use switch
@ -537,8 +541,9 @@ foreach ($questionList as $questionId) {
$url_name = get_lang('AddComments');
}
}
echo '<br />';
echo Display::url($url_name, 'javascript://', array('class' => 'btn', 'onclick'=>"showfck('".$name."', '".$marksname."');"));
echo Display::url($url_name, 'javascript://', array('class' => 'btn', 'onclick' => "showfck('".$name."', '".$marksname."');"));
echo '<br />';
echo '<div id="feedback_'.$name.'" style="width:100%">';
@ -550,8 +555,9 @@ foreach ($questionList as $questionId) {
}
echo '</div>';
$arrid[] = $questionId;
echo '<div id="'.$name.'" style="display:none">';
$arrid[] = $questionId;
$feedback_form = new FormValidator('frmcomments'.$questionId,'post','');
$feedback_form->addElement('html','<br>');
$renderer =& $feedback_form->defaultRenderer();
@ -562,6 +568,13 @@ foreach ($questionList as $questionId) {
$feedback_form->addElement('html_editor', 'comments_'.$questionId, null, null, array('ToolbarSet' => 'TestAnswerFeedback', 'Width' => '100%', 'Height' => '120'));
$feedback_form->addElement('html','<br>');
$feedback_form->setDefaults($default);
$modelType = $objExercise->getModelType();
if ($modelType == EXERCISE_MODEL_TYPE_COMMITTEE) {
//$app['orm']->getRepository()
}
$feedback_form->display();
echo '</div>';

@ -2,7 +2,7 @@
/* For licensing terms, see /license.txt */
/**
* Exercise library
* @todo convert this lib into a static class
* @todo move this in exercise.class or question.class depending of the functions.
*
* shows a question and its answers
* @package chamilo.exercise
@ -20,7 +20,7 @@ class ExerciseLib
{
/**
* Shows a question
*
* @todo move to the Exercise class
* @param int question id
* @param bool if true only show the questions, no exercise title
* @param bool origin i.e = learnpath
@ -37,7 +37,8 @@ class ExerciseLib
$user_choice = array(),
$show_comment = false,
$exercise_feedback = null,
$show_answers = false
$show_answers = false,
$modelType = null
) {
// Text direction for the current language
//$is_ltr_text_direction = api_get_text_direction() != 'rtl';
@ -160,7 +161,12 @@ class ExerciseLib
$num_suggestions = ($nbrAnswers - $j) + 1;
} elseif ($answerType == FREE_ANSWER) {
$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'));
$toolBar = 'TestFreeAnswer';
if ($modelType == EXERCISE_MODEL_TYPE_COMMITTEE) {
$toolBar = 'TestFreeAnswerStrict';
}
$form->addElement('html_editor', "choice[".$questionId."]", null, array('id' => "choice[".$questionId."]"), array('ToolbarSet' => $toolBar));
$form->setDefaults(array("choice[".$questionId."]" => $content));
$s .= $form->return_form();
} elseif ($answerType == ORAL_EXPRESSION) {

@ -52,9 +52,9 @@ class HTML_QuickForm_html_editor extends HTML_QuickForm_textarea
$this->fullPage = false;
$name = $this->getAttribute('name');
global $app;
//$this->fck_editor = new FCKeditor($name);
$this->fck_editor = new ChamiloLMS\Component\Editor\Editor($name);
$this->fck_editor = new ChamiloLMS\Component\Editor\Editor($name, $app['translator']);
$this->fck_editor->ToolbarSet = $fck_attribute['ToolbarSet'];
$this->fck_editor->Width = !empty($fck_attribute['Width']) ? $fck_attribute['Width'] : '990';

@ -47,13 +47,16 @@ class Editor
*/
public $Config;
/** @var \Symfony\Component\Translation\Translator */
public $translator;
/**
* Main Constructor.
* Refer to the _samples/php directory for examples.
*
* @param string $instanceName
*/
public function __construct($instanceName)
public function __construct($instanceName, \Symfony\Component\Translation\Translator $translator)
{
$this->InstanceName = $instanceName;
$this->Width = '100%';
@ -61,6 +64,7 @@ class Editor
$this->ToolbarSet = 'Basic';
$this->Value = '';
$this->Config = array();
$this->translator = $translator;
}
/**
@ -88,6 +92,7 @@ class Editor
public function ckeditorReplace()
{
$toolbar = new Toolbar\Basic($this->ToolbarSet);
$toolbar->setLanguage($this->translator->getLocale());
$config = $toolbar->getConfig();
$js = $this->to_js($config);
$settings = null;
@ -194,7 +199,7 @@ class Editor
return '[ '.implode(', ', $output).' ]';
}
// Otherwise, fall through to convert the array as an object.
case 'object' :
case 'object':
$output = array();
foreach ($var as $k => $v) {
$output[] = $this->to_js(strval($k)).': '.$this->to_js($v);

@ -72,8 +72,20 @@ class Basic
filebrowserImageUploadUrl
filebrowserUploadUrl*/
//$config['extraPlugins'] = 'oembed,video,wordcount';
$config['extraPlugins'] = 'oembed,video';
/*$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'
);*/
if (isset($this->config)) {
$this->config = array_merge($config, $this->config);
} else {
@ -84,5 +96,11 @@ class Basic
//$config['height'] = '200';
return $this->config;
}
public function setLanguage($language)
{
$this->config['language'] = $language;
}
}

@ -22,10 +22,24 @@ class TestFreeAnswer extends Basic
array('name' => 'colors'),
array('name' => 'tools'),
array('name' => 'others'),
array('name' => 'mode') // source
array('name' => 'mode')
);
$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;

@ -0,0 +1,49 @@
<?php
namespace ChamiloLMS\Component\Editor\Toolbar;
class TestFreeAnswerStrict 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'),
array('name' => 'mode')*/
);
$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['removePlugins'] = 'elementspath';
//$config['height'] = '200';
return $config;
}
}
Loading…
Cancel
Save