diff --git a/plugin/migrationmoodle/admin.php b/plugin/migrationmoodle/admin.php index 5be3f87c3f..0e5dff359e 100644 --- a/plugin/migrationmoodle/admin.php +++ b/plugin/migrationmoodle/admin.php @@ -7,6 +7,7 @@ use Chamilo\PluginBundle\MigrationMoodle\Task\CoursesTask; use Chamilo\PluginBundle\MigrationMoodle\Task\CourseUsersTask; use Chamilo\PluginBundle\MigrationMoodle\Task\CQuizTask; use Chamilo\PluginBundle\MigrationMoodle\Task\LearningPathsTask; +use Chamilo\PluginBundle\MigrationMoodle\Task\LessonAnswersMatchingTask; use Chamilo\PluginBundle\MigrationMoodle\Task\LessonAnswersMultipleAnswerTask; use Chamilo\PluginBundle\MigrationMoodle\Task\LessonAnswersMultipleChoiceTask; use Chamilo\PluginBundle\MigrationMoodle\Task\LessonAnswersTrueFalseTask; @@ -95,6 +96,11 @@ $menu = [ 'learnin_path_quiz_answers_multiple_answer', 'Answers for Multiple Answers questions', [] + ], + [ + 'learnin_path_quiz_answers_matching', + 'Answers for Matching questions', + [] ] ], ], @@ -178,6 +184,9 @@ if (!empty($action)) { case 'learnin_path_quiz_answers_multiple_answer': $task = new LessonAnswersMultipleAnswerTask(); break; + case 'learnin_path_quiz_answers_matching': + $task = new LessonAnswersMatchingTask(); + break; } if ($task) { diff --git a/plugin/migrationmoodle/src/Loader/LessonAnswersMatchingLoader.php b/plugin/migrationmoodle/src/Loader/LessonAnswersMatchingLoader.php new file mode 100644 index 0000000000..6eb267a89b --- /dev/null +++ b/plugin/migrationmoodle/src/Loader/LessonAnswersMatchingLoader.php @@ -0,0 +1,70 @@ +read($incomingData['quiz_id']); + + $question = \Question::read($incomingData['question_id'], $courseInfo); + + $answer = new \Answer($incomingData['question_id'], $incomingData['c_id'], $exercise); + $questionsAnswers = $answer->getAnswers(); + + foreach ($questionsAnswers as $questionsAnswer) { + $answer->createAnswer( + $questionsAnswer['answer'], + $questionsAnswer['correct'], + $questionsAnswer['comment'], + $questionsAnswer['ponderation'], + $questionsAnswer['position'], + $questionsAnswer['hotspot_coordinates'], + $questionsAnswer['hotspot_type'], + $questionsAnswer['destination'] + ); + } + + $optionPosition = $question->countAnswers() + 1; + + $answer->createAnswer($incomingData['feedback'], 0, '', 0, $optionPosition); + + $answerPosition = $optionPosition + 1; + + $answer->createAnswer( + $incomingData['answer'], + $optionPosition, + '', + $incomingData['score'], + $answerPosition + ); + + $answer->save(); + + $question->weighting += $incomingData['score']; + $question->save($exercise); + + return $question->id; + } +} diff --git a/plugin/migrationmoodle/src/Task/LessonAnswersMatchingTask.php b/plugin/migrationmoodle/src/Task/LessonAnswersMatchingTask.php new file mode 100644 index 0000000000..69aa70d7d3 --- /dev/null +++ b/plugin/migrationmoodle/src/Task/LessonAnswersMatchingTask.php @@ -0,0 +1,79 @@ + BaseExtractor::class, + 'query' => "SELECT la.id, la.pageid, la.answer, la.response, la.lessonid, l.course + FROM mdl_lesson_answers la + INNER JOIN mdl_lesson_pages lp ON (la.pageid = lp.id AND la.lessonid = lp.lessonid) + INNER JOIN mdl_lesson l ON (lp.lessonid = l.id AND la.lessonid = l.id) + WHERE lp.qtype = 5 + AND (la.response IS NOT NULL OR la.response != '') + ORDER BY lp.id", + ]; + } + + /** + * @return array + */ + public function getTransformConfiguration() + { + return [ + 'class' => BaseTransformer::class, + 'map' => [ + 'c_id' => [ + 'class' => LoadedCourseLookup::class, + 'properties' => ['course'], + ], + 'quiz_id' => [ + 'class' => LoadedLpQuizLookup::class, + 'properties' => ['pageid'], + ], + 'question_id' => [ + 'class' => LoadedLpQuizQuestionLookup::class, + 'properties' => ['pageid'], + ], + 'score' => [ + 'class' => LessonAnswersMatchingScoreLookup::class, + 'properties' => ['pageid', 'lessonid', 'course'], + ], + 'answer' => 'answer', + 'feedback' => 'response', + ], + ]; + } + + /** + * @return array + */ + public function getLoadConfiguration() + { + return [ + 'class' => LessonAnswersMatchingLoader::class, + ]; + } +} diff --git a/plugin/migrationmoodle/src/Transformer/Property/LessonAnswersMatchingScoreLookup.php b/plugin/migrationmoodle/src/Transformer/Property/LessonAnswersMatchingScoreLookup.php new file mode 100644 index 0000000000..666d123a34 --- /dev/null +++ b/plugin/migrationmoodle/src/Transformer/Property/LessonAnswersMatchingScoreLookup.php @@ -0,0 +1,55 @@ +getConnection(); + } catch (DBALException $e) { + throw new \Exception('Unable to start connection.', 0, $e); + } + + try { + $query = "SELECT la.score + FROM mdl_lesson_answers la + INNER JOIN mdl_lesson l ON (la.lessonid = l.id) + WHERE la.pageid = ? + AND la.lessonid = ? + AND l.course = ? + AND la.score > 0"; + + $score = $connection->fetchColumn($query, [$pageid, $lessonid, $course], 0); + } catch (DBALException $e) { + throw new \Exception("Unable to execute query \"{$this->query}\".", 0, $e); + } + + $connection->close(); + + if (empty($score)) { + return 1; + } + + return $score; + } +}