parent
de093062e7
commit
cbd59c727b
@ -0,0 +1,40 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\MigrationMoodle\Loader; |
||||
|
||||
use Chamilo\PluginBundle\MigrationMoodle\Interfaces\LoaderInterface; |
||||
|
||||
/** |
||||
* Class LpDocumentsLoader. |
||||
* |
||||
* @package Chamilo\PluginBundle\MigrationMoodle\Loader |
||||
*/ |
||||
class LpItemsLoader implements LoaderInterface |
||||
{ |
||||
/** |
||||
* Load the data and return the ID inserted. |
||||
* |
||||
* @param array $incomingData |
||||
* |
||||
* @return int |
||||
*/ |
||||
public function load(array $incomingData) |
||||
{ |
||||
$lp = new \learnpath( |
||||
$incomingData['c_code'], |
||||
$incomingData['lp_id'], |
||||
api_get_user_id() |
||||
); |
||||
$itemId = $lp->add_item( |
||||
$incomingData['parent'], |
||||
$incomingData['previous'], |
||||
$incomingData['item_type'], |
||||
0, |
||||
$incomingData['title'], |
||||
'' |
||||
); |
||||
|
||||
return $itemId; |
||||
} |
||||
} |
||||
@ -0,0 +1,77 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\MigrationMoodle\Task; |
||||
|
||||
use Chamilo\PluginBundle\MigrationMoodle\Extractor\BaseExtractor; |
||||
use Chamilo\PluginBundle\MigrationMoodle\Loader\LpItemsLoader; |
||||
use Chamilo\PluginBundle\MigrationMoodle\Transformer\BaseTransformer; |
||||
use Chamilo\PluginBundle\MigrationMoodle\Transformer\Property\LoadedCourseFromLessonLookup; |
||||
use Chamilo\PluginBundle\MigrationMoodle\Transformer\Property\LoadedLpDirFromLessonLookup; |
||||
use Chamilo\PluginBundle\MigrationMoodle\Transformer\Property\LoadedLpFromLessonLookup; |
||||
use Chamilo\PluginBundle\MigrationMoodle\Transformer\Property\LoadedLpItemLookup; |
||||
use Chamilo\PluginBundle\MigrationMoodle\Transformer\Property\LpItemTypeLookup; |
||||
|
||||
/** |
||||
* Class LpItemsTask. |
||||
* |
||||
* @package Chamilo\PluginBundle\MigrationMoodle\Task |
||||
*/ |
||||
class LpItemsTask extends BaseTask |
||||
{ |
||||
/** |
||||
* @return array |
||||
*/ |
||||
public function getExtractConfiguration() |
||||
{ |
||||
return [ |
||||
'class' => BaseExtractor::class, |
||||
'query' => 'SELECT id, lessonid, prevpageid, qtype, title |
||||
FROM mdl_lesson_pages |
||||
WHERE qtype NOT IN (21, 31)', |
||||
]; |
||||
} |
||||
|
||||
/** |
||||
* @return array |
||||
*/ |
||||
public function getTransformConfiguration() |
||||
{ |
||||
return [ |
||||
'class' => BaseTransformer::class, |
||||
'map' => [ |
||||
'c_code' => [ |
||||
'class' => LoadedCourseFromLessonLookup::class, |
||||
'properties' => ['lessonid'], |
||||
], |
||||
'lp_id' => [ |
||||
'class' => LoadedLpFromLessonLookup::class, |
||||
'properties' => ['lessonid'] |
||||
], |
||||
'parent' => [ |
||||
'class' => LoadedLpDirFromLessonLookup::class, |
||||
'properties' => ['lessonid'] |
||||
], |
||||
'previous' => [ |
||||
'class' => LoadedLpItemLookup::class, |
||||
'properties' => ['prevpageid'], |
||||
], |
||||
'item_type' => [ |
||||
'class' => LpItemTypeLookup::class, |
||||
'properties' => ['qtype'], |
||||
], |
||||
'title' => 'title', |
||||
], |
||||
]; |
||||
} |
||||
|
||||
/** |
||||
* @return array |
||||
*/ |
||||
public function getLoadConfiguration() |
||||
{ |
||||
return [ |
||||
'class' => LpItemsLoader::class, |
||||
]; |
||||
} |
||||
} |
||||
@ -0,0 +1,42 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\MigrationMoodle\Transformer\Property; |
||||
|
||||
use Doctrine\DBAL\DBALException; |
||||
use Doctrine\DBAL\FetchMode; |
||||
|
||||
/** |
||||
* Class LoadedCourseFromLessonLookup. |
||||
* |
||||
* @package Chamilo\PluginBundle\MigrationMoodle\Transformer\Property |
||||
*/ |
||||
class LoadedCourseFromLessonLookup extends LoadedCourseCodeLookup |
||||
{ |
||||
public function transform(array $data) |
||||
{ |
||||
try { |
||||
$connection = \MigrationMoodlePlugin::create()->getConnection(); |
||||
} catch (DBALException $e) { |
||||
throw new \Exception('Unable to start connection.', 0, $e); |
||||
} |
||||
|
||||
$query = "SELECT course FROM mdl_lesson WHERE id = ?"; |
||||
|
||||
$lessonId = current($data); |
||||
|
||||
try { |
||||
$statement = $connection->executeQuery($query, [$lessonId]); |
||||
} catch (DBALException $e) { |
||||
throw new \Exception("Unable to execute query \"$query\".", 0, $e); |
||||
} |
||||
|
||||
$result = $statement->fetch(FetchMode::ASSOCIATIVE); |
||||
|
||||
$connection->close(); |
||||
|
||||
$courseId = $result['course']; |
||||
|
||||
return parent::transform([$courseId]); |
||||
} |
||||
} |
||||
@ -0,0 +1,55 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\MigrationMoodle\Transformer\Property; |
||||
|
||||
use Chamilo\PluginBundle\MigrationMoodle\Task\LpDirsTask; |
||||
use Doctrine\DBAL\DBALException; |
||||
use Doctrine\DBAL\FetchMode; |
||||
|
||||
/** |
||||
* Class LoadedLpDirFromLessonLookup. |
||||
* |
||||
* @package Chamilo\PluginBundle\MigrationMoodle\Transformer\Property |
||||
*/ |
||||
class LoadedLpDirFromLessonLookup extends LoadedKeyLookup |
||||
{ |
||||
/** |
||||
* LoadedLpDirFromLessonLookup constructor. |
||||
*/ |
||||
public function __construct() |
||||
{ |
||||
$this->calledClass = LpDirsTask::class; |
||||
} |
||||
|
||||
public function transform(array $data) |
||||
{ |
||||
try { |
||||
$connection = \MigrationMoodlePlugin::create()->getConnection(); |
||||
} catch (DBALException $e) { |
||||
throw new \Exception('Unable to start connection.', 0, $e); |
||||
} |
||||
|
||||
$query = "SELECT cm.id FROM mdl_course_modules cm |
||||
INNER JOIN mdl_modules m ON cm.module = m.id |
||||
INNER JOIN mdl_lesson l ON (cm.course = l.course AND cm.instance = l.id) |
||||
WHERE m.name = 'lesson' |
||||
AND l.id = ?"; |
||||
|
||||
$lessonId = current($data); |
||||
|
||||
try { |
||||
$statement = $connection->executeQuery($query, [$lessonId]); |
||||
} catch (DBALException $e) { |
||||
throw new \Exception("Unable to execute query \"$query\".", 0, $e); |
||||
} |
||||
|
||||
$result = $statement->fetch(FetchMode::ASSOCIATIVE); |
||||
|
||||
$connection->close(); |
||||
|
||||
$lessonId = $result['id']; |
||||
|
||||
return parent::transform([$lessonId]); |
||||
} |
||||
} |
||||
@ -0,0 +1,57 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\MigrationMoodle\Transformer\Property; |
||||
|
||||
use Chamilo\PluginBundle\MigrationMoodle\Task\LearningPathsTask; |
||||
use Chamilo\UserBundle\Entity\User; |
||||
use Doctrine\DBAL\DBALException; |
||||
use Doctrine\DBAL\FetchMode; |
||||
|
||||
/** |
||||
* Class LoadedLpFromLessonLookup. |
||||
* |
||||
* @package Chamilo\PluginBundle\MigrationMoodle\Transformer\Property |
||||
*/ |
||||
class LoadedLpFromLessonLookup extends LoadedLpLookup |
||||
{ |
||||
|
||||
/** |
||||
* @param array $data |
||||
* |
||||
* @throws \Exception |
||||
* |
||||
* @return mixed |
||||
*/ |
||||
public function transform(array $data) |
||||
{ |
||||
try { |
||||
$connection = \MigrationMoodlePlugin::create()->getConnection(); |
||||
} catch (DBALException $e) { |
||||
throw new \Exception('Unable to start connection.', 0, $e); |
||||
} |
||||
|
||||
$query = "SELECT cs.id FROM mdl_course_sections cs |
||||
INNER JOIN mdl_course_modules cm ON (cs.id = cm.section AND cs.course = cm.course) |
||||
INNER JOIN mdl_modules m ON cm.module = m.id |
||||
INNER JOIN mdl_lesson l ON (cm.course = l.course AND cm.instance = l.id) |
||||
WHERE m.name = 'lesson' |
||||
AND l.id = ?"; |
||||
|
||||
$lessonId = current($data); |
||||
|
||||
try { |
||||
$statement = $connection->executeQuery($query, [$lessonId]); |
||||
} catch (DBALException $e) { |
||||
throw new \Exception("Unable to execute query \"$query\".", 0, $e); |
||||
} |
||||
|
||||
$result = $statement->fetch(FetchMode::ASSOCIATIVE); |
||||
|
||||
$connection->close(); |
||||
|
||||
$sectionId = $result['id']; |
||||
|
||||
return parent::transform([$sectionId]); |
||||
} |
||||
} |
||||
@ -0,0 +1,22 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\MigrationMoodle\Transformer\Property; |
||||
|
||||
use Chamilo\PluginBundle\MigrationMoodle\Task\LpItemsTask; |
||||
|
||||
/** |
||||
* Class LoadedLpItemLookup. |
||||
* |
||||
* @package Chamilo\PluginBundle\MigrationMoodle\Transformer\Property |
||||
*/ |
||||
class LoadedLpItemLookup extends LoadedKeyLookup |
||||
{ |
||||
/** |
||||
* LoadedLpItemLookup constructor. |
||||
*/ |
||||
public function __construct() |
||||
{ |
||||
$this->calledClass = LpItemsTask::class; |
||||
} |
||||
} |
||||
@ -0,0 +1,38 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\MigrationMoodle\Transformer\Property; |
||||
|
||||
use Chamilo\PluginBundle\MigrationMoodle\Interfaces\TransformPropertyInterface; |
||||
|
||||
/** |
||||
* Class LpItemTypeLookup. |
||||
* |
||||
* @package Chamilo\PluginBundle\MigrationMoodle\Transformer\Property |
||||
*/ |
||||
class LpItemTypeLookup implements TransformPropertyInterface |
||||
{ |
||||
/** |
||||
* @param array $data |
||||
* |
||||
* @return string |
||||
*/ |
||||
public function transform(array $data) |
||||
{ |
||||
$qtype = current($data); |
||||
|
||||
switch ($qtype) { |
||||
case 1: |
||||
case 2: |
||||
case 3: |
||||
case 5: |
||||
case 8: |
||||
case 10: |
||||
return 'quiz'; |
||||
case 20: |
||||
return 'document'; |
||||
} |
||||
|
||||
return 'dir'; |
||||
} |
||||
} |
||||
Loading…
Reference in new issue