parent
3d87eff7e1
commit
4bfbf72aa9
@ -0,0 +1,27 @@ |
|||||||
|
<?php |
||||||
|
/* For licensing terms, see /license.txt */ |
||||||
|
|
||||||
|
namespace Chamilo\PluginBundle\MigrationMoodle\Loader; |
||||||
|
|
||||||
|
use Chamilo\PluginBundle\MigrationMoodle\Interfaces\LoaderInterface; |
||||||
|
|
||||||
|
/** |
||||||
|
* Class SortSectionModuleLoader. |
||||||
|
* |
||||||
|
* @package Chamilo\PluginBundle\MigrationMoodle\Loader |
||||||
|
*/ |
||||||
|
class SortSectionModuleLoader implements LoaderInterface |
||||||
|
{ |
||||||
|
/** |
||||||
|
* @inheritDoc |
||||||
|
*/ |
||||||
|
public function load(array $incomingData) |
||||||
|
{ |
||||||
|
\learnpath::sortItemByOrderList( |
||||||
|
$incomingData['order_list'], |
||||||
|
$incomingData['c_id'] |
||||||
|
); |
||||||
|
|
||||||
|
return $incomingData['lp_id']; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,43 @@ |
|||||||
|
<?php |
||||||
|
/* For licensing terms, see /license.txt */ |
||||||
|
|
||||||
|
namespace Chamilo\PluginBundle\MigrationMoodle\Loader; |
||||||
|
|
||||||
|
use Chamilo\PluginBundle\MigrationMoodle\Interfaces\LoaderInterface; |
||||||
|
|
||||||
|
/** |
||||||
|
* Class UrlLoader. |
||||||
|
* |
||||||
|
* The Link created is added in a learning path (from a Moodle course section). |
||||||
|
* |
||||||
|
* @package Chamilo\PluginBundle\MigrationMoodle\Loader |
||||||
|
*/ |
||||||
|
class UrlLoader implements LoaderInterface |
||||||
|
{ |
||||||
|
/** |
||||||
|
* @inheritDoc |
||||||
|
*/ |
||||||
|
public function load(array $incomingData) |
||||||
|
{ |
||||||
|
$params = [ |
||||||
|
'c_id' => $incomingData['c_id'], |
||||||
|
'url' => $incomingData['url'], |
||||||
|
'title' => $incomingData['title'], |
||||||
|
'description' => null, |
||||||
|
'category_id' => null, |
||||||
|
'on_homepage' => '0', |
||||||
|
'target' => '_self', |
||||||
|
'session_id' => 0, |
||||||
|
]; |
||||||
|
|
||||||
|
$link = new \Link(); |
||||||
|
$linkId = $link->save($params); |
||||||
|
|
||||||
|
\Database::getManager() |
||||||
|
->createQuery('UPDATE ChamiloCourseBundle:CLpItem i SET i.path = :path WHERE i.iid = :id') |
||||||
|
->setParameters(['path' => $linkId, 'id' => $incomingData['item_id']]) |
||||||
|
->execute(); |
||||||
|
|
||||||
|
return $linkId; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,78 @@ |
|||||||
|
<?php |
||||||
|
/* For licensing terms, see /license.txt */ |
||||||
|
|
||||||
|
namespace Chamilo\PluginBundle\MigrationMoodle\Task; |
||||||
|
|
||||||
|
use Chamilo\PluginBundle\MigrationMoodle\Extractor\CourseExtractor; |
||||||
|
use Chamilo\PluginBundle\MigrationMoodle\Loader\SortSectionModuleLoader; |
||||||
|
use Chamilo\PluginBundle\MigrationMoodle\Transformer\BaseTransformer; |
||||||
|
use Chamilo\PluginBundle\MigrationMoodle\Transformer\Property\LoadedCourseLookup; |
||||||
|
use Chamilo\PluginBundle\MigrationMoodle\Transformer\Property\LoadedLpLookup; |
||||||
|
use Chamilo\PluginBundle\MigrationMoodle\Transformer\Property\SectionSequenceLookup; |
||||||
|
|
||||||
|
/** |
||||||
|
* Class SortSectionModulesTask. |
||||||
|
* |
||||||
|
* Task to fix the display order for learning path items. |
||||||
|
* |
||||||
|
* @package Chamilo\PluginBundle\MigrationMoodle\Task |
||||||
|
*/ |
||||||
|
class SortSectionModulesTask extends BaseTask |
||||||
|
{ |
||||||
|
/** |
||||||
|
* @inheritDoc |
||||||
|
*/ |
||||||
|
public function getExtractConfiguration() |
||||||
|
{ |
||||||
|
return [ |
||||||
|
'class' => CourseExtractor::class, |
||||||
|
'query' => "SELECT cm.id, cs.course, cm.section, cs.sequence |
||||||
|
FROM mdl_course_modules cm |
||||||
|
INNER JOIN mdl_modules m ON cm.module = m.id |
||||||
|
INNER JOIN mdl_course_sections cs ON (cm.course = cs.course AND cm.section = cs.id ) |
||||||
|
WHERE cs.course NOT IN ( |
||||||
|
SELECT sco.course |
||||||
|
FROM mdl_scorm sco |
||||||
|
INNER JOIN mdl_course_modules cm ON (sco.course = cm.course AND cm.instance = sco.id) |
||||||
|
INNER JOIN mdl_modules m ON cm.module = m.id |
||||||
|
INNER JOIN mdl_course_sections cs ON (cm.course = cs.course AND cm.section = cs.id ) |
||||||
|
WHERE m.name = 'scorm' |
||||||
|
) |
||||||
|
ORDER BY cs.course, cs.section, FIND_IN_SET(cm.id, cs.sequence)", |
||||||
|
]; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @inheritDoc |
||||||
|
*/ |
||||||
|
public function getTransformConfiguration() |
||||||
|
{ |
||||||
|
return [ |
||||||
|
'class' => BaseTransformer::class, |
||||||
|
'map' => [ |
||||||
|
'c_id' => [ |
||||||
|
'class' => LoadedCourseLookup::class, |
||||||
|
'properties' => ['course'], |
||||||
|
], |
||||||
|
'lp_id' => [ |
||||||
|
'class' => LoadedLpLookup::class, |
||||||
|
'properties' => ['section'], |
||||||
|
], |
||||||
|
'order_list' => [ |
||||||
|
'class' => SectionSequenceLookup::class, |
||||||
|
'properties' => ['sequence'], |
||||||
|
], |
||||||
|
], |
||||||
|
]; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @inheritDoc |
||||||
|
*/ |
||||||
|
public function getLoadConfiguration() |
||||||
|
{ |
||||||
|
return [ |
||||||
|
'class' => SortSectionModuleLoader::class, |
||||||
|
]; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,79 @@ |
|||||||
|
<?php |
||||||
|
/* For licensing terms, see /license.txt */ |
||||||
|
|
||||||
|
namespace Chamilo\PluginBundle\MigrationMoodle\Task; |
||||||
|
|
||||||
|
use Chamilo\PluginBundle\MigrationMoodle\Extractor\CourseExtractor; |
||||||
|
use Chamilo\PluginBundle\MigrationMoodle\Loader\UrlLoader; |
||||||
|
use Chamilo\PluginBundle\MigrationMoodle\Transformer\BaseTransformer; |
||||||
|
use Chamilo\PluginBundle\MigrationMoodle\Transformer\Property\LoadedCourseLookup; |
||||||
|
use Chamilo\PluginBundle\MigrationMoodle\Transformer\Property\LoadedCourseModulesUrlLookup; |
||||||
|
use Chamilo\PluginBundle\MigrationMoodle\Transformer\Property\LoadedLpLookup; |
||||||
|
|
||||||
|
/** |
||||||
|
* Class UrlsTask. |
||||||
|
* |
||||||
|
* @package Chamilo\PluginBundle\MigrationMoodle\Task |
||||||
|
*/ |
||||||
|
class UrlsTask extends BaseTask |
||||||
|
{ |
||||||
|
/** |
||||||
|
* @inheritDoc |
||||||
|
*/ |
||||||
|
public function getExtractConfiguration() |
||||||
|
{ |
||||||
|
return [ |
||||||
|
'class' => CourseExtractor::class, |
||||||
|
'query' => "SELECT u.id, u.course, u.name, u.externalurl, cm.section, cm.id cm_id |
||||||
|
FROM mdl_url u |
||||||
|
INNER JOIN mdl_course_modules cm ON (u.course = cm.course AND cm.instance = u.id) |
||||||
|
INNER JOIN mdl_modules m ON cm.module = m.id |
||||||
|
INNER JOIN mdl_course_sections cs ON (cm.course = cs.course AND cm.section = cs.id ) |
||||||
|
WHERE m.name = 'url' |
||||||
|
AND u.course NOT IN ( |
||||||
|
SELECT sco.course |
||||||
|
FROM mdl_scorm sco |
||||||
|
INNER JOIN mdl_course_modules cm ON (sco.course = cm.course AND cm.instance = sco.id) |
||||||
|
INNER JOIN mdl_modules m ON cm.module = m.id |
||||||
|
INNER JOIN mdl_course_sections cs ON (cm.course = cs.course AND cm.section = cs.id ) |
||||||
|
WHERE m.name = 'scorm' |
||||||
|
)", |
||||||
|
]; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @inheritDoc |
||||||
|
*/ |
||||||
|
public function getTransformConfiguration() |
||||||
|
{ |
||||||
|
return [ |
||||||
|
'class' => BaseTransformer::class, |
||||||
|
'map' => [ |
||||||
|
'c_id' => [ |
||||||
|
'class' => LoadedCourseLookup::class, |
||||||
|
'properties' => ['course'], |
||||||
|
], |
||||||
|
'lp_id' => [ |
||||||
|
'class' => LoadedLpLookup::class, |
||||||
|
'properties' => ['section'], |
||||||
|
], |
||||||
|
'item_id' => [ |
||||||
|
'class' => LoadedCourseModulesUrlLookup::class, |
||||||
|
'properties' => ['cm_id'], |
||||||
|
], |
||||||
|
'title' => 'name', |
||||||
|
'url' => 'externalurl', |
||||||
|
], |
||||||
|
]; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @inheritDoc |
||||||
|
*/ |
||||||
|
public function getLoadConfiguration() |
||||||
|
{ |
||||||
|
return [ |
||||||
|
'class' => UrlLoader::class, |
||||||
|
]; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,22 @@ |
|||||||
|
<?php |
||||||
|
/* For licensing terms, see /license.txt */ |
||||||
|
|
||||||
|
namespace Chamilo\PluginBundle\MigrationMoodle\Transformer\Property; |
||||||
|
|
||||||
|
use Chamilo\PluginBundle\MigrationMoodle\Task\CourseModulesUrlTask; |
||||||
|
|
||||||
|
/** |
||||||
|
* Class LoadedCourseModulesUrlLookup. |
||||||
|
* |
||||||
|
* @package Chamilo\PluginBundle\MigrationMoodle\Transformer\Property |
||||||
|
*/ |
||||||
|
class LoadedCourseModulesUrlLookup extends LoadedKeyLookup |
||||||
|
{ |
||||||
|
/** |
||||||
|
* LoadedCourseModulesUrlLookup constructor. |
||||||
|
*/ |
||||||
|
public function __construct() |
||||||
|
{ |
||||||
|
$this->calledClass = CourseModulesUrlTask::class; |
||||||
|
} |
||||||
|
} |
||||||
@ -1,44 +0,0 @@ |
|||||||
<?php |
|
||||||
/* For licensing terms, see /license.txt */ |
|
||||||
|
|
||||||
namespace Chamilo\PluginBundle\MigrationMoodle\Transformer\Property; |
|
||||||
|
|
||||||
use Chamilo\PluginBundle\MigrationMoodle\Task\CourseModulesLessonTask; |
|
||||||
|
|
||||||
/** |
|
||||||
* Class LoadedLpDirLookup. |
|
||||||
* |
|
||||||
* @package Chamilo\PluginBundle\MigrationMoodle\Transformer\Property |
|
||||||
*/ |
|
||||||
class LoadedLpDirLookup extends LoadedLpLookup |
|
||||||
{ |
|
||||||
/** |
|
||||||
* LoadedLpDirLookup constructor. |
|
||||||
*/ |
|
||||||
public function __construct() |
|
||||||
{ |
|
||||||
$this->calledClass = CourseModulesLessonTask::class; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* @param array $data |
|
||||||
* |
|
||||||
* @return mixed |
|
||||||
* @throws \Exception |
|
||||||
*/ |
|
||||||
public function transform(array $data) |
|
||||||
{ |
|
||||||
list($cmId, $sequenceStr) = array_values($data); |
|
||||||
|
|
||||||
$sequence = explode(',', $sequenceStr); |
|
||||||
$index = array_search($cmId, $sequence); |
|
||||||
|
|
||||||
if (empty($index)) { |
|
||||||
return 0; |
|
||||||
} |
|
||||||
|
|
||||||
$previous = $sequence[$index - 1]; |
|
||||||
|
|
||||||
return parent::transform([$previous]); |
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,67 +0,0 @@ |
|||||||
<?php |
|
||||||
/* For licensing terms, see /license.txt */ |
|
||||||
|
|
||||||
namespace Chamilo\PluginBundle\MigrationMoodle\Transformer\Property; |
|
||||||
|
|
||||||
use Chamilo\PluginBundle\MigrationMoodle\Task\CourseModulesLessonTask; |
|
||||||
use Doctrine\DBAL\DBALException; |
|
||||||
use Exception; |
|
||||||
use MigrationMoodlePlugin; |
|
||||||
|
|
||||||
/** |
|
||||||
* Class LoadedLpItemInSequenceLookup. |
|
||||||
* |
|
||||||
* Transform a Moodle course module in a Chamilo learning path item or section. |
|
||||||
* |
|
||||||
* @package Chamilo\PluginBundle\MigrationMoodle\Transformer\Property |
|
||||||
*/ |
|
||||||
class LoadedLpItemInSequenceLookup extends LoadedKeyLookup |
|
||||||
{ |
|
||||||
/** |
|
||||||
* @param array $data |
|
||||||
* |
|
||||||
* @throws Exception |
|
||||||
* |
|
||||||
* @return int |
|
||||||
*/ |
|
||||||
public function transform(array $data) |
|
||||||
{ |
|
||||||
$sequence = explode(',', $data['sequence']); |
|
||||||
|
|
||||||
$index = array_search($data['id'], $sequence); |
|
||||||
|
|
||||||
if (false === $index || !isset($sequence[$index - 1])) { |
|
||||||
return 0; |
|
||||||
} |
|
||||||
|
|
||||||
$mPreviousId = $sequence[$index - 1]; |
|
||||||
|
|
||||||
try { |
|
||||||
$connection = MigrationMoodlePlugin::create()->getConnection(); |
|
||||||
} catch (DBALException $e) { |
|
||||||
throw new Exception('Unable to start connection.', 0, $e); |
|
||||||
} |
|
||||||
|
|
||||||
try { |
|
||||||
$query = "SELECT m.name |
|
||||||
FROM mdl_course_modules cm |
|
||||||
INNER JOIN mdl_modules m ON cm.module = m.id |
|
||||||
WHERE cm.id = ?"; |
|
||||||
|
|
||||||
$result = $connection->fetchAssoc($query, [$mPreviousId]); |
|
||||||
} catch (DBALException $e) { |
|
||||||
throw new Exception("Unable to execute query \"{$this->query}\".", 0, $e); |
|
||||||
} |
|
||||||
|
|
||||||
$connection->close(); |
|
||||||
|
|
||||||
switch ($result['name']) { |
|
||||||
case 'lesson': |
|
||||||
$this->calledClass = CourseModulesLessonTask::class; |
|
||||||
|
|
||||||
return parent::transform([$mPreviousId]); |
|
||||||
} |
|
||||||
|
|
||||||
return 0; |
|
||||||
} |
|
||||||
} |
|
||||||
@ -0,0 +1,73 @@ |
|||||||
|
<?php |
||||||
|
/* For licensing terms, see /license.txt */ |
||||||
|
|
||||||
|
namespace Chamilo\PluginBundle\MigrationMoodle\Transformer\Property; |
||||||
|
|
||||||
|
use Chamilo\PluginBundle\MigrationMoodle\Task\CourseModulesLessonTask; |
||||||
|
use Chamilo\PluginBundle\MigrationMoodle\Task\CourseModulesQuizTask; |
||||||
|
use Doctrine\DBAL\DBALException; |
||||||
|
|
||||||
|
/** |
||||||
|
* Class LoadedLpItemInSequenceLookup. |
||||||
|
* |
||||||
|
* Transform a Moodle's course section sequence in a sort list for learning path item. |
||||||
|
* |
||||||
|
* @package Chamilo\PluginBundle\MigrationMoodle\Transformer\Property |
||||||
|
*/ |
||||||
|
class SectionSequenceLookup extends LoadedKeyLookup |
||||||
|
{ |
||||||
|
/** |
||||||
|
* @param array $data |
||||||
|
* |
||||||
|
* @throws \Exception |
||||||
|
* |
||||||
|
* @return array |
||||||
|
*/ |
||||||
|
public function transform(array $data) |
||||||
|
{ |
||||||
|
try { |
||||||
|
$connection = \MigrationMoodlePlugin::create()->getConnection(); |
||||||
|
} catch (DBALException $exception) { |
||||||
|
throw new \Exception('Unable to start connection.', 0, $exception); |
||||||
|
} |
||||||
|
|
||||||
|
$mSequence = explode(',', $data['sequence']); |
||||||
|
$lpOrderList = []; |
||||||
|
|
||||||
|
foreach ($mSequence as $mModuleId) { |
||||||
|
try { |
||||||
|
$query = "SELECT m.name |
||||||
|
FROM mdl_course_modules cm |
||||||
|
INNER JOIN mdl_modules m ON cm.module = m.id |
||||||
|
WHERE cm.id = ?"; |
||||||
|
|
||||||
|
$result = $connection->fetchAssoc($query, [$mModuleId]); |
||||||
|
} catch (DBALException $exception) { |
||||||
|
throw new \Exception("Unable to execute query \"{$this->query}\".", 0, $exception); |
||||||
|
} |
||||||
|
|
||||||
|
if (empty($result)) { |
||||||
|
continue; |
||||||
|
} |
||||||
|
|
||||||
|
switch ($result['name']) { |
||||||
|
case 'lesson': |
||||||
|
$this->calledClass = CourseModulesLessonTask::class; |
||||||
|
break; |
||||||
|
case 'quiz': |
||||||
|
$this->calledClass = CourseModulesQuizTask::class; |
||||||
|
break; |
||||||
|
default: |
||||||
|
continue; |
||||||
|
} |
||||||
|
|
||||||
|
$lpItemId = parent::transform([$mModuleId]); |
||||||
|
|
||||||
|
$lpOrderList[$lpItemId] = 0; |
||||||
|
} |
||||||
|
|
||||||
|
$connection->close(); |
||||||
|
|
||||||
|
return $lpOrderList; |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue