parent
e018e876b3
commit
f14828c83b
@ -0,0 +1,70 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\MigrationMoodle\Loader; |
||||
|
||||
use Chamilo\PluginBundle\MigrationMoodle\Interfaces\LoaderInterface; |
||||
|
||||
/** |
||||
* Class LessonAnswersMatchingLoader. |
||||
* |
||||
* Loader to create Matching question answers comming from Matching lesson page. |
||||
* |
||||
* @package Chamilo\PluginBundle\MigrationMoodle\Loader |
||||
*/ |
||||
class LessonAnswersMatchingLoader implements LoaderInterface |
||||
{ |
||||
/** |
||||
* Load the data and return the ID inserted. |
||||
* |
||||
* @param array $incomingData |
||||
* |
||||
* @return int |
||||
*/ |
||||
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); |
||||
|
||||
$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; |
||||
} |
||||
} |
||||
@ -0,0 +1,79 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\MigrationMoodle\Task; |
||||
|
||||
use Chamilo\PluginBundle\MigrationMoodle\Extractor\BaseExtractor; |
||||
use Chamilo\PluginBundle\MigrationMoodle\Loader\LessonAnswersMatchingLoader; |
||||
use Chamilo\PluginBundle\MigrationMoodle\Transformer\BaseTransformer; |
||||
use Chamilo\PluginBundle\MigrationMoodle\Transformer\Property\LessonAnswersMatchingScoreLookup; |
||||
use Chamilo\PluginBundle\MigrationMoodle\Transformer\Property\LoadedCourseLookup; |
||||
use Chamilo\PluginBundle\MigrationMoodle\Transformer\Property\LoadedLpQuizLookup; |
||||
use Chamilo\PluginBundle\MigrationMoodle\Transformer\Property\LoadedLpQuizQuestionLookup; |
||||
|
||||
/** |
||||
* Class LessonAnswersMatchingTask. |
||||
* |
||||
* Task to convert Matching answers from a lesson page in quiz answers for chamilo. |
||||
* |
||||
* @package Chamilo\PluginBundle\MigrationMoodle\Task |
||||
*/ |
||||
class LessonAnswersMatchingTask extends BaseTask |
||||
{ |
||||
/** |
||||
* @return array |
||||
*/ |
||||
public function getExtractConfiguration() |
||||
{ |
||||
return [ |
||||
'class' => 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, |
||||
]; |
||||
} |
||||
} |
||||
@ -0,0 +1,55 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\MigrationMoodle\Transformer\Property; |
||||
|
||||
use Chamilo\PluginBundle\MigrationMoodle\Interfaces\TransformPropertyInterface; |
||||
use Doctrine\DBAL\DBALException; |
||||
|
||||
/** |
||||
* Class LessonAnswersMatchingScoreLookup. |
||||
* |
||||
* @package Chamilo\PluginBundle\MigrationMoodle\Transformer\Property |
||||
*/ |
||||
class LessonAnswersMatchingScoreLookup implements TransformPropertyInterface |
||||
{ |
||||
/** |
||||
* @param array $data |
||||
* |
||||
* @throws \Exception |
||||
* |
||||
* @return mixed |
||||
*/ |
||||
public function transform(array $data) |
||||
{ |
||||
list($pageid, $lessonid, $course) = array_values($data); |
||||
|
||||
try { |
||||
$connection = \MigrationMoodlePlugin::create()->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; |
||||
} |
||||
} |
||||
Loading…
Reference in new issue