parent
b484376f00
commit
adaad15679
@ -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…
Reference in new issue