parent
6ff0eb305c
commit
572b54d20a
@ -0,0 +1,56 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\MigrationMoodle\Extractor; |
||||
|
||||
use Chamilo\PluginBundle\MigrationMoodle\Task\CourseModulesScormTask; |
||||
use Chamilo\PluginBundle\MigrationMoodle\Traits\MapTrait\MapTrait; |
||||
|
||||
/** |
||||
* Class ScormExtractor. |
||||
* |
||||
* @package Chamilo\PluginBundle\MigrationMoodle\Extractor |
||||
*/ |
||||
class ScormExtractor extends BaseExtractor |
||||
{ |
||||
use MapTrait; |
||||
|
||||
/** |
||||
* ScormExtractor constructor. |
||||
* |
||||
* @param array $configuration |
||||
*/ |
||||
public function __construct(array $configuration) |
||||
{ |
||||
parent::__construct($configuration); |
||||
|
||||
$this->calledClass = CourseModulesScormTask::class; |
||||
} |
||||
|
||||
/** |
||||
* Filter to avoid scorms not yet migrated. |
||||
* |
||||
* @param array $sourceData |
||||
* |
||||
* @return bool |
||||
*/ |
||||
public function filter(array $sourceData) |
||||
{ |
||||
$scormId = $sourceData['scorm']; |
||||
|
||||
$taskName = $this->getTaskName(); |
||||
|
||||
$result = \Database::select( |
||||
'COUNT(1) AS c', |
||||
'plugin_migrationmoodle_item i INNER JOIN plugin_migrationmoodle_task t ON i.task_id = t.id', |
||||
[ |
||||
'where' => [ |
||||
't.name = ? AND i.extracted_id = ?' => [$taskName, $scormId] |
||||
], |
||||
], |
||||
'first' |
||||
); |
||||
|
||||
return $result['c'] == 0; |
||||
} |
||||
} |
||||
@ -0,0 +1,47 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\MigrationMoodle\Loader; |
||||
|
||||
use Chamilo\PluginBundle\MigrationMoodle\Interfaces\LoaderInterface; |
||||
|
||||
/** |
||||
* Class ScormScoLoader. |
||||
* |
||||
* @package Chamilo\PluginBundle\MigrationMoodle\Loader |
||||
*/ |
||||
class ScormScoLoader implements LoaderInterface |
||||
{ |
||||
/** |
||||
* @inheritDoc |
||||
*/ |
||||
public function load(array $incomingData) |
||||
{ |
||||
$em = \Database::getManager(); |
||||
|
||||
$scorm = new \scorm( |
||||
$incomingData['c_code'], |
||||
$incomingData['lp_id'], |
||||
api_get_user_id() |
||||
); |
||||
|
||||
$itemId = $scorm->add_item( |
||||
$incomingData['parent_item_id'], |
||||
0, |
||||
$incomingData['item_type'], |
||||
0, |
||||
$incomingData['title'], |
||||
'' |
||||
); |
||||
|
||||
$item = $em->find('ChamiloCourseBundle:CLpItem', $itemId); |
||||
$item |
||||
->setPath($incomingData['path']) |
||||
->setRef($incomingData['ref']); |
||||
|
||||
$em->persist($item); |
||||
$em->flush(); |
||||
|
||||
return $item->getId(); |
||||
} |
||||
} |
||||
@ -0,0 +1,71 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\MigrationMoodle\Task; |
||||
|
||||
use Chamilo\PluginBundle\MigrationMoodle\Extractor\ScormExtractor; |
||||
use Chamilo\PluginBundle\MigrationMoodle\Loader\ScormScoLoader; |
||||
use Chamilo\PluginBundle\MigrationMoodle\Transformer\BaseTransformer; |
||||
use Chamilo\PluginBundle\MigrationMoodle\Transformer\Property\LoadedCourseCodeLookup; |
||||
use Chamilo\PluginBundle\MigrationMoodle\Transformer\Property\LoadedScormLookup; |
||||
use Chamilo\PluginBundle\MigrationMoodle\Transformer\Property\ScormScoParentLookup; |
||||
|
||||
/** |
||||
* Class ScormScoesTask. |
||||
* |
||||
* @package Chamilo\PluginBundle\MigrationMoodle\Task |
||||
*/ |
||||
class ScormScoesTask extends BaseTask |
||||
{ |
||||
/** |
||||
* @inheritDoc |
||||
*/ |
||||
public function getExtractConfiguration() |
||||
{ |
||||
return [ |
||||
'class' => ScormExtractor::class, |
||||
'query' => "SELECT i.id, i.title, i.scormtype, i.launch, i.identifier, i.scorm, i.parent, s.course |
||||
FROM mdl_scorm_scoes i |
||||
INNER JOIN mdl_scorm s ON i.scorm = s.id |
||||
WHERE i.parent != '/' ORDER BY s.id, i.sortorder", |
||||
]; |
||||
} |
||||
|
||||
/** |
||||
* @inheritDoc |
||||
*/ |
||||
public function getTransformConfiguration() |
||||
{ |
||||
return [ |
||||
'class' => BaseTransformer::class, |
||||
'map' => [ |
||||
'title' => 'title', |
||||
'item_type' => 'scormtype', |
||||
'path' => 'launch', |
||||
'ref' => 'identifier', |
||||
'lp_id' => [ |
||||
'class' => LoadedScormLookup::class, |
||||
'properties' => ['scorm'], |
||||
], |
||||
'parent_item_id' => [ |
||||
'class' => ScormScoParentLookup::class, |
||||
'properties' => ['parent', 'scorm'], |
||||
], |
||||
'c_code' => [ |
||||
'class' => LoadedCourseCodeLookup::class, |
||||
'properties' => ['course'], |
||||
], |
||||
], |
||||
]; |
||||
} |
||||
|
||||
/** |
||||
* @inheritDoc |
||||
*/ |
||||
public function getLoadConfiguration() |
||||
{ |
||||
return [ |
||||
'class' => ScormScoLoader::class, |
||||
]; |
||||
} |
||||
} |
||||
@ -0,0 +1,22 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\MigrationMoodle\Transformer\Property; |
||||
|
||||
use Chamilo\PluginBundle\MigrationMoodle\Task\CourseModulesScormTask; |
||||
|
||||
/** |
||||
* Class LoadedScormLookup. |
||||
* |
||||
* @package Chamilo\PluginBundle\MigrationMoodle\Transformer\Property |
||||
*/ |
||||
class LoadedScormLookup extends LoadedKeyLookup |
||||
{ |
||||
/** |
||||
* LoadedScormLookup constructor. |
||||
*/ |
||||
public function __construct() |
||||
{ |
||||
$this->calledClass = CourseModulesScormTask::class; |
||||
} |
||||
} |
||||
@ -0,0 +1,43 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\MigrationMoodle\Transformer\Property; |
||||
|
||||
use Chamilo\PluginBundle\MigrationMoodle\Interfaces\TransformPropertyInterface; |
||||
|
||||
/** |
||||
* Class ScormScoParentLookup. |
||||
* |
||||
* @package Chamilo\PluginBundle\MigrationMoodle\Transformer\Property |
||||
*/ |
||||
class ScormScoParentLookup extends LoadedScormLookup |
||||
{ |
||||
/** |
||||
* @inheritDoc |
||||
*/ |
||||
public function transform(array $data) |
||||
{ |
||||
$lpId = parent::transform([$data['scorm']]); |
||||
|
||||
if (empty($lpId)) { |
||||
throw new \Exception("Learning path SCORM ({$data['scorm']}) not found searching item {$data['parent']}"); |
||||
} |
||||
|
||||
$lpItem = \Database::select( |
||||
'iid', |
||||
\Database::get_course_table(TABLE_LP_ITEM), |
||||
[ |
||||
'where' => [ |
||||
'lp_id = ? AND ref = ?' => [$lpId, $data['parent']], |
||||
], |
||||
], |
||||
'first' |
||||
); |
||||
|
||||
if (!empty($lpItem)) { |
||||
return $lpItem['iid']; |
||||
} |
||||
|
||||
return 0; |
||||
} |
||||
} |
||||
Loading…
Reference in new issue