You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.5 KiB
55 lines
1.5 KiB
<?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]);
|
|
}
|
|
}
|
|
|