diff --git a/app/Resources/public/css/base.css b/app/Resources/public/css/base.css index 3846e34a53..8a1fd5fe92 100644 --- a/app/Resources/public/css/base.css +++ b/app/Resources/public/css/base.css @@ -4664,7 +4664,6 @@ div#chat-remote-video video { padding-right: 3%; } #page-install .install-steps-menu{ - background: #c9f4ff; border: none; } #page-install .install-steps-menu ol li{ @@ -6059,3 +6058,273 @@ footer{ #upload_form .fa-plus-square-o, #upload_form .fa-minus-square-o { cursor:pointer; } + +@-moz-keyframes wobblebar-loader { + 0% { + left: 4px; + } + 3% { + left: 204px; + } + 6% { + left: 4px; + } + 9% { + left: 204px; + } + 12% { + left: 4px; + } + 15% { + left: 204px; + } + 18% { + left: 32px; + } + 27% { + left: 32px; + } + 30% { + left: 204px; + } + 33% { + left: 4px; + } + 36% { + left: 204px; + } + 39% { + left: 4px; + } + 42% { + left: 204px; + } + 45% { + left: 4px; + } + 48% { + left: 204px; + } + 51% { + left: 152px; + } + 63% { + left: 152px; + } + 66% { + left: 4px; + } + 69% { + left: 204px; + } + 72% { + left: 4px; + } + 75% { + left: 204px; + } + 78% { + left: 4px; + } + 81% { + left: 204px; + } + 84% { + left: 72px; + } + 94% { + left: 72px; + } + 97% { + left: 204px; + } +} +@-webkit-keyframes wobblebar-loader { + 0% { + left: 4px; + } + 3% { + left: 204px; + } + 6% { + left: 4px; + } + 9% { + left: 204px; + } + 12% { + left: 4px; + } + 15% { + left: 204px; + } + 18% { + left: 32px; + } + 27% { + left: 32px; + } + 30% { + left: 204px; + } + 33% { + left: 4px; + } + 36% { + left: 204px; + } + 39% { + left: 4px; + } + 42% { + left: 204px; + } + 45% { + left: 4px; + } + 48% { + left: 204px; + } + 51% { + left: 152px; + } + 63% { + left: 152px; + } + 66% { + left: 4px; + } + 69% { + left: 204px; + } + 72% { + left: 4px; + } + 75% { + left: 204px; + } + 78% { + left: 4px; + } + 81% { + left: 204px; + } + 84% { + left: 72px; + } + 94% { + left: 72px; + } + 97% { + left: 204px; + } +} +@keyframes wobblebar-loader { + 0% { + left: 4px; + } + 3% { + left: 204px; + } + 6% { + left: 4px; + } + 9% { + left: 204px; + } + 12% { + left: 4px; + } + 15% { + left: 204px; + } + 18% { + left: 32px; + } + 27% { + left: 32px; + } + 30% { + left: 204px; + } + 33% { + left: 4px; + } + 36% { + left: 204px; + } + 39% { + left: 4px; + } + 42% { + left: 204px; + } + 45% { + left: 4px; + } + 48% { + left: 204px; + } + 51% { + left: 152px; + } + 63% { + left: 152px; + } + 66% { + left: 4px; + } + 69% { + left: 204px; + } + 72% { + left: 4px; + } + 75% { + left: 204px; + } + 78% { + left: 4px; + } + 81% { + left: 204px; + } + 84% { + left: 72px; + } + 94% { + left: 72px; + } + 97% { + left: 204px; + } +} +/* :not(:required) hides this rule from IE9 and below */ +.wobblebar-loader:not(:required) { + background: #2E6DA4; + -moz-border-radius: 10.66667px; + -webkit-border-radius: 10.66667px; + border-radius: 10.66667px; + display: inline-block; + overflow: hidden; + text-indent: -9999px; + width: 228px; + height: 21.33333px; + position: relative; +} +.wobblebar-loader:not(:required)::after { + -moz-animation: wobblebar-loader 15000ms infinite ease; + -webkit-animation: wobblebar-loader 15000ms infinite ease; + animation: wobblebar-loader 15000ms infinite ease; + background: white; + display: block; + -moz-border-radius: 7.11111px; + -webkit-border-radius: 7.11111px; + border-radius: 7.11111px; + content: ''; + position: absolute; + top: 3.55556px; + left: 4px; + width: 21.33333px; + height: 14.22222px; +} diff --git a/main/coursecopy/import_moodle.php b/main/coursecopy/import_moodle.php index 0f3aec57b0..3d3b196827 100644 --- a/main/coursecopy/import_moodle.php +++ b/main/coursecopy/import_moodle.php @@ -41,13 +41,19 @@ $form->addButtonImport(get_lang('Import')); if ($form->validate()) { $file = $_FILES['moodle_file']; $moodleImport = new MoodleImport(); - $moodleImport->readMoodleFile($file); + $responseImport = $moodleImport->readMoodleFile($file); + if ($responseImport) { + Display::addFlash(Display::return_message(get_lang('MoodleFileImportedSuccessfull'), 'success')); + } else { + Display::addFlash(Display::return_message(get_lang('ErrorImportingFile'), 'error')); + } + header('Location: ' . api_get_self() . '?' . api_get_cidreq()); } $templateName = get_lang('ImportFromMoodle'); $template = new Template($templateName); -$infoMsg = Display::return_message(get_lang('ImportFromMoodleInstructions')); +$infoMsg = Display::return_message(get_lang('ImportFromMoodleInstructions'), 'normal', false); $template->assign('info_msg', $infoMsg); $template->assign('form', $form->returnForm()); $content = $template->fetch('default/coursecopy/import_moodle.tpl'); diff --git a/main/exercise/answer.class.php b/main/exercise/answer.class.php index ed0c07d918..68d12604c8 100755 --- a/main/exercise/answer.class.php +++ b/main/exercise/answer.class.php @@ -265,8 +265,8 @@ class Answer $this->comment[$i] = $doubt_data->comment; $this->weighting[$i] = $doubt_data->ponderation; $this->position[$i] = $doubt_data->position; - $this->hotspot_coordinates[$i] = $object->hotspot_coordinates; - $this->hotspot_type[$i] = $object->hotspot_type; + $this->hotspot_coordinates[$i] = isset($object->hotspot_coordinates) ? $object->hotspot_coordinates : 0; + $this->hotspot_type[$i] = isset($object->hotspot_type) ? $object->hotspot_type : 0; $this->destination[$i] = $doubt_data->destination; $this->autoId[$i] = $doubt_data->id_auto; $this->iid[$i] = $doubt_data->iid; diff --git a/main/inc/lib/MoodleImport.class.php b/main/inc/lib/MoodleImport.class.php index 0bb9e8f523..6c6efdd22e 100644 --- a/main/inc/lib/MoodleImport.class.php +++ b/main/inc/lib/MoodleImport.class.php @@ -218,6 +218,7 @@ class MoodleImport } } } else { + removeDir($destinationDir); return false; } } else { @@ -521,11 +522,12 @@ class MoodleImport case 'match': return FILL_IN_BLANKS; break; + case 'match': case 'essay': return FREE_ANSWER; break; case 'truefalse': - return MULTIPLE_ANSWER_TRUE_FALSE; + return UNIQUE_ANSWER_NO_OPTION; break; } } @@ -566,7 +568,7 @@ class MoodleImport foreach ($questionList as $slot => $subQuestion) { $qtype = $subQuestion['qtype']; - $optionsValues[] = $this->processFillBlanks($objAnswer, $subQuestion, $subQuestion['plugin_qtype_'.$qtype.'_question'], $placeholder, $slot + 1); + $optionsValues[] = $this->processFillBlanks($objAnswer, $qtype, $subQuestion['plugin_qtype_'.$qtype.'_question'], $placeholder, $slot + 1); } $answerOptionsWeight = '::'; @@ -581,34 +583,77 @@ class MoodleImport $answerOptionsWeight = substr($answerOptionsWeight, 0, -1); $answerOptionsSize = substr($answerOptionsSize, 0, -1); - $suffleAnswers = isset($subQuestion[$qtype.'_values']['shuffleanswers']) ? $subQuestion[$qtype.'_values']['shuffleanswers'] : false; + $answerOptions = $answerOptionsWeight.':'.$answerOptionsSize.':0@'; + + $placeholder = $placeholder.PHP_EOL.$answerOptions; + + // This is a minor trick to clean the question description that in a multianswer is the main placeholder + $questionInstance->updateDescription(''); + // sets the total weighting of the question + $questionInstance->updateWeighting($questionWeighting); + $questionInstance->save(); + // saves the answers into the data base + $objAnswer->createAnswer($placeholder, 0, '', 0, 1); + $objAnswer->save(); + + return true; + case 'match': + $objAnswer = new Answer($questionInstance->id); + $placeholder = ''; + + $optionsValues = $this->processFillBlanks($objAnswer, 'match', $questionList, $placeholder, 0); - if ($suffleAnswers) { - $answerOptions = $answerOptionsWeight.':'.$answerOptionsSize.':0@'.$suffleAnswers; - } else { - $answerOptions = $answerOptionsWeight.':'.$answerOptionsSize.':0@'; + $answerOptionsWeight = '::'; + $answerOptionsSize = ''; + $questionWeighting = 0; + foreach ($optionsValues as $index => $value) { + $questionWeighting += $value['weight']; + $answerOptionsWeight .= $value['weight'].','; + $answerOptionsSize .= $value['size'].','; } - $placeholder = $placeholder.$answerOptions; + $answerOptionsWeight = substr($answerOptionsWeight, 0, -1); + $answerOptionsSize = substr($answerOptionsSize, 0, -1); + $answerOptions = $answerOptionsWeight.':'.$answerOptionsSize.':0@'; + + $placeholder = $placeholder.PHP_EOL.$answerOptions; + + // sets the total weighting of the question $questionInstance->updateWeighting($questionWeighting); - $questionInstance->updateDescription(''); $questionInstance->save(); + // saves the answers into the data base $objAnswer->createAnswer($placeholder, 0, '', 0, 1); $objAnswer->save(); + + return true; + break; case 'shortanswer': - case 'match': case 'ddmatch': - // Not Supported Yet + $questionWeighting = $currentQuestion['defaultmark']; + $questionInstance->updateWeighting($questionWeighting); + $questionInstance->updateDescription(get_lang('ThisQuestionIsNotSupportedYet')); + $questionInstance->save(); return false; break; case 'essay': $questionWeighting = $currentQuestion['defaultmark']; $questionInstance->updateWeighting($questionWeighting); $questionInstance->save(); + return true; break; case 'truefalse': - // Not Supported Yet + $objAnswer = new Answer($questionInstance->id); + $questionWeighting = 0; + foreach ($questionList as $slot => $answer) { + $this->processTrueFalse($objAnswer, $answer, $slot + 1, $questionWeighting); + } + + // saves the answers into the data base + $objAnswer->save(); + // sets the total weighting of the question + $questionInstance->updateWeighting($questionWeighting); + $questionInstance->save(); return false; break; default: @@ -650,19 +695,52 @@ class MoodleImport ); } + /** + * Process Chamilo True False + * + * @param object $objAnswer + * @param array $answerValues + * @param integer $position + * @param integer $questionWeighting + * @return integer db response + */ + public function processTrueFalse($objAnswer, $answerValues, $position, &$questionWeighting) + { + $correct = intval($answerValues['fraction']) ? intval($answerValues['fraction']) : 0; + $answer = $answerValues['answertext']; + $comment = $answerValues['feedback']; + $weighting = $answerValues['fraction']; + $weighting = abs($weighting); + if ($weighting > 0) { + $questionWeighting += $weighting; + } + $goodAnswer = $correct ? true : false; + + $objAnswer->createAnswer( + $answer, + $goodAnswer, + $comment, + $weighting, + $position, + null, + null, + '' + ); + } + /** * Process Chamilo FillBlanks * * @param object $objAnswer - * @param array $question + * @param array $questionType * @param array $answerValues * @param string $placeholder * @param integer $position * @return integer db response */ - public function processFillBlanks($objAnswer, $question, $answerValues, &$placeholder, $position) + public function processFillBlanks($objAnswer, $questionType, $answerValues, &$placeholder, $position) { - switch ($question['qtype']) { + switch ($questionType) { case 'multichoice': $optionsValues = []; @@ -704,6 +782,38 @@ class MoodleImport return $optionsValues; + break; + case 'match': + $answers = []; + // Here first we need to extract all the possible answers + foreach ($answerValues as $slot => $answer) { + $answers[$slot] = $answer['answertext']; + } + + // Now we set the order of the values matching the correct answer and set it to the first element + $optionsValues = []; + foreach ($answerValues as $slot => $answer) { + $correctAnswer = ''; + $othersAnswers = ''; + $correctAnswer .= $answer['answertext'].'|'; + + foreach ($answers as $other) { + if ($other !== $answer['answertext']) { + $othersAnswers .= $other.'|'; + } + } + + $optionsValues[$slot]['weight'] = 1; + $optionsValues[$slot]['size'] = '200'; + + $currentAnswers = $correctAnswer.$othersAnswers; + $currentAnswers = '['.substr($currentAnswers, 0, -1).'] '; + + $placeholder .= '

' . strip_tags($answer['questiontext']).' '.$currentAnswers . '

'; + } + + return $optionsValues; + break; default: return false; @@ -718,7 +828,8 @@ class MoodleImport * @param $array * @param $keys */ - public function traverseArray(&$array, $keys) { + public function traverseArray(&$array, $keys) + { foreach ($array as $key => &$value) { if (is_array($value)) { $this->traverseArray($value, $keys); diff --git a/main/template/default/coursecopy/import_moodle.tpl b/main/template/default/coursecopy/import_moodle.tpl index 07a5bc4770..b2908fe4f9 100644 --- a/main/template/default/coursecopy/import_moodle.tpl +++ b/main/template/default/coursecopy/import_moodle.tpl @@ -1,4 +1,15 @@ {{ info_msg }}
+
+ +

-{{ form }} \ No newline at end of file +{{ form }} + + \ No newline at end of file