MigrationMoodle: Add task for user sessions - BT#15992

pull/3127/head
Angel Fernando Quiroz Campos 6 years ago
parent b484376f00
commit adaad15679
  1. 1
      plugin/migrationmoodle/admin.php
  2. 1
      plugin/migrationmoodle/lang/english.php
  3. 38
      plugin/migrationmoodle/src/Extractor/UserExtractor.php
  4. 35
      plugin/migrationmoodle/src/Loader/EfcUserSessionLoader.php
  5. 62
      plugin/migrationmoodle/src/Task/EfcUserSessionsTask.php
  6. 30
      plugin/migrationmoodle/src/Transformer/Property/SessionName.php

@ -23,6 +23,7 @@ $menu = [
//'courses',
'efc_courses',
'role_assignments',
'efc_user_sessions',
],
'efc_courses' => [
'course_sections',

@ -40,3 +40,4 @@ $strings['QuestionsTrueFalseTask'] = 'Answers for truefalse questions';
$strings['CourseModulesScormTask'] = 'Course Scorms';
$strings['ScormScoesTask'] = 'Scorms items';
$strings['FilesForScormScoesTask'] = 'Files for Scorm items';
$strings['EfcUserSessionsTask'] = 'Course Sessions for efc* users';

@ -0,0 +1,38 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\PluginBundle\MigrationMoodle\Extractor;
use Chamilo\PluginBundle\MigrationMoodle\Task\EfcUsersTask;
/**
* Class UserExtractor.
*
* @package Chamilo\PluginBundle\MigrationMoodle\Extractor
*/
class UserExtractor extends FilterExtractor
{
/**
* UserExtractor constructor.
*
* @param array $configuration
*/
public function __construct(array $configuration)
{
parent::__construct($configuration);
$this->calledClass = EfcUsersTask::class;
}
/**
* @param array $sourceData
*
* @return bool
*/
public function filter(array $sourceData)
{
$userId = current($sourceData);
return !$this->existsExtracted($userId);
}
}

@ -0,0 +1,35 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\PluginBundle\MigrationMoodle\Loader;
use Chamilo\PluginBundle\MigrationMoodle\Interfaces\LoaderInterface;
/**
* Class EfcUserSessionLoader.
*
* @package Chamilo\PluginBundle\MigrationMoodle\Loader
*/
class EfcUserSessionLoader implements LoaderInterface
{
/**
* @inheritDoc
*/
public function load(array $incomingData)
{
$datetime = api_get_utc_datetime();
$coachId = 1;
return \SessionManager::create_session(
$incomingData['name'],
$datetime,
'',
$datetime,
'',
$datetime,
'',
$coachId,
0
);
}
}

@ -0,0 +1,62 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\PluginBundle\MigrationMoodle\Task;
use Chamilo\PluginBundle\MigrationMoodle\Extractor\UserExtractor;
use Chamilo\PluginBundle\MigrationMoodle\Loader\EfcUserSessionLoader;
use Chamilo\PluginBundle\MigrationMoodle\Transformer\BaseTransformer;
use Chamilo\PluginBundle\MigrationMoodle\Transformer\Property\SessionName;
/**
* Class EfcUserSessionsTask.
*
* @package Chamilo\PluginBundle\MigrationMoodle\Task
*/
class EfcUserSessionsTask extends BaseTask
{
/**
* @inheritDoc
*/
public function getExtractConfiguration()
{
return [
'class' => UserExtractor::class,
'query' => 'SELECT u.id, u.username, GROUP_CONCAT(c.shortname SEPARATOR " - ") session_name
FROM mdl_role_assignments ra
INNER JOIN mdl_role r ON ra.roleid = r.id
INNER JOIN mdl_context ctx ON ra.contextid = ctx.id
INNER JOIN mdl_course c ON ctx.instanceid = c.id
INNER JOIN mdl_user u ON ra.userid = u.id
WHERE ctx.contextlevel = '.RoleAssignmentsTask::CONTEXT_LEVEL_COURSE.'
AND u.username LIKE "efc%"
GROUP BY ra.userid',
];
}
/**
* @inheritDoc
*/
public function getTransformConfiguration()
{
return [
'class' => BaseTransformer::class,
'map' => [
'name' => [
'class' => SessionName::class,
'properties' => ['username', 'session_name']
],
],
];
}
/**
* @inheritDoc
*/
public function getLoadConfiguration()
{
return [
'class' => EfcUserSessionLoader::class,
];
}
}

@ -0,0 +1,30 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\PluginBundle\MigrationMoodle\Transformer\Property;
use Chamilo\PluginBundle\MigrationMoodle\Interfaces\TransformPropertyInterface;
/**
* Class SessionName.
*
* @package Chamilo\PluginBundle\MigrationMoodle\Transformer\Property
*/
class SessionName implements TransformPropertyInterface
{
/**
* @inheritDoc
*/
public function transform(array $data)
{
$pieces = [
'[',
$data['username'],
']',
' ',
$data['session_name']
];
return implode('', $pieces);
}
}
Loading…
Cancel
Save