parent
a27e48a739
commit
a5503611ad
@ -0,0 +1,37 @@ |
|||||||
|
<?php |
||||||
|
/* For licensing terms, see /license.txt */ |
||||||
|
|
||||||
|
namespace Chamilo\PluginBundle\MigrationMoodle\Loader; |
||||||
|
|
||||||
|
use Chamilo\PluginBundle\MigrationMoodle\Interfaces\LoaderInterface; |
||||||
|
|
||||||
|
/** |
||||||
|
* Class QuestionGapselectLoader. |
||||||
|
* |
||||||
|
* @package Chamilo\PluginBundle\MigrationMoodle\Loader |
||||||
|
*/ |
||||||
|
class QuestionGapselectLoader implements LoaderInterface |
||||||
|
{ |
||||||
|
/** |
||||||
|
* @inheritDoc |
||||||
|
*/ |
||||||
|
public function load(array $incomingData) |
||||||
|
{ |
||||||
|
$courseInfo = api_get_course_info_by_id($incomingData['c_id']); |
||||||
|
|
||||||
|
$exercise = new \Exercise($incomingData['c_id']); |
||||||
|
$exercise->read($incomingData['quiz_id']); |
||||||
|
|
||||||
|
$question = \Question::read($incomingData['question_id'], $courseInfo); |
||||||
|
$question->setTitle(get_lang('FillBlanks')); |
||||||
|
$question->weighting = $incomingData['score']; |
||||||
|
|
||||||
|
$answer = new \Answer($incomingData['question_id'], $incomingData['c_id'], $exercise); |
||||||
|
$answer->createAnswer($incomingData['answer'], 0, $incomingData['comment'], 0, 1); |
||||||
|
$answer->save(); |
||||||
|
|
||||||
|
$question->save($exercise); |
||||||
|
|
||||||
|
return $question->id; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,89 @@ |
|||||||
|
<?php |
||||||
|
/* For licensing terms, see /license.txt */ |
||||||
|
|
||||||
|
namespace Chamilo\PluginBundle\MigrationMoodle\Task; |
||||||
|
|
||||||
|
use Chamilo\PluginBundle\MigrationMoodle\Extractor\LoadedCoursesFilterExtractor; |
||||||
|
use Chamilo\PluginBundle\MigrationMoodle\Loader\QuestionGapselectLoader; |
||||||
|
use Chamilo\PluginBundle\MigrationMoodle\Transformer\BaseTransformer; |
||||||
|
use Chamilo\PluginBundle\MigrationMoodle\Transformer\Property\LoadedCourseLookup; |
||||||
|
use Chamilo\PluginBundle\MigrationMoodle\Transformer\Property\LoadedQuestionLookup; |
||||||
|
use Chamilo\PluginBundle\MigrationMoodle\Transformer\Property\LoadedQuizLookup; |
||||||
|
use Chamilo\PluginBundle\MigrationMoodle\Transformer\Property\QuestionGapselectAnswer; |
||||||
|
|
||||||
|
/** |
||||||
|
* Class QuestionGapselectTask. |
||||||
|
* |
||||||
|
* @package Chamilo\PluginBundle\MigrationMoodle\Task |
||||||
|
*/ |
||||||
|
class QuestionGapselectTask extends BaseTask |
||||||
|
{ |
||||||
|
/** |
||||||
|
* @inheritDoc |
||||||
|
*/ |
||||||
|
public function getExtractConfiguration() |
||||||
|
{ |
||||||
|
return [ |
||||||
|
'class' => LoadedCoursesFilterExtractor::class, |
||||||
|
'query' => "SELECT |
||||||
|
qa.id, |
||||||
|
qa.question, |
||||||
|
GROUP_CONCAT( |
||||||
|
CONCAT(qa.feedback, '==>>', qa.answer) ORDER BY qa.id ASC SEPARATOR '@||@' |
||||||
|
) answers, |
||||||
|
qq.questiontext, |
||||||
|
qs.maxmark, |
||||||
|
qg.correctfeedback, |
||||||
|
q.id quiz_id, |
||||||
|
q.course |
||||||
|
FROM mdl_question_answers qa |
||||||
|
INNER JOIN mdl_question qq ON qa.question = qq.id |
||||||
|
INNER JOIN mdl_question_gapselect qg ON qq.id = qg.questionid |
||||||
|
INNER JOIN mdl_quiz_slots qs ON qq.id = qs.questionid |
||||||
|
INNER JOIN mdl_quiz q ON qs.quizid = q.id |
||||||
|
WHERE qq.qtype = 'gapselect' |
||||||
|
GROUP BY q.id, qq.id |
||||||
|
ORDER BY q.id, qq.id" |
||||||
|
]; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @inheritDoc |
||||||
|
*/ |
||||||
|
public function getTransformConfiguration() |
||||||
|
{ |
||||||
|
return [ |
||||||
|
'class' => BaseTransformer::class, |
||||||
|
'map' => [ |
||||||
|
'c_id' => [ |
||||||
|
'class' => LoadedCourseLookup::class, |
||||||
|
'properties' => ['course'], |
||||||
|
], |
||||||
|
'quiz_id' => [ |
||||||
|
'class' => LoadedQuizLookup::class, |
||||||
|
'properties' => ['quiz_id'], |
||||||
|
], |
||||||
|
'question_id' => [ |
||||||
|
'class' => LoadedQuestionLookup::class, |
||||||
|
'properties' => ['question'], |
||||||
|
], |
||||||
|
'answer' => [ |
||||||
|
'class' => QuestionGapselectAnswer::class, |
||||||
|
'properties' => ['answers', 'questiontext', 'maxmark'], |
||||||
|
], |
||||||
|
'score' => 'maxmark', |
||||||
|
'comment' => 'correctfeedback', |
||||||
|
], |
||||||
|
]; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @inheritDoc |
||||||
|
*/ |
||||||
|
public function getLoadConfiguration() |
||||||
|
{ |
||||||
|
return [ |
||||||
|
'class' => QuestionGapselectLoader::class, |
||||||
|
]; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,77 @@ |
|||||||
|
<?php |
||||||
|
/* For licensing terms, see /license.txt */ |
||||||
|
|
||||||
|
namespace Chamilo\PluginBundle\MigrationMoodle\Transformer\Property; |
||||||
|
|
||||||
|
use Chamilo\PluginBundle\MigrationMoodle\Interfaces\TransformPropertyInterface; |
||||||
|
|
||||||
|
/** |
||||||
|
* Class QuestionGapselectAnswer. |
||||||
|
* |
||||||
|
* @package Chamilo\PluginBundle\MigrationMoodle\Transformer\Property |
||||||
|
*/ |
||||||
|
class QuestionGapselectAnswer implements TransformPropertyInterface |
||||||
|
{ |
||||||
|
/** |
||||||
|
* @inheritDoc |
||||||
|
*/ |
||||||
|
public function transform(array $data) |
||||||
|
{ |
||||||
|
list($answers, $questionText, $score) = array_values($data); |
||||||
|
|
||||||
|
$groupsAndOptions = explode('@||@', $answers); |
||||||
|
|
||||||
|
$groups = []; |
||||||
|
$positionsByGroup = []; |
||||||
|
|
||||||
|
foreach ($groupsAndOptions as $zeroPosition => $groupAndOption) { |
||||||
|
$position = $zeroPosition + 1; |
||||||
|
|
||||||
|
list($group, $option) = explode('==>>', $groupAndOption); |
||||||
|
|
||||||
|
$positionsByGroup[$position] = $group; |
||||||
|
$groups[$group][$position] = $option; |
||||||
|
} |
||||||
|
|
||||||
|
$blanks = []; |
||||||
|
|
||||||
|
foreach ($positionsByGroup as $option => $group) { |
||||||
|
if ($option === 1) { |
||||||
|
$blanks[] = '['.implode($groups[$group], '|').']'; |
||||||
|
|
||||||
|
continue; |
||||||
|
} |
||||||
|
|
||||||
|
$baz = $groups[$group]; |
||||||
|
|
||||||
|
unset($baz[$option]); |
||||||
|
|
||||||
|
$baz = [$groups[$group][$option]] + $baz; |
||||||
|
|
||||||
|
$blanks[] = '['.implode($baz, '|').']'; |
||||||
|
} |
||||||
|
|
||||||
|
$countBlanks = 0; |
||||||
|
|
||||||
|
foreach ($blanks as $zeroPosition => $blank) { |
||||||
|
$countBlank = 0; |
||||||
|
$position = $zeroPosition + 1; |
||||||
|
$questionText = str_replace("[[$position]]", $blank, $questionText, $countBlank); |
||||||
|
|
||||||
|
$countBlanks += $countBlank; |
||||||
|
} |
||||||
|
|
||||||
|
$individualScore = $score / $countBlanks; |
||||||
|
$scores = []; |
||||||
|
|
||||||
|
for ($i = 0; $i < $countBlanks - 1; $i++) { |
||||||
|
$scores[] = $individualScore; |
||||||
|
} |
||||||
|
|
||||||
|
$scores[] = $score - array_sum($scores); |
||||||
|
|
||||||
|
$inputs = str_repeat('300,', $countBlanks - 1).'300'; |
||||||
|
|
||||||
|
return "$questionText::".implode(',', $scores).":$inputs:0@"; |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue