|
|
|
@ -12,73 +12,82 @@ |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
CLASS FillBlanks |
|
|
|
|
* |
|
|
|
|
* This class allows to instantiate an object of type MULTIPLE_ANSWER (MULTIPLE CHOICE, MULTIPLE ANSWER), |
|
|
|
|
* This class allows to instantiate an object of type MULTIPLE_ANSWER |
|
|
|
|
* (MULTIPLE CHOICE, MULTIPLE ANSWER), |
|
|
|
|
* extending the class question |
|
|
|
|
* |
|
|
|
|
* @author Eric Marguin |
|
|
|
|
* @author Julio Montoya multiple fill in blank option added |
|
|
|
|
* @package chamilo.exercise |
|
|
|
|
**/ |
|
|
|
|
|
|
|
|
|
class FillBlanks extends Question |
|
|
|
|
{ |
|
|
|
|
static $typePicture = 'fill_in_blanks.gif'; |
|
|
|
|
static $explanationLangVar = 'FillBlanks'; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Constructor |
|
|
|
|
*/ |
|
|
|
|
function FillBlanks() |
|
|
|
|
{ |
|
|
|
|
parent::question(); |
|
|
|
|
$this -> type = FILL_IN_BLANKS; |
|
|
|
|
$this -> isContent = $this-> getIsContent(); |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* Constructor |
|
|
|
|
*/ |
|
|
|
|
public function FillBlanks() |
|
|
|
|
{ |
|
|
|
|
parent::question(); |
|
|
|
|
$this -> type = FILL_IN_BLANKS; |
|
|
|
|
$this -> isContent = $this-> getIsContent(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* function which redifines Question::createAnswersForm |
|
|
|
|
* @param the formvalidator instance |
|
|
|
|
*/ |
|
|
|
|
function createAnswersForm($form) |
|
|
|
|
{ |
|
|
|
|
$defaults = array(); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* function which redifines Question::createAnswersForm |
|
|
|
|
* @param the formvalidator instance |
|
|
|
|
*/ |
|
|
|
|
function createAnswersForm ($form) { |
|
|
|
|
$defaults = array(); |
|
|
|
|
if (!empty($this->id)) { |
|
|
|
|
$objAnswer = new answer($this->id); |
|
|
|
|
|
|
|
|
|
if (!empty($this->id)) { |
|
|
|
|
$objAnswer = new answer($this->id); |
|
|
|
|
// the question is encoded like this |
|
|
|
|
// [A] B [C] D [E] F::10,10,10@1 |
|
|
|
|
// number 1 before the "@" means that is a switchable fill in blank question |
|
|
|
|
// [A] B [C] D [E] F::10,10,10@ or [A] B [C] D [E] F::10,10,10 |
|
|
|
|
// means that is a normal fill blank question |
|
|
|
|
|
|
|
|
|
// the question is encoded like this |
|
|
|
|
// [A] B [C] D [E] F::10,10,10@1 |
|
|
|
|
// number 1 before the "@" means that is a switchable fill in blank question |
|
|
|
|
// [A] B [C] D [E] F::10,10,10@ or [A] B [C] D [E] F::10,10,10 |
|
|
|
|
// means that is a normal fill blank question |
|
|
|
|
$pre_array = explode('::', $objAnswer->selectAnswer(1)); |
|
|
|
|
|
|
|
|
|
$pre_array = explode('::', $objAnswer->selectAnswer(1)); |
|
|
|
|
//make sure we only take the last bit to find special marks |
|
|
|
|
$sz = count($pre_array); |
|
|
|
|
$is_set_switchable = explode('@', $pre_array[$sz-1]); |
|
|
|
|
|
|
|
|
|
//make sure we only take the last bit to find special marks |
|
|
|
|
$sz = count($pre_array); |
|
|
|
|
$is_set_switchable = explode('@', $pre_array[$sz-1]); |
|
|
|
|
if ($is_set_switchable[1]) { |
|
|
|
|
$defaults['multiple_answer'] = 1; |
|
|
|
|
} else { |
|
|
|
|
$defaults['multiple_answer'] = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($is_set_switchable[1]) { |
|
|
|
|
$defaults['multiple_answer'] = 1; |
|
|
|
|
} else { |
|
|
|
|
$defaults['multiple_answer'] = 0; |
|
|
|
|
} |
|
|
|
|
//Take the complete string except after the last '::' |
|
|
|
|
|
|
|
|
|
//Take the complete string except after the last '::' |
|
|
|
|
$defaults['answer'] = ''; |
|
|
|
|
for ($i=0; $i<($sz-1); $i++) { |
|
|
|
|
$defaults['answer'] .= $pre_array[$i]; |
|
|
|
|
} |
|
|
|
|
$a_weightings = explode(',', $is_set_switchable[0]); |
|
|
|
|
} else { |
|
|
|
|
$defaults['answer'] = get_lang('DefaultTextInBlanks'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$defaults['answer'] = ''; |
|
|
|
|
for ($i=0;$i<($sz-1);$i++) { |
|
|
|
|
$defaults['answer'] .= $pre_array[$i]; |
|
|
|
|
} |
|
|
|
|
$a_weightings = explode(',', $is_set_switchable[0]); |
|
|
|
|
} else { |
|
|
|
|
$defaults['answer'] = get_lang('DefaultTextInBlanks'); |
|
|
|
|
} |
|
|
|
|
$setValues = null; |
|
|
|
|
|
|
|
|
|
if (isset($a_weightings) && count($a_weightings) > 0) { |
|
|
|
|
foreach ($a_weightings as $i => $weighting) { |
|
|
|
|
$setValues .= 'document.getElementById("weighting['.$i.']").value = "'.$weighting.'";'; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// javascript |
|
|
|
|
echo '<script> |
|
|
|
|
function FCKeditor_OnComplete( editorInstance ) { |
|
|
|
|
|
|
|
|
|
function FCKeditor_OnComplete(editorInstance) { |
|
|
|
|
if (window.attachEvent) { |
|
|
|
|
editorInstance.EditorDocument.attachEvent("onkeyup", updateBlanks) ; |
|
|
|
|
} else { |
|
|
|
@ -113,35 +122,30 @@ class FillBlanks extends Question |
|
|
|
|
document.getElementById("blanks_weighting").innerHTML = fields + "</table></div></div>"; |
|
|
|
|
if (firstTime) { |
|
|
|
|
firstTime = false; |
|
|
|
|
'; |
|
|
|
|
|
|
|
|
|
if (count($a_weightings) > 0) { |
|
|
|
|
foreach($a_weightings as $i => $weighting) { |
|
|
|
|
echo 'document.getElementById("weighting['.$i.']").value = "'.$weighting.'";'; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
echo '} |
|
|
|
|
'.$setValues.' |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
window.onload = updateBlanks; |
|
|
|
|
</script>'; |
|
|
|
|
|
|
|
|
|
// answer |
|
|
|
|
$form -> addElement ('label', null, '<br /><br />'.get_lang('TypeTextBelow').', '.get_lang('And').' '.get_lang('UseTagForBlank')); |
|
|
|
|
$form -> addElement ('html_editor', 'answer', '<img src="../img/fill_field.png">','id="answer" cols="122" rows="6" onkeyup="javascript: updateBlanks(this);"', array('ToolbarSet' => 'TestQuestionDescription', 'Width' => '100%', 'Height' => '350')); |
|
|
|
|
$form->addElement('label', null, '<br /><br />'.get_lang('TypeTextBelow').', '.get_lang('And').' '.get_lang('UseTagForBlank')); |
|
|
|
|
$form->addElement('html_editor', 'answer', '<img src="../img/fill_field.png">','id="answer" cols="122" rows="6" onkeyup="javascript: updateBlanks(this);"', array('ToolbarSet' => 'TestQuestionDescription', 'Width' => '100%', 'Height' => '350')); |
|
|
|
|
|
|
|
|
|
$form -> addRule ('answer',get_lang('GiveText'),'required'); |
|
|
|
|
$form -> addRule ('answer',get_lang('DefineBlanks'),'regex','/\[.*\]/'); |
|
|
|
|
$form->addRule('answer', get_lang('GiveText'),'required'); |
|
|
|
|
$form->addRule('answer', get_lang('DefineBlanks'),'regex','/\[.*\]/'); |
|
|
|
|
|
|
|
|
|
//added multiple answers |
|
|
|
|
$form -> addElement ('checkbox','multiple_answer','', get_lang('FillInBlankSwitchable')); |
|
|
|
|
$form->addElement('checkbox', 'multiple_answer','', get_lang('FillInBlankSwitchable')); |
|
|
|
|
|
|
|
|
|
$form -> addElement('html','<div id="blanks_weighting"></div>'); |
|
|
|
|
$form->addElement('html', '<div id="blanks_weighting"></div>'); |
|
|
|
|
|
|
|
|
|
global $text, $class; |
|
|
|
|
// setting the save button here and not in the question class.php |
|
|
|
|
$form->addElement('style_submit_button','submitQuestion',$text, 'class="'.$class.'"'); |
|
|
|
|
$form->addElement('style_submit_button', 'submitQuestion', $text, 'class="'.$class.'"'); |
|
|
|
|
|
|
|
|
|
if (!empty($this -> id)) { |
|
|
|
|
if (!empty($this->id)) { |
|
|
|
|
$form -> setDefaults($defaults); |
|
|
|
|
} else { |
|
|
|
|
if ($this->isContent == 1) { |
|
|
|
@ -150,10 +154,9 @@ class FillBlanks extends Question |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* abstract function which creates the form to create / edit the answers of the question |
|
|
|
|
* @param the formvalidator instance |
|
|
|
|
* @param FormValidator $form |
|
|
|
|
*/ |
|
|
|
|
function processAnswersCreation($form) |
|
|
|
|
{ |
|
|
|
|