Using textarea instead ckeditor if course exercise setting was set to "fast edition" see BT#6264 + adding UniqueAnswerImage toolbar

skala
Julio Montoya 13 years ago
parent 7359739be9
commit 1b7bdfa3b5
  1. 18
      main/exercice/admin.php
  2. 11
      main/exercice/draggable.class.php
  3. 2
      main/exercice/exercise.class.php
  4. 4
      main/exercice/fill_blanks.class.php
  5. 12
      main/exercice/freeanswer.class.php
  6. 126
      main/exercice/global_multiple_answer.class.php
  7. 8
      main/exercice/media_question.class.php
  8. 42
      main/exercice/multiple_answer.class.php
  9. 386
      main/exercice/multiple_answer_combination.class.php
  10. 48
      main/exercice/multiple_answer_true_false.class.php
  11. 15
      main/exercice/question.class.php
  12. 48
      main/exercice/unique_answer.class.php
  13. 69
      main/exercice/unique_answer_image.class.php
  14. 34
      src/ChamiloLMS/Component/Editor/Toolbar/UniqueAnswerImage.php

@ -119,9 +119,11 @@ if (empty($modifyExercise)) {
delete_all_incomplete_attempts(api_get_user_id(), $exerciseId, api_get_course_int_id(), api_get_session_id());
// get from session
/** @var Exercise $objExercise */
$objExercise = isset($_SESSION['objExercise']) ? $_SESSION['objExercise'] : 0;
/** @var Question $objQuestion */
$objQuestion = isset($_SESSION['objQuestion']) ? $_SESSION['objQuestion'] : 0;
/** @var Answer $objAnswer */
$objAnswer = isset($_SESSION['objAnswer'])?$_SESSION['objAnswer']:0;
// document path
@ -142,13 +144,6 @@ $aType = array(
get_lang('FreeAnswer')
);
$fastEdition = api_get_course_setting('allow_fast_exercise_edition') == 1 ? true : false;
//$fastEdition = false;
if ($fastEdition) {
$htmlHeadXtra[] = api_get_jqgrid_js();
}
// tables used in the exercise tool
if (!empty($_GET['action']) && $_GET['action'] == 'exportqti2' && !empty($_GET['questionId'])) {
@ -189,6 +184,10 @@ if (!is_object($objExercise)) {
Session::write('objExercise', $objExercise);
}
if ($objExercise->fastEdition) {
$htmlHeadXtra[] = api_get_jqgrid_js();
}
// Doesn't select the exercise ID if we come from the question pool
if (!isset($fromExercise) or !$fromExercise) {
// gets the right exercise ID, and if 0 creates a new exercise
@ -600,7 +599,8 @@ if (!$newQuestion && !$modifyQuestion && !$editQuestion && !isset($_GET['hotspot
Display::display_normal_message(get_lang('AllQuestionsMustHaveACategory'));
}
// Question list (drag n drop view)
if ($fastEdition) {
// @todo this bad do not require files like this
if ($objExercise->fastEdition) {
require 'question_list_pagination_admin.inc.php';
} else {
require 'question_list_admin.inc.php';

@ -12,11 +12,6 @@
/**
* Code
*/
/**
* Matching questions type class
* @package chamilo.exercise
*/
class Draggable extends Matching
{
static $typePicture = 'matching.gif';
@ -25,7 +20,7 @@ class Draggable extends Matching
/**
* Constructor
*/
function Draggable()
public function Draggable()
{
parent::question();
$this->type = DRAGGABLE;
@ -34,7 +29,7 @@ class Draggable extends Matching
/**
* Function which redefines Question::createAnswersForm
* @param the formvalidator instance
* @param FormValidator instance
*/
public function createAnswersForm($form)
{
@ -168,7 +163,7 @@ class Draggable extends Matching
/**
* abstract function which creates the form to create / edit the answers of the question
* @param the formvalidator instance
* @param FormValidator instance
*/
public function processAnswersCreation($form)
{

@ -73,6 +73,7 @@ class Exercise
public $loadQuestionAJAX = false;
public $emailNotificationTemplate = null;
public $countQuestions = 0;
public $fastEdition = false;
/**
* Constructor of the class
@ -173,6 +174,7 @@ class Exercise
}
$this->force_edit_exercise_in_lp = isset($_configuration['force_edit_exercise_in_lp']) ? $_configuration['force_edit_exercise_in_lp'] : false;
$this->fastEdition = api_get_course_setting('allow_fast_exercise_edition') == 1 ? true : false;
if ($this->exercise_was_added_in_lp) {
$this->edit_exercise_in_lp = $this->force_edit_exercise_in_lp == true;

@ -30,7 +30,7 @@ class FillBlanks extends Question
/**
* Constructor
*/
function FillBlanks()
public function FillBlanks()
{
parent::question();
$this->type = FILL_IN_BLANKS;
@ -39,7 +39,7 @@ class FillBlanks extends Question
/**
* function which redifines Question::createAnswersForm
* @param \Formvalidator instance
* @param \FormValidator instance
*/
public function createAnswersForm($form)
{

@ -24,7 +24,7 @@ class FreeAnswer extends Question
/**
* Constructor
*/
function __construct()
public function __construct()
{
parent::question();
$this->type = FREE_ANSWER;
@ -32,10 +32,10 @@ class FreeAnswer extends Question
}
/**
* function which redifines Question::createAnswersForm
* @param the formvalidator instance
* function which redefines Question::createAnswersForm
* @param FormValidator instance
*/
function createAnswersForm($form)
public function createAnswersForm($form)
{
$form->addElement('text', 'weighting', get_lang('Weighting'), array('class' => 'span1'));
// setting the save button here and not in the question class.php
@ -51,9 +51,9 @@ class FreeAnswer extends Question
/**
* abstract function which creates the form to create / edit the answers of the question
* @param the formvalidator instance
* @param FormValidator instance
*/
function processAnswersCreation($form)
public function processAnswersCreation($form)
{
$this->weighting = $form->getSubmitValue('weighting');
$this->save();

@ -7,20 +7,22 @@ class GlobalMultipleAnswer extends Question
static $typePicture = 'mcmagl.gif';
static $explanationLangVar = 'GlobalMultipleAnswer';
/* Constructor */
function GlobalMultipleAnswer() {
/**
*
*/
public function GlobalMultipleAnswer()
{
parent::question();
$this->type = GLOBAL_MULTIPLE_ANSWER;
$this->type = GLOBAL_MULTIPLE_ANSWER;
$this->isContent = $this->getIsContent();
}
/**
* function which redifines Question::createAnswersForm
* @param the formvalidator instance
* @param the answers number to display
* function which redefines Question::createAnswersForm
* @param FormValidator instance
*/
function createAnswersForm($form) {
public function createAnswersForm($form)
{
$nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4;
$nb_answers += (isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0));
@ -31,27 +33,27 @@ class GlobalMultipleAnswer extends Question
$html = '<table class="data_table">
<tr>
<th width="10px">
' . get_lang('Number') . '
'.get_lang('Number').'
</th>
<th width="10px">
' . get_lang('True') . '
'.get_lang('True').'
</th>
<th width="50%">
' . get_lang('Answer') . '
'.get_lang('Answer').'
</th>';
// Espace entre l'entete et les r<EFBFBD>ponses
if ($obj_ex->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
$html .='<th>' . get_lang('Comment') . '</th>';
$html .= '<th>'.get_lang('Comment').'</th>';
}
$html .='</tr>';
$html .= '</tr>';
$form->addElement('label', get_lang('Answers') . '<br />'.Display::return_icon('fill_field.png'), $html);
$form->addElement('label', get_lang('Answers').'<br />'.Display::return_icon('fill_field.png'), $html);
/* Initialiation variable */
$defaults = array();
$correct = 0;
$correct = 0;
/* Mise en variable du nombre de reponse */
if (!empty($this->id)) {
@ -81,10 +83,10 @@ class GlobalMultipleAnswer extends Question
/* boucle pour sauvegarder les donn<EFBFBD>es dans le tableau defaults */
for ($i = 1; $i <= $nb_answers; ++$i) {
/* si la reponse est de type objet */
if (is_object($answer)) {
if (isset($answer) && is_object($answer)) {
$answer_id = $answer->getRealAnswerIdFromList($i);
$defaults['answer['.$i.']'] = $answer->answer[$answer_id];
$defaults['answer['.$i.']'] = $answer->answer[$answer_id];
$defaults['comment['.$i.']'] = $answer->comment[$answer_id];
$defaults['correct['.$i.']'] = $answer->correct[$answer_id];
@ -96,31 +98,56 @@ class GlobalMultipleAnswer extends Question
}
//------------- Fin
//------------- Debut si un des scores par reponse est egal <EFBFBD> 0 : la coche vaut 1 (coch<EFBFBD>)
if ($scoreA == 0)
if ($scoreA == 0) {
$defaults['pts'] = 1;
else
} else {
$defaults['pts'] = 0;
}
$renderer = & $form->defaultRenderer();
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct['.$i.']');
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'counter['.$i.']');
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'answer['.$i.']');
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment['.$i.']');
$renderer->setElementTemplate(
'<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>',
'correct['.$i.']'
);
$renderer->setElementTemplate(
'<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>',
'counter['.$i.']'
);
$renderer->setElementTemplate(
'<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>',
'answer['.$i.']'
);
$renderer->setElementTemplate(
'<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>',
'comment['.$i.']'
);
//$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'weighting['.$i.']');
$answer_number = $form->addElement('text', 'counter[' . $i . ']', null, 'value="' . $i . '"');
$answer_number = $form->addElement('text', 'counter['.$i.']', null, 'value="'.$i.'"');
$answer_number->freeze();
$form->addElement('checkbox', 'correct[' . $i . ']', null, null, 'class="checkbox"');
$boxes_names[] = 'correct[' . $i . ']';
$form->addElement('checkbox', 'correct['.$i.']', null, null, 'class="checkbox"');
$boxes_names[] = 'correct['.$i.']';
$form->addElement('html_editor', 'answer[' . $i . ']', null, 'style="vertical-align:middle"', array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100'));
$form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required');
$form->addElement(
'html_editor',
'answer['.$i.']',
null,
'style="vertical-align:middle"',
array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100')
);
$form->addRule('answer['.$i.']', get_lang('ThisFieldIsRequired'), 'required');
// show comment when feedback is enable
if ($obj_ex->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
$form->addElement('html_editor', 'comment[' . $i . ']', null, 'style="vertical-align:middle"', array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100'));
$form->addElement(
'html_editor',
'comment['.$i.']',
null,
'style="vertical-align:middle"',
array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100')
);
}
$form->addElement('html', '</tr>');
@ -151,11 +178,16 @@ class GlobalMultipleAnswer extends Question
if ($navigator_info['name'] == 'Internet Explorer' && $navigator_info['version'] == '6') {
$form->addElement('submit', 'lessAnswers', get_lang('LessAnswer'), 'class="minus"');
$form->addElement('submit', 'moreAnswers', get_lang('PlusAnswer'), 'class="plus"');
$form->addElement('submit', 'submitQuestion', $this->submitText, 'class="' . $this->submitClass . '"');
$form->addElement('submit', 'submitQuestion', $this->submitText, 'class="'.$this->submitClass.'"');
} else {
$form->addElement('style_submit_button', 'lessAnswers', get_lang('LessAnswer'), 'class="minus"');
$form->addElement('style_submit_button', 'moreAnswers', get_lang('PlusAnswer'), 'class="plus"');
$form->addElement('style_submit_button', 'submitQuestion', $this->submitText, 'class="' . $this->submitClass . '"');
$form->addElement(
'style_submit_button',
'submitQuestion',
$this->submitText,
'class="'.$this->submitClass.'"'
);
// setting the save button here and not in the question class.php
}
}
@ -182,10 +214,11 @@ class GlobalMultipleAnswer extends Question
* @param the formvalidator instance
* @param the answers number to display
*/
function processAnswersCreation($form) {
function processAnswersCreation($form)
{
$questionWeighting = $nbrGoodAnswers = 0;
$objAnswer = new Answer($this->id);
$nb_answers = $form->getSubmitValue('nb_answers');
$objAnswer = new Answer($this->id);
$nb_answers = $form->getSubmitValue('nb_answers');
// Score total
$answer_score = trim($form->getSubmitValue('weighting[1]'));
@ -193,7 +226,7 @@ class GlobalMultipleAnswer extends Question
// Reponses correctes
$nbr_corrects = 0;
for ($i = 1; $i <= $nb_answers; $i++) {
$goodAnswer = trim($form->getSubmitValue('correct[' . $i . ']'));
$goodAnswer = trim($form->getSubmitValue('correct['.$i.']'));
if ($goodAnswer) {
$nbr_corrects++;
}
@ -212,17 +245,18 @@ class GlobalMultipleAnswer extends Question
$test = $form->getSubmitValue('pts');
for ($i = 1; $i <= $nb_answers; $i++) {
$answer = trim($form->getSubmitValue('answer[' . $i . ']'));
$comment = trim($form->getSubmitValue('comment[' . $i . ']'));
$goodAnswer = trim($form->getSubmitValue('correct[' . $i . ']'));
$answer = trim($form->getSubmitValue('answer['.$i.']'));
$comment = trim($form->getSubmitValue('comment['.$i.']'));
$goodAnswer = trim($form->getSubmitValue('correct['.$i.']'));
if ($goodAnswer) {
$weighting = abs($answer_score);
} else {
if ($test == 1) {
$weighting = 0;
}else
} else {
$weighting = -abs($answer_score);
}
}
$objAnswer->createAnswer($answer, $goodAnswer, $comment, $weighting, $i);
@ -235,19 +269,21 @@ class GlobalMultipleAnswer extends Question
$this->save();
}
function return_header($feedback_type = null, $counter = null, $score = null, $show_media = false) {
function return_header($feedback_type = null, $counter = null, $score = null, $show_media = false)
{
$header = parent::return_header($feedback_type, $counter, $score, $show_media);
$header .= '<table class="'.$this->question_table_class .'">
$header .= '<table class="'.$this->question_table_class.'">
<tr>
<th>' . get_lang("Choice") . '</th>
<th>' . get_lang("ExpectedChoice") . '</th>
<th>' . get_lang("Answer") . '</th>';
<th>'.get_lang("Choice").'</th>
<th>'.get_lang("ExpectedChoice").'</th>
<th>'.get_lang("Answer").'</th>';
if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {
$header .= '<th>' . get_lang("Comment") . '</th>';
$header .= '<th>'.get_lang("Comment").'</th>';
} else {
$header .= '<th>&nbsp;</th>';
}
$header .= '</tr>';
return $header;
}
}

@ -6,19 +6,19 @@ class MediaQuestion extends Question
static $typePicture = 'media-question.png';
static $explanationLangVar = 'MediaQuestion';
function __construct()
public function __construct()
{
parent::question();
$this->type = MEDIA_QUESTION;
}
function processAnswersCreation($form)
public function processAnswersCreation($form)
{
$params = $form->getSubmitValues();
$this->saveMedia($params);
}
function saveMedia($params)
public function saveMedia($params)
{
$table_question = Database::get_course_table(TABLE_QUIZ_QUESTION);
$new_params = array(
@ -36,7 +36,7 @@ class MediaQuestion extends Question
}
}
function createAnswersForm ($form)
public function createAnswersForm ($form)
{
$form->addElement('button', 'submitQuestion', get_lang('Save'));
}

@ -135,25 +135,43 @@ class MultipleAnswer extends Question
$form->addElement('checkbox', 'correct['.$i.']', null, null, 'class="checkbox" style="margin-left: 0em;"');
$boxes_names[] = 'correct['.$i.']';
$form->addElement(
'html_editor',
'answer['.$i.']',
null,
'style="vertical-align:middle"',
array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100')
);
$form->addRule('answer['.$i.']', get_lang('ThisFieldIsRequired'), 'required');
// show comment when feedback is enable
if (!empty($obj_ex) && $obj_ex->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
if ($obj_ex->fastEdition) {
$form->addElement(
'textarea',
'answer['.$i.']',
null,
$this->textareaSettings
);
} else {
$form->addElement(
'html_editor',
'comment['.$i.']',
'answer['.$i.']',
null,
'style="vertical-align:middle"',
array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100')
);
}
$form->addRule('answer['.$i.']', get_lang('ThisFieldIsRequired'), 'required');
// show comment when feedback is enable
if (!empty($obj_ex) && $obj_ex->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
if ($obj_ex->fastEdition) {
$form->addElement(
'textarea',
'comment['.$i.']',
null,
$this->textareaSettings
);
} else {
$form->addElement(
'html_editor',
'comment['.$i.']',
null,
'style="vertical-align:middle"',
array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100')
);
}
}
$form->addElement('text', 'weighting['.$i.']', null, array('class' => "span1", 'value' => '0'));
$form->addElement('html', '</tr>');

@ -1,49 +1,47 @@
<?php
/* For licensing terms, see /license.txt */
/**
* File containing the MultipleAnswer class.
* @package chamilo.exercise
* @author Eric Marguin
* @version $Id: admin.php 10680 2007-01-11 21:26:23Z pcool $
*/
/**
* Code
* File containing the MultipleAnswer class.
* @package chamilo.exercise
* @author Eric Marguin
* @version $Id: admin.php 10680 2007-01-11 21:26:23Z pcool $
*/
/**
CLASS MultipleAnswer
CLASS MultipleAnswer
*
* This class allows to instantiate an object of type MULTIPLE_ANSWER (MULTIPLE CHOICE, MULTIPLE ANSWER),
* extending the class question
* This class allows to instantiate an object of type MULTIPLE_ANSWER (MULTIPLE CHOICE, MULTIPLE ANSWER),
* extending the class question
*
* @author Eric Marguin
* @package chamilo.exercise
* @author Eric Marguin
* @package chamilo.exercise
**/
class MultipleAnswerCombination extends Question
{
static $typePicture = 'mcmac.gif';
static $explanationLangVar = 'MultipleSelectCombination';
/**
* Constructor
*/
function MultipleAnswerCombination(){
parent::question();
$this -> type = MULTIPLE_ANSWER_COMBINATION;
$this -> isContent = $this-> getIsContent();
}
/**
* function which redifines Question::createAnswersForm
* @param the formvalidator instance
* @param the answers number to display
*/
function createAnswersForm ($form) {
$nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 2;
$nb_answers += (isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0));
$obj_ex = $this->exercise;
$html= '<table class="data_table">
static $typePicture = 'mcmac.gif';
static $explanationLangVar = 'MultipleSelectCombination';
/**
* Constructor
*/
public function MultipleAnswerCombination()
{
parent::question();
$this->type = MULTIPLE_ANSWER_COMBINATION;
$this->isContent = $this->getIsContent();
}
/**
* function which redefines Question::createAnswersForm
* @param FormValidator instance
*/
public function createAnswersForm($form)
{
$nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 2;
$nb_answers += (isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0));
$obj_ex = $this->exercise;
$html = '<table class="data_table">
<tr style="text-align: center;">
<th width="10px">
'.get_lang('Number').'
@ -54,171 +52,219 @@ class MultipleAnswerCombination extends Question
<th width="50%">
'.get_lang('Answer').'
</th>';
// show column comment when feedback is enable
if ($obj_ex->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM ) {
$html .='<th>'.get_lang('Comment').'</th>';
}
$html .= '</tr>';
$form -> addElement ('label', get_lang('Answers').'<br />'.Display::return_icon('fill_field.png'), $html);
$defaults = array();
$correct = 0;
if(!empty($this -> id)) {
$answer = new Answer($this->id);
$answer->read();
if(count($answer->nbrAnswers)>0 && !$form->isSubmitted()) {
$nb_answers = $answer->nbrAnswers;
}
}
$form -> addElement('hidden', 'nb_answers');
$boxes_names = array();
if ($nb_answers < 1) {
$nb_answers = 1;
Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
}
for($i = 1 ; $i <= $nb_answers ; ++$i) {
if(is_object($answer)) {
$answer_id = $answer->getRealAnswerIdFromList($i);
$defaults['answer['.$i.']'] = $answer->answer[$answer_id];
$defaults['comment['.$i.']'] = $answer->comment[$answer_id];
$defaults['weighting['.$i.']'] = Text::float_format($answer->weighting[$answer_id], 1);
$defaults['correct['.$i.']'] = $answer->correct[$answer_id];
} else {
$defaults['answer[1]'] = get_lang('DefaultMultipleAnswer2');
$defaults['comment[1]'] = get_lang('DefaultMultipleComment2');
$defaults['correct[1]'] = true;
$defaults['weighting[1]'] = 10;
$defaults['answer[2]'] = get_lang('DefaultMultipleAnswer1');
$defaults['comment[2]'] = get_lang('DefaultMultipleComment1');
$defaults['correct[2]'] = false;
}
$renderer = & $form->defaultRenderer();
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct['.$i.']');
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'counter['.$i.']');
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'answer['.$i.']');
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment['.$i.']');
$answer_number=$form->addElement('text', 'counter['.$i.']', null,'value="'.$i.'"');
$answer_number->freeze();
// show column comment when feedback is enable
if ($obj_ex->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
$html .= '<th>'.get_lang('Comment').'</th>';
}
$html .= '</tr>';
$form->addElement('label', get_lang('Answers').'<br />'.Display::return_icon('fill_field.png'), $html);
$defaults = array();
$correct = 0;
if (!empty($this->id)) {
$answer = new Answer($this->id);
$answer->read();
if (count($answer->nbrAnswers) > 0 && !$form->isSubmitted()) {
$nb_answers = $answer->nbrAnswers;
}
}
$form->addElement('checkbox', 'correct['.$i.']', null, null, 'class="checkbox" style="margin-left: 0em;"');
$boxes_names[] = 'correct['.$i.']';
$form->addElement('hidden', 'nb_answers');
$boxes_names = array();
$form->addElement('html_editor', 'answer['.$i.']',null, 'style="vertical-align:middle"', array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100'));
$form->addRule('answer['.$i.']', get_lang('ThisFieldIsRequired'), 'required');
if ($nb_answers < 1) {
$nb_answers = 1;
Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
}
if ($obj_ex->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
$form->addElement('html_editor', 'comment['.$i.']',null, 'style="vertical-align:middle"', array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100'));
}
//only 1 answer the all deal ...
//$form->addElement('text', 'weighting['.$i.']',null, 'style="vertical-align:middle;margin-left: 0em;" size="5" value="10"');
for ($i = 1; $i <= $nb_answers; ++$i) {
if (isset($answer) && is_object($answer)) {
$answer_id = $answer->getRealAnswerIdFromList($i);
$defaults['answer['.$i.']'] = $answer->answer[$answer_id];
$defaults['comment['.$i.']'] = $answer->comment[$answer_id];
$defaults['weighting['.$i.']'] = Text::float_format($answer->weighting[$answer_id], 1);
$defaults['correct['.$i.']'] = $answer->correct[$answer_id];
} else {
$defaults['answer[1]'] = get_lang('DefaultMultipleAnswer2');
$defaults['comment[1]'] = get_lang('DefaultMultipleComment2');
$defaults['correct[1]'] = true;
$defaults['weighting[1]'] = 10;
$defaults['answer[2]'] = get_lang('DefaultMultipleAnswer1');
$defaults['comment[2]'] = get_lang('DefaultMultipleComment1');
$defaults['correct[2]'] = false;
}
$renderer = & $form->defaultRenderer();
$renderer->setElementTemplate(
'<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>',
'correct['.$i.']'
);
$renderer->setElementTemplate(
'<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>',
'counter['.$i.']'
);
$renderer->setElementTemplate(
'<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>',
'answer['.$i.']'
);
$renderer->setElementTemplate(
'<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>',
'comment['.$i.']'
);
$answer_number = $form->addElement('text', 'counter['.$i.']', null, 'value="'.$i.'"');
$answer_number->freeze();
$form->addElement('checkbox', 'correct['.$i.']', null, null, 'class="checkbox" style="margin-left: 0em;"');
$boxes_names[] = 'correct['.$i.']';
if ($obj_ex->fastEdition) {
$form->addElement(
'textarea',
'answer['.$i.']',
null,
$this->textareaSettings
);
} else {
$form->addElement(
'html_editor',
'answer['.$i.']',
null,
'style="vertical-align:middle"',
array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100')
);
}
$form->addRule('answer['.$i.']', get_lang('ThisFieldIsRequired'), 'required');
if ($obj_ex->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
if ($obj_ex->fastEdition) {
$form->addElement(
'textarea',
'comment['.$i.']',
null,
$this->textareaSettings
);
} else {
$form->addElement(
'html_editor',
'comment['.$i.']',
null,
'style="vertical-align:middle"',
array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100')
);
}
}
//only 1 answer the all deal ...
//$form->addElement('text', 'weighting['.$i.']',null, 'style="vertical-align:middle;margin-left: 0em;" size="5" value="10"');
$form -> addElement ('html', '</tr>');
}
$form -> addElement ('html', '</table>');
$form -> addElement ('html', '<br />');
$form->addElement('html', '</tr>');
}
$form->addElement('html', '</table>');
$form->addElement('html', '<br />');
$form -> add_multiple_required_rule ($boxes_names , get_lang('ChooseAtLeastOneCheckbox') , 'multiple_required');
$form->add_multiple_required_rule($boxes_names, get_lang('ChooseAtLeastOneCheckbox'), 'multiple_required');
//only 1 answer the all deal ...
$form->addElement('text', 'weighting[1]', get_lang('Score'), array('class' => "span1", 'value' => '10'));
//only 1 answer the all deal ...
$form->addElement('text', 'weighting[1]', get_lang('Score'), array('class' => "span1", 'value' => '10'));
$navigator_info = api_get_navigator();
//ie6 fix
if ($obj_ex->edit_exercise_in_lp == true) {
if ($navigator_info['name']=='Internet Explorer' && $navigator_info['version']=='6') {
$navigator_info = api_get_navigator();
//ie6 fix
if ($obj_ex->edit_exercise_in_lp == true) {
if ($navigator_info['name'] == 'Internet Explorer' && $navigator_info['version'] == '6') {
$form->addElement('submit', 'lessAnswers', get_lang('LessAnswer'),'class="btn minus"');
$form->addElement('submit', 'moreAnswers', get_lang('PlusAnswer'),'class="btn plus"');
$form->addElement('submit', 'lessAnswers', get_lang('LessAnswer'), 'class="btn minus"');
$form->addElement('submit', 'moreAnswers', get_lang('PlusAnswer'), 'class="btn plus"');
$form->addElement('submit', 'submitQuestion', $this->submitText, 'class="'.$this->submitClass.'"');
} else {
} else {
$form->addElement('style_submit_button', 'lessAnswers', get_lang('LessAnswer'),'class="btn minus"');
$form->addElement('style_submit_button', 'moreAnswers', get_lang('PlusAnswer'),'class="btn plus"');
$form->addElement('style_submit_button', 'submitQuestion',$this->submitText, 'class="'.$this->submitClass.'"');
$form->addElement('style_submit_button', 'lessAnswers', get_lang('LessAnswer'), 'class="btn minus"');
$form->addElement('style_submit_button', 'moreAnswers', get_lang('PlusAnswer'), 'class="btn plus"');
$form->addElement(
'style_submit_button',
'submitQuestion',
$this->submitText,
'class="'.$this->submitClass.'"'
);
// setting the save button here and not in the question class.php
// setting the save button here and not in the question class.php
}
}
$renderer->setElementTemplate('{element}&nbsp;','lessAnswers');
$renderer->setElementTemplate('{element}&nbsp;','submitQuestion');
$renderer->setElementTemplate('{element}&nbsp;','moreAnswers');
$form -> addElement ('html', '</div></div>');
$defaults['correct'] = $correct;
if (!empty($this->id)) {
$form -> setDefaults($defaults);
} else {
if ($this -> isContent == 1) {
$form -> setDefaults($defaults);
}
}
$form->setConstants(array('nb_answers' => $nb_answers));
}
}
}
$renderer->setElementTemplate('{element}&nbsp;', 'lessAnswers');
$renderer->setElementTemplate('{element}&nbsp;', 'submitQuestion');
$renderer->setElementTemplate('{element}&nbsp;', 'moreAnswers');
$form->addElement('html', '</div></div>');
$defaults['correct'] = $correct;
if (!empty($this->id)) {
$form->setDefaults($defaults);
} else {
if ($this->isContent == 1) {
$form->setDefaults($defaults);
}
}
$form->setConstants(array('nb_answers' => $nb_answers));
}
/**
* abstract function which creates the form to create / edit the answers of the question
* @param the formvalidator instance
* @param the answers number to display
*/
function processAnswersCreation($form) {
/**
* abstract function which creates the form to create / edit the answers of the question
* @param the formvalidator instance
* @param the answers number to display
*/
function processAnswersCreation($form)
{
$questionWeighting = $nbrGoodAnswers = 0;
$questionWeighting = $nbrGoodAnswers = 0;
$objAnswer = new Answer($this->id);
$objAnswer = new Answer($this->id);
$nb_answers = $form -> getSubmitValue('nb_answers');
$nb_answers = $form->getSubmitValue('nb_answers');
for ($i = 1; $i <= $nb_answers; $i++) {
$answer = trim($form -> getSubmitValue('answer['.$i.']'));
$comment = trim($form -> getSubmitValue('comment['.$i.']'));
if ($i == 1)
$weighting = trim($form -> getSubmitValue('weighting['.$i.']'));
else {
$weighting = 0;
$answer = trim($form->getSubmitValue('answer['.$i.']'));
$comment = trim($form->getSubmitValue('comment['.$i.']'));
if ($i == 1) {
$weighting = trim($form->getSubmitValue('weighting['.$i.']'));
} else {
$weighting = 0;
}
$goodAnswer = trim($form->getSubmitValue('correct['.$i.']'));
if ($goodAnswer) {
$weighting = abs($weighting);
} else {
$weighting = abs($weighting);
// $weighting = -$weighting;
}
$goodAnswer = trim($form -> getSubmitValue('correct['.$i.']'));
if($goodAnswer){
$weighting = abs($weighting);
} else {
$weighting = abs($weighting);
// $weighting = -$weighting;
}
if ($weighting > 0) {
$questionWeighting += $weighting;
}
$objAnswer -> createAnswer($answer,$goodAnswer,$comment,$weighting,$i);
$objAnswer->createAnswer($answer, $goodAnswer, $comment, $weighting, $i);
}
// saves the answers into the data base
$objAnswer -> save();
// saves the answers into the data base
$objAnswer->save();
// sets the total weighting of the question
$this -> updateWeighting($questionWeighting);
$this -> save();
}
function return_header($feedback_type = null, $counter = null, $score = null, $show_media = false) {
$header = parent::return_header($feedback_type, $counter, $score, $show_media);
$header .= '<table class="'.$this->question_table_class .'">
$this->updateWeighting($questionWeighting);
$this->save();
}
function return_header($feedback_type = null, $counter = null, $score = null, $show_media = false)
{
$header = parent::return_header($feedback_type, $counter, $score, $show_media);
$header .= '<table class="'.$this->question_table_class.'">
<tr>
<th>'.get_lang("Choice").'</th>
<th>'. get_lang("ExpectedChoice").'</th>
<th>'. get_lang("Answer").'</i></th>';
if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {
$header .= '<th>'.get_lang("Comment").'</th>';
} else {
$header .= '<th>&nbsp;</th>';
}
<th>'.get_lang("ExpectedChoice").'</th>
<th>'.get_lang("Answer").'</i></th>';
if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {
$header .= '<th>'.get_lang("Comment").'</th>';
} else {
$header .= '<th>&nbsp;</th>';
}
$header .= '</tr>';
return $header;
}
}
}

@ -115,7 +115,7 @@ class MultipleAnswerTrueFalse extends Question
$answer_number = $form->addElement('text', 'counter['.$i.']', null, 'value="'.$i.'"');
$answer_number->freeze();
if (is_object($answer)) {
if (isset($answer) && is_object($answer)) {
$answer_id = $answer->getRealAnswerIdFromList($i);
@ -143,29 +143,47 @@ class MultipleAnswerTrueFalse extends Question
$defaults['comment['.$i.']'] = '';
$defaults['correct['.$i.']'] = '';
}
$boxes_names[] = 'correct['.$i.']';
$form->addElement(
'html_editor',
'answer['.$i.']',
null,
'style="vertical-align:middle"',
array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100')
);
$form->addRule('answer['.$i.']', get_lang('ThisFieldIsRequired'), 'required');
// show comment when feedback is enable
if ($obj_ex->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
if ($obj_ex->fastEdition) {
$form->addElement(
'textarea',
'answer['.$i.']',
null,
$this->textareaSettings
);
} else {
$form->addElement(
'html_editor',
'comment['.$i.']',
'answer['.$i.']',
null,
'style="vertical-align:middle"',
array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100')
);
}
$form->addRule('answer['.$i.']', get_lang('ThisFieldIsRequired'), 'required');
// show comment when feedback is enable
if ($obj_ex->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
if ($obj_ex->fastEdition) {
$form->addElement(
'textarea',
'comment['.$i.']',
null,
$this->textareaSettings
);
} else {
$form->addElement(
'html_editor',
'comment['.$i.']',
null,
'style="vertical-align:middle"',
array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100')
);
}
}
$form->addElement('html', '</tr>');
}

@ -45,6 +45,8 @@ abstract class Question
public $submitText;
public $setDefaultQuestionValues = false;
public $c_id = null;
// if fastEdition is on
public $textareaSettings = ' cols="50" rows="5" ';
public static $questionTypes = array(
UNIQUE_ANSWER => array('unique_answer.class.php', 'UniqueAnswer'),
@ -1622,15 +1624,15 @@ abstract class Question
/**
* abstract function which creates the form to create / edit the answers of the question
* @param the formvalidator instance
* @param FormValidator instance
*/
abstract function createAnswersForm($form);
abstract public function createAnswersForm($form);
/**
* abstract function which process the creation of answers
* @param the formvalidator instance
* @param FormValidator instance
*/
abstract function processAnswersCreation($form);
abstract public function processAnswersCreation($form);
/**
@ -1735,6 +1737,11 @@ abstract class Question
return $result;
}
/**
* @param int $question_id
* @param int $course_id
* @return array
*/
public static function readQuestionOption($question_id, $course_id)
{
$TBL_EXERCICE_QUESTION_OPTION = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);

@ -39,15 +39,13 @@ class UniqueAnswer extends Question
/**
* function which redifines Question::createAnswersForm
* @param the formvalidator instance
* @param the answers number to display
* @param FormValidator instance
*/
public function createAnswersForm($form)
{
// Getting the exercise list
/** @var Exercise $obj_ex */
$obj_ex = $this->exercise;
$editor_config = array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '125');
//this line define how many question by default appear when creating a choice question
@ -67,8 +65,6 @@ class UniqueAnswer extends Question
$feedback_title = '<th width="350px" >'.get_lang('Scenario').'</th>';
}
$html = '<table class="data_table">
<tr style="text-align: center;">
<th width="10px">
@ -101,8 +97,6 @@ class UniqueAnswer extends Question
$form->addElement('hidden', 'nb_answers');
$list = new LearnpathList(api_get_user_id());
$flat_list = $list->get_flat_list();
$select_lp_id = array();
@ -119,8 +113,6 @@ class UniqueAnswer extends Question
Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
}
for ($i = 1; $i <= $nb_answers; ++$i) {
$form->addElement('html', '<tr>');
if (isset($answer) && is_object($answer)) {
@ -199,22 +191,35 @@ class UniqueAnswer extends Question
$answer_number->freeze();
$form->addElement('radio', 'correct', null, null, $i, 'class="checkbox" style="margin-left: 0em;"');
$form->addElement('html_editor', 'answer['.$i.']', null, 'style="vertical-align:middle"', $editor_config);
if ($obj_ex->fastEdition) {
$form->addElement('textarea', 'answer['.$i.']', null, $this->textareaSettings);
} else {
$form->addElement('html_editor', 'answer['.$i.']', null, 'style="vertical-align:middle"', $editor_config);
}
$form->addRule('answer['.$i.']', get_lang('ThisFieldIsRequired'), 'required');
if ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_END) {
// feedback
$form->addElement(
'html_editor',
'comment['.$i.']',
null,
'style="vertical-align:middle"',
$editor_config
);
if ($obj_ex->fastEdition) {
// feedback
$form->addElement(
'textarea',
'comment['.$i.']',
null,
$this->textareaSettings
);
} else {
// feedback
$form->addElement(
'html_editor',
'comment['.$i.']',
null,
'style="vertical-align:middle"',
$editor_config
);
}
} elseif ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
// Feedback SELECT
@ -246,6 +251,7 @@ class UniqueAnswer extends Question
'style="vertical-align:middle"',
$editor_config
);
// Direct feedback
//Adding extra feedback fields

@ -1,15 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
/**
* File containing the UNIQUE_ANSWER class.
* @package chamilo.exercise
* @author Eric Marguin
*/
/**
* Code
*/
/**
*
* This class allows to instantiate an object of type UNIQUE_ANSWER_IMAGE
@ -29,7 +19,7 @@ class UniqueAnswerImage extends UniqueAnswer
/**
* Constructor
*/
function UniqueAnswerImage()
public function UniqueAnswerImage()
{
//this is highly important
parent::question();
@ -39,10 +29,10 @@ class UniqueAnswerImage extends UniqueAnswer
/**
* function which redifines Question::createAnswersForm
* @param the formvalidator instance
* @param the answers number to display
* @param FormValidator instance
*/
function createAnswersForm($form)
public function createAnswersForm($form)
{
// Getting the exercise list
$obj_ex = $this->exercise;
@ -183,20 +173,38 @@ class UniqueAnswerImage extends UniqueAnswer
$answer_number->freeze();
$form->addElement('radio', 'correct', null, null, $i, 'class="checkbox" style="margin-left: 0em;"');
$form->addElement('html_editor', 'answer['.$i.']', null, 'style="vertical-align:middle"', $editor_config);
/*
if ($obj_ex->fastEdition) {
$form->addElement('textarea', 'answer['.$i.']', null, $this->textareaSettings);
} else {
$form->addElement('html_editor', 'answer['.$i.']', null, 'style="vertical-align:middle"', $editor_config);
}*/
$form->addRule('answer['.$i.']', get_lang('ThisFieldIsRequired'), 'required');
if ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_END) {
// feedback
$form->addElement(
'html_editor',
'comment['.$i.']',
null,
'style="vertical-align:middle"',
$editor_config
);
if ($obj_ex->fastEdition) {
// feedback
$form->addElement(
'textarea',
'comment['.$i.']',
null,
$this->textareaSettings
);
} else {
// feedback
$form->addElement(
'html_editor',
'comment['.$i.']',
null,
'style="vertical-align:middle"',
$editor_config
);
}
} elseif ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
$form->addElement(
'html_editor',
'comment['.$i.']',
@ -282,10 +290,9 @@ class UniqueAnswerImage extends UniqueAnswer
/**
* abstract function which creates the form to create / edit the answers of the question
* @param the formvalidator instance
* @param the answers number to display
* @param FormValidator instance
*/
function processAnswersCreation($form)
public function processAnswersCreation($form)
{
$questionWeighting = $nbrGoodAnswers = 0;
@ -307,9 +314,6 @@ class UniqueAnswerImage extends UniqueAnswer
$lp = $scenario['lp'.$i];
$destination = $scenario['destination'.$i];
$url = trim($scenario['url'.$i]);
$goodAnswer = ($correct == $i) ? true : false;
if ($goodAnswer) {
@ -349,7 +353,14 @@ class UniqueAnswerImage extends UniqueAnswer
$this->save();
}
function return_header($feedback_type = null, $counter = null, $score = null, $show_media = false)
/**
* @param int $feedback_type
* @param int $counter
* @param int $score
* @param bool $show_media
* @return string
*/
public function return_header($feedback_type = null, $counter = null, $score = null, $show_media = false)
{
return parent::return_header($feedback_type, $counter, $score, $show_media);
}

@ -0,0 +1,34 @@
<?php
namespace ChamiloLMS\Component\Editor\Toolbar;
class UniqueAnswerImage 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